Index: webkit/tools/test_shell/simple_file_writer.cc |
diff --git a/webkit/tools/test_shell/simple_file_writer.cc b/webkit/tools/test_shell/simple_file_writer.cc |
index dfa37baf298e564f74c4c2d8e4b283b3dde8d7eb..c548183e35b31c4862fb2c7db927c920b9dc63a9 100644 |
--- a/webkit/tools/test_shell/simple_file_writer.cc |
+++ b/webkit/tools/test_shell/simple_file_writer.cc |
@@ -80,14 +80,19 @@ class SimpleFileWriter::IOThreadProxy |
DidFail(base::PLATFORM_FILE_ERROR_INVALID_OPERATION); |
return; |
} |
- operation_->Cancel(GetNewOperation()); |
+ operation_->Cancel(CallbackDispatcher::Create(this)); |
} |
private: |
// Inner class to receive callbacks from FileSystemOperation. |
class CallbackDispatcher : public FileSystemCallbackDispatcher { |
public: |
- explicit CallbackDispatcher(IOThreadProxy* proxy) : proxy_(proxy) { |
+ // An instance of this class must be created by Create() |
+ // (so that we do not leak ownerships). |
+ static scoped_ptr<FileSystemCallbackDispatcher> Create( |
+ IOThreadProxy* proxy) { |
+ return scoped_ptr<FileSystemCallbackDispatcher>( |
+ new CallbackDispatcher(proxy)); |
} |
~CallbackDispatcher() { |
@@ -124,12 +129,14 @@ class SimpleFileWriter::IOThreadProxy |
NOTREACHED(); |
} |
+ private: |
+ explicit CallbackDispatcher(IOThreadProxy* proxy) : proxy_(proxy) {} |
scoped_refptr<IOThreadProxy> proxy_; |
}; |
FileSystemOperation* GetNewOperation() { |
// The FileSystemOperation takes ownership of the CallbackDispatcher. |
- return new FileSystemOperation(new CallbackDispatcher(this), |
+ return new FileSystemOperation(CallbackDispatcher::Create(this), |
io_thread_, file_system_context_.get()); |
} |