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

Unified Diff: content/browser/appcache/appcache_disk_cache.cc

Issue 1136373003: AppCache: Ensure inflight ActiveCalls are not destroyed (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/appcache/appcache_disk_cache.cc
diff --git a/content/browser/appcache/appcache_disk_cache.cc b/content/browser/appcache/appcache_disk_cache.cc
index 382ed45fed2197ae8be5b861e1f310d18a118694..79efd83887941a68d4eb5d00ce1b621e1f5874bb 100644
--- a/content/browser/appcache/appcache_disk_cache.cc
+++ b/content/browser/appcache/appcache_disk_cache.cc
@@ -119,14 +119,15 @@ class AppCacheDiskCache::ActiveCall {
explicit ActiveCall(AppCacheDiskCache* owner)
: entry_(NULL),
owner_(owner),
- entry_ptr_(NULL) {
+ entry_ptr_(NULL),
+ weak_factory_(this) {
}
int CreateEntry(int64 key, Entry** entry,
const net::CompletionCallback& callback) {
int rv = owner_->disk_cache()->CreateEntry(
base::Int64ToString(key), &entry_ptr_,
- base::Bind(&ActiveCall::OnAsyncCompletion, base::Unretained(this)));
+ base::Bind(&ActiveCall::OnAsyncCompletion, weak_factory_.GetWeakPtr()));
michaeln 2015/05/14 02:25:01 I remember there being a difference in behavior be
nhiroki 2015/05/14 04:27:05 I haven't had an absolute proof yet, but it seems
return HandleImmediateReturnValue(rv, entry, callback);
}
@@ -134,17 +135,22 @@ class AppCacheDiskCache::ActiveCall {
const net::CompletionCallback& callback) {
int rv = owner_->disk_cache()->OpenEntry(
base::Int64ToString(key), &entry_ptr_,
- base::Bind(&ActiveCall::OnAsyncCompletion, base::Unretained(this)));
+ base::Bind(&ActiveCall::OnAsyncCompletion, weak_factory_.GetWeakPtr()));
return HandleImmediateReturnValue(rv, entry, callback);
}
int DoomEntry(int64 key, const net::CompletionCallback& callback) {
int rv = owner_->disk_cache()->DoomEntry(
base::Int64ToString(key),
- base::Bind(&ActiveCall::OnAsyncCompletion, base::Unretained(this)));
+ base::Bind(&ActiveCall::OnAsyncCompletion, weak_factory_.GetWeakPtr()));
return HandleImmediateReturnValue(rv, NULL, callback);
}
+ void Abort() {
+ callback_.Run(net::ERR_ABORTED);
+ delete this;
+ }
+
private:
int HandleImmediateReturnValue(int rv, Entry** entry,
const net::CompletionCallback& callback) {
@@ -166,7 +172,6 @@ class AppCacheDiskCache::ActiveCall {
if (rv == net::OK && entry_)
*entry_ = new EntryImpl(entry_ptr_, owner_);
callback_.Run(rv);
- callback_.Reset();
delete this;
}
@@ -174,6 +179,8 @@ class AppCacheDiskCache::ActiveCall {
net::CompletionCallback callback_;
AppCacheDiskCache* owner_;
disk_cache::Entry* entry_ptr_;
+
+ base::WeakPtrFactory<AppCacheDiskCache::ActiveCall> weak_factory_;
};
AppCacheDiskCache::AppCacheDiskCache()
@@ -225,7 +232,10 @@ void AppCacheDiskCache::Disable() {
}
open_entries_.clear();
disk_cache_.reset();
- STLDeleteElements(&active_calls_);
+
+ for (AppCacheDiskCache::ActiveCall* active_call : active_calls_)
+ active_call->Abort();
+ active_calls_.clear();
}
int AppCacheDiskCache::CreateEntry(int64 key, Entry** entry,
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698