Chromium Code Reviews| Index: net/http/http_cache.cc |
| diff --git a/net/http/http_cache.cc b/net/http/http_cache.cc |
| index 157059df10269303e14b82d5c0f49370bbd24d4d..97709f4a2100efd79f6600c077555b85a027f1c9 100644 |
| --- a/net/http/http_cache.cc |
| +++ b/net/http/http_cache.cc |
| @@ -463,6 +463,52 @@ void HttpCache::CloseAllConnections() { |
| session->CloseAllConnections(); |
| } |
| +class ReportExternalCacheHitJob { |
|
rvargas (doing something else)
2011/07/27 23:26:17
Maybe we can simplify this code if the disk cache
|
| + public: |
| + ReportExternalCacheHitJob(); |
| + void Start(HttpCache* cache, const GURL& url, const std::string& http_method); |
| + |
| + private: |
| + void OnIOComplete(int rv); |
| + |
| + HttpRequestInfo request_info_; |
| + CompletionCallbackImpl<ReportExternalCacheHitJob> io_callback_; |
| + scoped_ptr<HttpTransaction> trans_; |
| +}; |
| + |
| +ReportExternalCacheHitJob::ReportExternalCacheHitJob() : |
| + ALLOW_THIS_IN_INITIALIZER_LIST( |
| + io_callback_(this, &ReportExternalCacheHitJob::OnIOComplete)) { |
| +} |
| + |
| +void ReportExternalCacheHitJob::Start(HttpCache* cache, const GURL& url, |
| + const std::string& http_method) { |
| + DCHECK(cache); |
| + cache->CreateTransaction(&trans_); |
| + request_info_.url = url; |
| + request_info_.method = http_method; |
| + request_info_.load_flags = LOAD_ONLY_FROM_CACHE; |
| + int rv = trans_->Start(&request_info_, &io_callback_, BoundNetLog()); |
| + if (rv != ERR_IO_PENDING) { |
| + OnIOComplete(rv); |
| + } |
| +} |
| + |
| +void ReportExternalCacheHitJob::OnIOComplete(int rv) { |
| + DCHECK(trans_.get()); |
| + if (rv == OK) { |
| + trans_->UpdateRankForExternalCacheHit(); |
| + } |
| + delete this; |
| +} |
| + |
| +void HttpCache::ReportExternalCacheHit(const GURL& url, |
| + const std::string& http_method) { |
| + ReportExternalCacheHitJob* job = new ReportExternalCacheHitJob; |
| + job->Start(this, url, http_method); |
| + // Job will delete itself when finished. |
| +} |
| + |
| int HttpCache::CreateTransaction(scoped_ptr<HttpTransaction>* trans) { |
| // Do lazy initialization of disk cache if needed. |
| if (!disk_cache_.get()) |