60 | | TBD: In progress |
| 60 | Here's an example of converting the move method from WebKit/chromium/src/WorkerFileSystemCallbacksBridge.cpp (http://trac.webkit.org/browser/trunk/Source/WebKit/chromium/src/WorkerFileSystemCallbacksBridge.cpp) to using this. |
| 61 | |
| 62 | The main changes are less code at the calling sites and less mechanics around carefully tracking the lifetime of each side. |
| 63 | |
| 64 | {{{ |
| 65 | class MainThreadFileSystemCallbacks : public WebFileSystemCallbacks { |
| 66 | public: |
| 67 | // Callbacks are self-destructed and we always return leaked pointer here. |
| 68 | static MainThreadFileSystemCallbacks* createLeakedPtr(PassOwnPtr<ClassProxy> callbackProxy) |
| 69 | { |
| 70 | return adoptPtr(new MainThreadFileSystemCallbacks(callbackProxy)).leakPtr(); |
| 71 | } |
| 72 | |
| 73 | virtual void didSucceed() |
| 74 | { |
| 75 | m_callbackProxy->invoke(&didSucceedOnMainThread); |
| 76 | m_callbackProxy->done(); |
| 77 | delete this; |
| 78 | } |
| 79 | |
| 80 | private: |
| 81 | MainThreadFileSystemCallbacks(PassOwnPtr<ClassProxy> callbackProxy) |
| 82 | : m_callbackProxy(callbackProxy) |
| 83 | { |
| 84 | } |
| 85 | |
| 86 | OwnPtr<ClassProxy> m_callbackProxy; |
| 87 | }; |
| 88 | |
| 89 | void moveOnMainThread(PassOwnPtr<ClassProxy> callbackProxy, WebFileSystem* fileSystem, const String& sourcePath, const String& destinationPath, const String& mode) |
| 90 | { |
| 91 | fileSystem->move(sourcePath, destinationPath, MainThreadFileSystemCallbacks::createLeakedPtr(callbackProxy)); |
| 92 | } |
| 93 | |
| 94 | void WorkerFileSystemCallbacks::stop() |
| 95 | { |
| 96 | if (m_callbacksOnWorkerThread) { |
| 97 | m_callbacksOnWorkerThread->didFail(WebFileErrorAbort); |
| 98 | m_callbacksOnWorkerThread = 0; |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | void WorkerFileSystemCallbacks::postMoveToMainThread(WebFileSystem* fileSystem, const String& sourcePath, const String& destinationPath, const String& mode) |
| 103 | { |
| 104 | OwnPtr<SyncWaiter> syncCall = mainThreadMessageLoop->invoke(&moveOnMainThread, getProxy(), fileSystem, sourcePath, destinationPath); |
| 105 | syncCall.wait(); |
| 106 | stop(); |
| 107 | } |
| 108 | }}} |