Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1423)

Unified Diff: webkit/tools/test_shell/simple_file_writer.cc

Issue 4821005: Make FileSystemOperation's lifetime more explicit. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: simple_file_writer fix Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webkit/tools/test_shell/simple_file_system.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 bb4758f3f5323aadaf36b050b74abc7070e60032..d33d75dc0543175311f61d7f8d8982f6c5b43c2d 100644
--- a/webkit/tools/test_shell/simple_file_writer.cc
+++ b/webkit/tools/test_shell/simple_file_writer.cc
@@ -28,7 +28,8 @@ class SimpleFileWriter::IOThreadProxy
: public base::RefCountedThreadSafe<SimpleFileWriter::IOThreadProxy> {
public:
explicit IOThreadProxy(const base::WeakPtr<SimpleFileWriter>& simple_writer)
- : simple_writer_(simple_writer) {
+ : simple_writer_(simple_writer),
+ operation_(NULL) {
// The IO thread needs to be running for this class to work.
SimpleResourceLoaderBridge::EnsureIOThread();
io_thread_ = SimpleResourceLoaderBridge::GetIoThread();
@@ -44,8 +45,8 @@ class SimpleFileWriter::IOThreadProxy
this, &IOThreadProxy::Truncate, path, offset));
return;
}
- DCHECK(!operation_.get());
- operation_.reset(GetNewOperation());
+ DCHECK(!operation_);
+ operation_ = GetNewOperation();
operation_->Truncate(path, offset);
}
@@ -56,8 +57,8 @@ class SimpleFileWriter::IOThreadProxy
return;
}
DCHECK(request_context_);
- DCHECK(!operation_.get());
- operation_.reset(GetNewOperation());
+ DCHECK(!operation_);
+ operation_ = GetNewOperation();
operation_->Write(request_context_, path, blob_url, offset);
}
@@ -67,12 +68,11 @@ class SimpleFileWriter::IOThreadProxy
this, &IOThreadProxy::Cancel));
return;
}
- if (!operation_.get()) {
+ if (!operation_) {
DidFail(base::PLATFORM_FILE_ERROR_INVALID_OPERATION);
return;
}
- cancel_operation_.reset(GetNewOperation());
- operation_->Cancel(cancel_operation_.get());
+ operation_->Cancel(GetNewOperation());
}
private:
@@ -82,6 +82,10 @@ class SimpleFileWriter::IOThreadProxy
explicit CallbackDispatcher(IOThreadProxy* proxy) : proxy_(proxy) {
}
+ ~CallbackDispatcher() {
+ proxy_->ClearOperation();
+ }
+
virtual void DidSucceed() {
proxy_->DidSucceed();
}
@@ -119,7 +123,6 @@ class SimpleFileWriter::IOThreadProxy
void DidSucceed() {
if (!main_thread_->BelongsToCurrentThread()) {
- operation_.reset();
main_thread_->PostTask(FROM_HERE, NewRunnableMethod(
this, &IOThreadProxy::DidSucceed));
return;
@@ -130,7 +133,6 @@ class SimpleFileWriter::IOThreadProxy
void DidFail(base::PlatformFileError error_code) {
if (!main_thread_->BelongsToCurrentThread()) {
- operation_.reset();
main_thread_->PostTask(FROM_HERE, NewRunnableMethod(
this, &IOThreadProxy::DidFail, error_code));
return;
@@ -141,8 +143,6 @@ class SimpleFileWriter::IOThreadProxy
void DidWrite(int64 bytes, bool complete) {
if (!main_thread_->BelongsToCurrentThread()) {
- if (complete)
- operation_.reset();
main_thread_->PostTask(FROM_HERE, NewRunnableMethod(
this, &IOThreadProxy::DidWrite, bytes, complete));
return;
@@ -151,6 +151,10 @@ class SimpleFileWriter::IOThreadProxy
simple_writer_->DidWrite(bytes, complete);
}
+ void ClearOperation() {
+ operation_ = NULL;
+ }
+
scoped_refptr<base::MessageLoopProxy> io_thread_;
scoped_refptr<base::MessageLoopProxy> main_thread_;
@@ -158,8 +162,7 @@ class SimpleFileWriter::IOThreadProxy
base::WeakPtr<SimpleFileWriter> simple_writer_;
// Only used on the io thread.
- scoped_ptr<FileSystemOperation> operation_;
- scoped_ptr<FileSystemOperation> cancel_operation_;
+ FileSystemOperation* operation_;
};
« no previous file with comments | « webkit/tools/test_shell/simple_file_system.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698