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

Side by Side 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, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/http/http_cache.h" 5 #include "net/http/http_cache.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 10
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 } 456 }
457 457
458 void HttpCache::CloseAllConnections() { 458 void HttpCache::CloseAllConnections() {
459 net::HttpNetworkLayer* network = 459 net::HttpNetworkLayer* network =
460 static_cast<net::HttpNetworkLayer*>(network_layer_.get()); 460 static_cast<net::HttpNetworkLayer*>(network_layer_.get());
461 HttpNetworkSession* session = network->GetSession(); 461 HttpNetworkSession* session = network->GetSession();
462 if (session) 462 if (session)
463 session->CloseAllConnections(); 463 session->CloseAllConnections();
464 } 464 }
465 465
466 class ReportExternalCacheHitJob {
rvargas (doing something else) 2011/07/27 23:26:17 Maybe we can simplify this code if the disk cache
467 public:
468 ReportExternalCacheHitJob();
469 void Start(HttpCache* cache, const GURL& url, const std::string& http_method);
470
471 private:
472 void OnIOComplete(int rv);
473
474 HttpRequestInfo request_info_;
475 CompletionCallbackImpl<ReportExternalCacheHitJob> io_callback_;
476 scoped_ptr<HttpTransaction> trans_;
477 };
478
479 ReportExternalCacheHitJob::ReportExternalCacheHitJob() :
480 ALLOW_THIS_IN_INITIALIZER_LIST(
481 io_callback_(this, &ReportExternalCacheHitJob::OnIOComplete)) {
482 }
483
484 void ReportExternalCacheHitJob::Start(HttpCache* cache, const GURL& url,
485 const std::string& http_method) {
486 DCHECK(cache);
487 cache->CreateTransaction(&trans_);
488 request_info_.url = url;
489 request_info_.method = http_method;
490 request_info_.load_flags = LOAD_ONLY_FROM_CACHE;
491 int rv = trans_->Start(&request_info_, &io_callback_, BoundNetLog());
492 if (rv != ERR_IO_PENDING) {
493 OnIOComplete(rv);
494 }
495 }
496
497 void ReportExternalCacheHitJob::OnIOComplete(int rv) {
498 DCHECK(trans_.get());
499 if (rv == OK) {
500 trans_->UpdateRankForExternalCacheHit();
501 }
502 delete this;
503 }
504
505 void HttpCache::ReportExternalCacheHit(const GURL& url,
506 const std::string& http_method) {
507 ReportExternalCacheHitJob* job = new ReportExternalCacheHitJob;
508 job->Start(this, url, http_method);
509 // Job will delete itself when finished.
510 }
511
466 int HttpCache::CreateTransaction(scoped_ptr<HttpTransaction>* trans) { 512 int HttpCache::CreateTransaction(scoped_ptr<HttpTransaction>* trans) {
467 // Do lazy initialization of disk cache if needed. 513 // Do lazy initialization of disk cache if needed.
468 if (!disk_cache_.get()) 514 if (!disk_cache_.get())
469 CreateBackend(NULL, NULL); // We don't care about the result. 515 CreateBackend(NULL, NULL); // We don't care about the result.
470 516
471 trans->reset(new HttpCache::Transaction(this)); 517 trans->reset(new HttpCache::Transaction(this));
472 return OK; 518 return OK;
473 } 519 }
474 520
475 HttpCache* HttpCache::GetCache() { 521 HttpCache* HttpCache::GetCache() {
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after
1133 building_backend_ = false; 1179 building_backend_ = false;
1134 DeletePendingOp(pending_op); 1180 DeletePendingOp(pending_op);
1135 } 1181 }
1136 1182
1137 // The cache may be gone when we return from the callback. 1183 // The cache may be gone when we return from the callback.
1138 if (!item->DoCallback(result, backend)) 1184 if (!item->DoCallback(result, backend))
1139 item->NotifyTransaction(result, NULL); 1185 item->NotifyTransaction(result, NULL);
1140 } 1186 }
1141 1187
1142 } // namespace net 1188 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698