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

Unified Diff: content/child/fileapi/webfilesystem_impl.cc

Issue 102603014: FileAPI: Fix memory leak in WebFileSystemImpl (won't commit) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: clean up Created 6 years, 9 months 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 | « no previous file | tools/valgrind/memcheck/suppressions.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/child/fileapi/webfilesystem_impl.cc
diff --git a/content/child/fileapi/webfilesystem_impl.cc b/content/child/fileapi/webfilesystem_impl.cc
index c149afd3ff628eb1ab28634122b38720109e6761..93765cb9d7ca1bc9a8238c59b9022823f5196f00 100644
--- a/content/child/fileapi/webfilesystem_impl.cc
+++ b/content/child/fileapi/webfilesystem_impl.cc
@@ -42,32 +42,32 @@ base::LazyInstance<base::ThreadLocalPointer<WebFileSystemImpl> >::Leaky
class WaitableCallbackResults {
public:
- static WaitableCallbackResults* MaybeCreate(
+ static scoped_ptr<WaitableCallbackResults> MaybeCreate(
const WebFileSystemCallbacks& callbacks) {
if (callbacks.shouldBlockUntilCompletion())
- return new WaitableCallbackResults;
- return NULL;
+ return make_scoped_ptr(new WaitableCallbackResults);
+ return scoped_ptr<WaitableCallbackResults>();
}
~WaitableCallbackResults() {}
void SetResultsAndSignal(const base::Closure& results_closure) {
results_closure_ = results_closure;
- event_->Signal();
+ event_.Signal();
}
void WaitAndRun() {
{
blink::WebHeap::SafePointScope safe_point;
- event_->Wait();
+ event_.Wait();
}
DCHECK(!results_closure_.is_null());
results_closure_.Run();
}
private:
- WaitableCallbackResults() : event_(new base::WaitableEvent(true, false)) {}
+ WaitableCallbackResults() : event_(true, false) {}
- base::WaitableEvent* event_;
+ base::WaitableEvent event_;
base::Closure results_closure_;
DISALLOW_COPY_AND_ASSIGN(WaitableCallbackResults);
};
@@ -198,7 +198,7 @@ void ReadMetadataCallbackAdapter(int thread_id, int callbacks_id,
MakeTuple(web_file_info));
}
-void ReadDirectoryCallbackAdapater(
+void ReadDirectoryCallbackAdapter(
int thread_id, int callbacks_id, WaitableCallbackResults* waitable_results,
const std::vector<fileapi::DirectoryEntry>& entries,
bool has_more) {
@@ -332,8 +332,9 @@ void WebFileSystemImpl::openFileSystem(
blink::WebFileSystemType type,
WebFileSystemCallbacks callbacks) {
int callbacks_id = RegisterCallbacks(callbacks);
- WaitableCallbackResults* waitable_results =
+ scoped_ptr<WaitableCallbackResults> waitable_results =
WaitableCallbackResults::MaybeCreate(callbacks);
+ WaitableCallbackResults* waitable_results_ptr = waitable_results.get();
CallDispatcherOnMainThread(
main_thread_loop_.get(),
&FileSystemDispatcher::OpenFileSystem,
@@ -341,30 +342,31 @@ void WebFileSystemImpl::openFileSystem(
static_cast<fileapi::FileSystemType>(type),
base::Bind(&OpenFileSystemCallbackAdapter,
CurrentWorkerId(), callbacks_id,
- base::Unretained(waitable_results)),
+ waitable_results_ptr),
base::Bind(&StatusCallbackAdapter,
CurrentWorkerId(), callbacks_id,
- base::Unretained(waitable_results))),
- make_scoped_ptr(waitable_results));
+ waitable_results_ptr)),
+ waitable_results.Pass());
}
void WebFileSystemImpl::resolveURL(
const blink::WebURL& filesystem_url,
WebFileSystemCallbacks callbacks) {
int callbacks_id = RegisterCallbacks(callbacks);
- WaitableCallbackResults* waitable_results =
+ scoped_ptr<WaitableCallbackResults> waitable_results =
WaitableCallbackResults::MaybeCreate(callbacks);
+ WaitableCallbackResults* waitable_results_ptr = waitable_results.get();
CallDispatcherOnMainThread(
main_thread_loop_.get(),
&FileSystemDispatcher::ResolveURL,
MakeTuple(GURL(filesystem_url),
base::Bind(&ResolveURLCallbackAdapter,
CurrentWorkerId(), callbacks_id,
- base::Unretained(waitable_results)),
+ waitable_results_ptr),
base::Bind(&StatusCallbackAdapter,
CurrentWorkerId(), callbacks_id,
- base::Unretained(waitable_results))),
- make_scoped_ptr(waitable_results));
+ waitable_results_ptr)),
+ waitable_results.Pass());
}
void WebFileSystemImpl::deleteFileSystem(
@@ -372,8 +374,9 @@ void WebFileSystemImpl::deleteFileSystem(
blink::WebFileSystemType type,
WebFileSystemCallbacks callbacks) {
int callbacks_id = RegisterCallbacks(callbacks);
- WaitableCallbackResults* waitable_results =
+ scoped_ptr<WaitableCallbackResults> waitable_results =
WaitableCallbackResults::MaybeCreate(callbacks);
+ WaitableCallbackResults* waitable_results_ptr = waitable_results.get();
CallDispatcherOnMainThread(
main_thread_loop_.get(),
&FileSystemDispatcher::DeleteFileSystem,
@@ -381,8 +384,8 @@ void WebFileSystemImpl::deleteFileSystem(
static_cast<fileapi::FileSystemType>(type),
base::Bind(&StatusCallbackAdapter,
CurrentWorkerId(), callbacks_id,
- base::Unretained(waitable_results))),
- make_scoped_ptr(waitable_results));
+ waitable_results_ptr)),
+ waitable_results.Pass());
}
void WebFileSystemImpl::move(
@@ -390,16 +393,17 @@ void WebFileSystemImpl::move(
const blink::WebURL& dest_path,
WebFileSystemCallbacks callbacks) {
int callbacks_id = RegisterCallbacks(callbacks);
- WaitableCallbackResults* waitable_results =
+ scoped_ptr<WaitableCallbackResults> waitable_results =
WaitableCallbackResults::MaybeCreate(callbacks);
+ WaitableCallbackResults* waitable_results_ptr = waitable_results.get();
CallDispatcherOnMainThread(
main_thread_loop_.get(),
&FileSystemDispatcher::Move,
MakeTuple(GURL(src_path), GURL(dest_path),
base::Bind(&StatusCallbackAdapter,
CurrentWorkerId(), callbacks_id,
- base::Unretained(waitable_results))),
- make_scoped_ptr(waitable_results));
+ waitable_results_ptr)),
+ waitable_results.Pass());
}
void WebFileSystemImpl::copy(
@@ -407,67 +411,71 @@ void WebFileSystemImpl::copy(
const blink::WebURL& dest_path,
WebFileSystemCallbacks callbacks) {
int callbacks_id = RegisterCallbacks(callbacks);
- WaitableCallbackResults* waitable_results =
+ scoped_ptr<WaitableCallbackResults> waitable_results =
WaitableCallbackResults::MaybeCreate(callbacks);
+ WaitableCallbackResults* waitable_results_ptr = waitable_results.get();
CallDispatcherOnMainThread(
main_thread_loop_.get(),
&FileSystemDispatcher::Copy,
MakeTuple(GURL(src_path), GURL(dest_path),
base::Bind(&StatusCallbackAdapter,
CurrentWorkerId(), callbacks_id,
- base::Unretained(waitable_results))),
- make_scoped_ptr(waitable_results));
+ waitable_results_ptr)),
+ waitable_results.Pass());
}
void WebFileSystemImpl::remove(
const blink::WebURL& path,
WebFileSystemCallbacks callbacks) {
int callbacks_id = RegisterCallbacks(callbacks);
- WaitableCallbackResults* waitable_results =
+ scoped_ptr<WaitableCallbackResults> waitable_results =
WaitableCallbackResults::MaybeCreate(callbacks);
+ WaitableCallbackResults* waitable_results_ptr = waitable_results.get();
CallDispatcherOnMainThread(
main_thread_loop_.get(),
&FileSystemDispatcher::Remove,
MakeTuple(GURL(path), false /* recursive */,
base::Bind(&StatusCallbackAdapter,
CurrentWorkerId(), callbacks_id,
- base::Unretained(waitable_results))),
- make_scoped_ptr(waitable_results));
+ waitable_results_ptr)),
+ waitable_results.Pass());
}
void WebFileSystemImpl::removeRecursively(
const blink::WebURL& path,
WebFileSystemCallbacks callbacks) {
int callbacks_id = RegisterCallbacks(callbacks);
- WaitableCallbackResults* waitable_results =
+ scoped_ptr<WaitableCallbackResults> waitable_results =
WaitableCallbackResults::MaybeCreate(callbacks);
+ WaitableCallbackResults* waitable_results_ptr = waitable_results.get();
CallDispatcherOnMainThread(
main_thread_loop_.get(),
&FileSystemDispatcher::Remove,
MakeTuple(GURL(path), true /* recursive */,
base::Bind(&StatusCallbackAdapter,
CurrentWorkerId(), callbacks_id,
- base::Unretained(waitable_results))),
- make_scoped_ptr(waitable_results));
+ waitable_results_ptr)),
+ waitable_results.Pass());
}
void WebFileSystemImpl::readMetadata(
const blink::WebURL& path,
WebFileSystemCallbacks callbacks) {
int callbacks_id = RegisterCallbacks(callbacks);
- WaitableCallbackResults* waitable_results =
+ scoped_ptr<WaitableCallbackResults> waitable_results =
WaitableCallbackResults::MaybeCreate(callbacks);
+ WaitableCallbackResults* waitable_results_ptr = waitable_results.get();
CallDispatcherOnMainThread(
main_thread_loop_.get(),
&FileSystemDispatcher::ReadMetadata,
MakeTuple(GURL(path),
base::Bind(&ReadMetadataCallbackAdapter,
CurrentWorkerId(), callbacks_id,
- base::Unretained(waitable_results)),
+ waitable_results_ptr),
base::Bind(&StatusCallbackAdapter,
CurrentWorkerId(), callbacks_id,
- base::Unretained(waitable_results))),
- make_scoped_ptr(waitable_results));
+ waitable_results_ptr)),
+ waitable_results.Pass());
}
void WebFileSystemImpl::createFile(
@@ -475,16 +483,17 @@ void WebFileSystemImpl::createFile(
bool exclusive,
WebFileSystemCallbacks callbacks) {
int callbacks_id = RegisterCallbacks(callbacks);
- WaitableCallbackResults* waitable_results =
+ scoped_ptr<WaitableCallbackResults> waitable_results =
WaitableCallbackResults::MaybeCreate(callbacks);
+ WaitableCallbackResults* waitable_results_ptr = waitable_results.get();
CallDispatcherOnMainThread(
main_thread_loop_.get(),
&FileSystemDispatcher::CreateFile,
MakeTuple(GURL(path), exclusive,
base::Bind(&StatusCallbackAdapter,
CurrentWorkerId(), callbacks_id,
- base::Unretained(waitable_results))),
- make_scoped_ptr(waitable_results));
+ waitable_results_ptr)),
+ waitable_results.Pass());
}
void WebFileSystemImpl::createDirectory(
@@ -492,67 +501,71 @@ void WebFileSystemImpl::createDirectory(
bool exclusive,
WebFileSystemCallbacks callbacks) {
int callbacks_id = RegisterCallbacks(callbacks);
- WaitableCallbackResults* waitable_results =
+ scoped_ptr<WaitableCallbackResults> waitable_results =
WaitableCallbackResults::MaybeCreate(callbacks);
+ WaitableCallbackResults* waitable_results_ptr = waitable_results.get();
CallDispatcherOnMainThread(
main_thread_loop_.get(),
&FileSystemDispatcher::CreateDirectory,
MakeTuple(GURL(path), exclusive, false /* recursive */,
base::Bind(&StatusCallbackAdapter,
CurrentWorkerId(), callbacks_id,
- base::Unretained(waitable_results))),
- make_scoped_ptr(waitable_results));
+ waitable_results_ptr)),
+ waitable_results.Pass());
}
void WebFileSystemImpl::fileExists(
const blink::WebURL& path,
WebFileSystemCallbacks callbacks) {
int callbacks_id = RegisterCallbacks(callbacks);
- WaitableCallbackResults* waitable_results =
+ scoped_ptr<WaitableCallbackResults> waitable_results =
WaitableCallbackResults::MaybeCreate(callbacks);
+ WaitableCallbackResults* waitable_results_ptr = waitable_results.get();
CallDispatcherOnMainThread(
main_thread_loop_.get(),
&FileSystemDispatcher::Exists,
MakeTuple(GURL(path), false /* directory */,
base::Bind(&StatusCallbackAdapter,
CurrentWorkerId(), callbacks_id,
- base::Unretained(waitable_results))),
- make_scoped_ptr(waitable_results));
+ waitable_results_ptr)),
+ waitable_results.Pass());
}
void WebFileSystemImpl::directoryExists(
const blink::WebURL& path,
WebFileSystemCallbacks callbacks) {
int callbacks_id = RegisterCallbacks(callbacks);
- WaitableCallbackResults* waitable_results =
+ scoped_ptr<WaitableCallbackResults> waitable_results =
WaitableCallbackResults::MaybeCreate(callbacks);
+ WaitableCallbackResults* waitable_results_ptr = waitable_results.get();
CallDispatcherOnMainThread(
main_thread_loop_.get(),
&FileSystemDispatcher::Exists,
MakeTuple(GURL(path), true /* directory */,
base::Bind(&StatusCallbackAdapter,
CurrentWorkerId(), callbacks_id,
- base::Unretained(waitable_results))),
- make_scoped_ptr(waitable_results));
+ waitable_results_ptr)),
+ waitable_results.Pass());
}
void WebFileSystemImpl::readDirectory(
const blink::WebURL& path,
WebFileSystemCallbacks callbacks) {
int callbacks_id = RegisterCallbacks(callbacks);
- WaitableCallbackResults* waitable_results =
+ scoped_ptr<WaitableCallbackResults> waitable_results =
WaitableCallbackResults::MaybeCreate(callbacks);
+ WaitableCallbackResults* waitable_results_ptr = waitable_results.get();
CallDispatcherOnMainThread(
main_thread_loop_.get(),
&FileSystemDispatcher::ReadDirectory,
MakeTuple(GURL(path),
- base::Bind(&ReadDirectoryCallbackAdapater,
+ base::Bind(&ReadDirectoryCallbackAdapter,
CurrentWorkerId(), callbacks_id,
- base::Unretained(waitable_results)),
+ waitable_results_ptr),
base::Bind(&StatusCallbackAdapter,
CurrentWorkerId(), callbacks_id,
-base::Unretained(waitable_results))),
- make_scoped_ptr(waitable_results));
+ waitable_results_ptr)),
+ waitable_results.Pass());
}
void WebFileSystemImpl::createFileWriter(
@@ -560,40 +573,42 @@ void WebFileSystemImpl::createFileWriter(
blink::WebFileWriterClient* client,
WebFileSystemCallbacks callbacks) {
int callbacks_id = RegisterCallbacks(callbacks);
- WaitableCallbackResults* waitable_results =
+ scoped_ptr<WaitableCallbackResults> waitable_results =
WaitableCallbackResults::MaybeCreate(callbacks);
+ WaitableCallbackResults* waitable_results_ptr = waitable_results.get();
CallDispatcherOnMainThread(
main_thread_loop_.get(),
&FileSystemDispatcher::ReadMetadata,
MakeTuple(GURL(path),
base::Bind(&CreateFileWriterCallbackAdapter,
CurrentWorkerId(), callbacks_id,
- base::Unretained(waitable_results),
+ waitable_results_ptr,
main_thread_loop_, GURL(path), client),
base::Bind(&StatusCallbackAdapter,
CurrentWorkerId(), callbacks_id,
- base::Unretained(waitable_results))),
- make_scoped_ptr(waitable_results));
+ waitable_results_ptr)),
+ waitable_results.Pass());
}
void WebFileSystemImpl::createSnapshotFileAndReadMetadata(
const blink::WebURL& path,
WebFileSystemCallbacks callbacks) {
int callbacks_id = RegisterCallbacks(callbacks);
- WaitableCallbackResults* waitable_results =
+ scoped_ptr<WaitableCallbackResults> waitable_results =
WaitableCallbackResults::MaybeCreate(callbacks);
+ WaitableCallbackResults* waitable_results_ptr = waitable_results.get();
CallDispatcherOnMainThread(
main_thread_loop_.get(),
&FileSystemDispatcher::CreateSnapshotFile,
MakeTuple(GURL(path),
base::Bind(&CreateSnapshotFileCallbackAdapter,
CurrentWorkerId(), callbacks_id,
- base::Unretained(waitable_results),
+ waitable_results_ptr,
main_thread_loop_),
base::Bind(&StatusCallbackAdapter,
CurrentWorkerId(), callbacks_id,
- base::Unretained(waitable_results))),
- make_scoped_ptr(waitable_results));
+ waitable_results_ptr)),
+ waitable_results.Pass());
}
int WebFileSystemImpl::RegisterCallbacks(
« no previous file with comments | « no previous file | tools/valgrind/memcheck/suppressions.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698