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

Unified Diff: net/http/http_cache.cc

Issue 7461106: Inform disk cache of WebKit memory cache hits. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 5 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
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())

Powered by Google App Engine
This is Rietveld 408576698