diff options
author | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-25 23:34:34 +0000 |
---|---|---|
committer | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-25 23:34:34 +0000 |
commit | 59326aacf6020c3cfa8978a334c36b2dcc1a99bb (patch) | |
tree | 698940cee180d498131c98b9efbb2de30b642161 /net | |
parent | 754f7e974507e71f6ac40eec66bcb73f13d868c6 (diff) | |
download | chromium_src-59326aacf6020c3cfa8978a334c36b2dcc1a99bb.zip chromium_src-59326aacf6020c3cfa8978a334c36b2dcc1a99bb.tar.gz chromium_src-59326aacf6020c3cfa8978a334c36b2dcc1a99bb.tar.bz2 |
Implement ScopedRunnableMethodFactory using WeakPtr.
This required some changes to WeakPtr to support the addition
of WeakPtrFactory::HasWeakPtrs(), which is used to implement
ScopedRunnableMethodFactory::empty().
Now, the WeakReferenceOwner just holds a pointer to the Flag
class, and the Flag holds a back-pointer that it can use to
clear the WeakReferenceOwner's pointer when the Flag is
destroyed. I use the null'ness of this back-pointer in place
of the bool member that was previously used to indicate if the
WeakReference is valid.
It was also necessary to expose a HasOneRef method on
RefCounted. I included one on RefCountedThreadSafe for
completeness.
Finally, I switched HttpCache over to using WeakPtr instead
of RevocableStore so that I could delete RevocableStore.
(I'm making this change to consolidate similar functionality.)
R=abarth
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/235027
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27287 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/http/http_cache.cc | 32 | ||||
-rw-r--r-- | net/http/http_cache.h | 6 |
2 files changed, 18 insertions, 20 deletions
diff --git a/net/http/http_cache.cc b/net/http/http_cache.cc index 6703661..c1c3478 100644 --- a/net/http/http_cache.cc +++ b/net/http/http_cache.cc @@ -168,13 +168,11 @@ HttpCache::ActiveEntry::~ActiveEntry() { //----------------------------------------------------------------------------- -class HttpCache::Transaction - : public HttpTransaction, public RevocableStore::Revocable { +class HttpCache::Transaction : public HttpTransaction { public: Transaction(HttpCache* cache, bool enable_range_support) - : RevocableStore::Revocable(&cache->transactions_), - request_(NULL), - cache_(cache), + : request_(NULL), + cache_(cache->AsWeakPtr()), entry_(NULL), network_trans_(NULL), callback_(NULL), @@ -382,7 +380,7 @@ class HttpCache::Transaction // If extra_headers specified a "if-modified-since" or "if-none-match", // |external_validation_| contains the value of that header. ValidationHeader external_validation_; - HttpCache* cache_; + base::WeakPtr<HttpCache> cache_; HttpCache::ActiveEntry* entry_; scoped_ptr<HttpTransaction> network_trans_; CompletionCallback* callback_; // Consumer's callback. @@ -407,7 +405,7 @@ class HttpCache::Transaction }; HttpCache::Transaction::~Transaction() { - if (!revoked()) { + if (cache_) { if (entry_) { bool cancel_request = reading_ && enable_range_support_; if (cancel_request && !partial_.get()) @@ -425,7 +423,7 @@ HttpCache::Transaction::~Transaction() { // We could still have a cache read in progress, so we just null the cache_ // pointer to signal that we are dead. See OnCacheReadCompleted. - cache_ = NULL; + cache_.reset(); } int HttpCache::Transaction::Start(const HttpRequestInfo* request, @@ -437,7 +435,7 @@ int HttpCache::Transaction::Start(const HttpRequestInfo* request, // ensure that we only have one asynchronous call at a time. DCHECK(!callback_); - if (revoked()) + if (!cache_) return ERR_UNEXPECTED; SetRequest(load_log, request); @@ -493,7 +491,7 @@ int HttpCache::Transaction::RestartIgnoringLastError( // ensure that we only have one asynchronous call at a time. DCHECK(!callback_); - if (revoked()) + if (!cache_) return ERR_UNEXPECTED; int rv = RestartNetworkRequest(); @@ -512,7 +510,7 @@ int HttpCache::Transaction::RestartWithCertificate( // ensure that we only have one asynchronous call at a time. DCHECK(!callback_); - if (revoked()) + if (!cache_) return ERR_UNEXPECTED; int rv = RestartNetworkRequestWithCertificate(client_cert); @@ -533,7 +531,7 @@ int HttpCache::Transaction::RestartWithAuth( // Ensure that we only have one asynchronous call at a time. DCHECK(!callback_); - if (revoked()) + if (!cache_) return ERR_UNEXPECTED; // Clear the intermediate response since we are going to start over. @@ -561,7 +559,7 @@ int HttpCache::Transaction::Read(IOBuffer* buf, int buf_len, DCHECK(!callback_); - if (revoked()) + if (!cache_) return ERR_UNEXPECTED; // If we have an intermediate auth response at this point, then it means the @@ -629,7 +627,7 @@ uint64 HttpCache::Transaction::GetUploadProgress() const { int HttpCache::Transaction::AddToEntry() { ActiveEntry* entry = NULL; - if (revoked()) + if (!cache_) return ERR_UNEXPECTED; if (mode_ == WRITE) { @@ -1396,7 +1394,7 @@ void HttpCache::Transaction::DoomPartialEntry(bool delete_object) { int HttpCache::Transaction::DoNetworkReadCompleted(int result) { DCHECK(mode_ & WRITE || mode_ == NONE); - if (revoked()) + if (!cache_) return HandleResult(ERR_UNEXPECTED); AppendResponseDataToEntry(read_buf_, result); @@ -1431,7 +1429,7 @@ int HttpCache::Transaction::DoCacheReadCompleted(int result) { DCHECK(cache_); cache_read_callback_->Release(); // Balance the AddRef() from Start(). - if (revoked()) + if (!cache_) return HandleResult(ERR_UNEXPECTED); if (partial_.get()) @@ -1467,7 +1465,7 @@ int HttpCache::Transaction::DoPartialCacheReadCompleted(int result) { void HttpCache::Transaction::OnNetworkInfoAvailable(int result) { DCHECK(result != ERR_IO_PENDING); - if (revoked()) { + if (!cache_) { HandleResult(ERR_UNEXPECTED); return; } diff --git a/net/http/http_cache.h b/net/http/http_cache.h index 652f3a4..15163b07 100644 --- a/net/http/http_cache.h +++ b/net/http/http_cache.h @@ -21,6 +21,7 @@ #include "base/hash_tables.h" #include "base/scoped_ptr.h" #include "base/task.h" +#include "base/weak_ptr.h" #include "net/base/cache_type.h" #include "net/http/http_transaction_factory.h" @@ -38,7 +39,8 @@ class HttpResponseInfo; class ProxyService; class SSLConfigService; -class HttpCache : public HttpTransactionFactory { +class HttpCache : public HttpTransactionFactory, + public base::SupportsWeakPtr<HttpCache> { public: ~HttpCache(); @@ -206,8 +208,6 @@ class HttpCache : public HttpTransactionFactory { typedef base::hash_map<std::string, int> PlaybackCacheMap; scoped_ptr<PlaybackCacheMap> playback_cache_map_; - RevocableStore transactions_; - DISALLOW_COPY_AND_ASSIGN(HttpCache); }; |