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

Side by Side Diff: net/http/http_cache.cc

Issue 10909136: Http Cache: Add code for simulating an infinite HTTP cache. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 3 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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
11 #if defined(OS_POSIX) 11 #if defined(OS_POSIX)
12 #include <unistd.h> 12 #include <unistd.h>
13 #endif 13 #endif
14 14
15 #include "base/bind.h" 15 #include "base/bind.h"
16 #include "base/bind_helpers.h" 16 #include "base/bind_helpers.h"
17 #include "base/callback.h" 17 #include "base/callback.h"
18 #include "base/format_macros.h" 18 #include "base/format_macros.h"
19 #include "base/location.h" 19 #include "base/location.h"
20 #include "base/memory/ref_counted.h" 20 #include "base/memory/ref_counted.h"
21 #include "base/message_loop.h" 21 #include "base/message_loop.h"
22 #include "base/metrics/field_trial.h"
22 #include "base/pickle.h" 23 #include "base/pickle.h"
23 #include "base/stl_util.h" 24 #include "base/stl_util.h"
24 #include "base/string_number_conversions.h" 25 #include "base/string_number_conversions.h"
25 #include "base/string_util.h" 26 #include "base/string_util.h"
26 #include "base/stringprintf.h" 27 #include "base/stringprintf.h"
27 #include "net/base/io_buffer.h" 28 #include "net/base/io_buffer.h"
28 #include "net/base/load_flags.h" 29 #include "net/base/load_flags.h"
29 #include "net/base/net_errors.h" 30 #include "net/base/net_errors.h"
30 #include "net/disk_cache/disk_cache.h" 31 #include "net/disk_cache/disk_cache.h"
31 #include "net/http/http_cache_transaction.h" 32 #include "net/http/http_cache_transaction.h"
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 int buf_len) { 403 int buf_len) {
403 if (!buf_len) 404 if (!buf_len)
404 return; 405 return;
405 406
406 // Do lazy initialization of disk cache if needed. 407 // Do lazy initialization of disk cache if needed.
407 if (!disk_cache_.get()) { 408 if (!disk_cache_.get()) {
408 // We don't care about the result. 409 // We don't care about the result.
409 CreateBackend(NULL, net::CompletionCallback()); 410 CreateBackend(NULL, net::CompletionCallback());
410 } 411 }
411 412
412 HttpCache::Transaction* trans = new HttpCache::Transaction(this, NULL); 413 HttpCache::Transaction* trans = new HttpCache::Transaction(this, NULL, NULL);
413 MetadataWriter* writer = new MetadataWriter(trans); 414 MetadataWriter* writer = new MetadataWriter(trans);
414 415
415 // The writer will self destruct when done. 416 // The writer will self destruct when done.
416 writer->Write(url, expected_response_time, buf, buf_len); 417 writer->Write(url, expected_response_time, buf, buf_len);
417 } 418 }
418 419
419 void HttpCache::CloseAllConnections() { 420 void HttpCache::CloseAllConnections() {
420 net::HttpNetworkLayer* network = 421 net::HttpNetworkLayer* network =
421 static_cast<net::HttpNetworkLayer*>(network_layer_.get()); 422 static_cast<net::HttpNetworkLayer*>(network_layer_.get());
422 HttpNetworkSession* session = network->GetSession(); 423 HttpNetworkSession* session = network->GetSession();
(...skipping 14 matching lines...) Expand all
437 if (!disk_cache_.get()) 438 if (!disk_cache_.get())
438 return; 439 return;
439 440
440 HttpRequestInfo request_info; 441 HttpRequestInfo request_info;
441 request_info.url = url; 442 request_info.url = url;
442 request_info.method = http_method; 443 request_info.method = http_method;
443 std::string key = GenerateCacheKey(&request_info); 444 std::string key = GenerateCacheKey(&request_info);
444 disk_cache_->OnExternalCacheHit(key); 445 disk_cache_->OnExternalCacheHit(key);
445 } 446 }
446 447
448 void HttpCache::InitializeInfiniteCache(const FilePath& path) {
449 if (base::FieldTrialList::FindFullName("InfiniteCache") != "Yes")
450 return;
451 // To be enabled after everything is fully wired.
452 // infinite_cache_.Init(path);
453 }
454
447 int HttpCache::CreateTransaction(scoped_ptr<HttpTransaction>* trans, 455 int HttpCache::CreateTransaction(scoped_ptr<HttpTransaction>* trans,
448 HttpTransactionDelegate* delegate) { 456 HttpTransactionDelegate* delegate) {
449 // Do lazy initialization of disk cache if needed. 457 // Do lazy initialization of disk cache if needed.
450 if (!disk_cache_.get()) { 458 if (!disk_cache_.get()) {
451 // We don't care about the result. 459 // We don't care about the result.
452 CreateBackend(NULL, net::CompletionCallback()); 460 CreateBackend(NULL, net::CompletionCallback());
453 } 461 }
454 462
455 trans->reset(new HttpCache::Transaction(this, delegate)); 463 InfiniteCacheTransaction* infinite_cache_transaction =
464 infinite_cache_.CreateInfiniteCacheTransaction();
465 trans->reset(new HttpCache::Transaction(this, delegate,
466 infinite_cache_transaction));
456 return OK; 467 return OK;
457 } 468 }
458 469
459 HttpCache* HttpCache::GetCache() { 470 HttpCache* HttpCache::GetCache() {
460 return this; 471 return this;
461 } 472 }
462 473
463 HttpNetworkSession* HttpCache::GetSession() { 474 HttpNetworkSession* HttpCache::GetSession() {
464 net::HttpNetworkLayer* network = 475 net::HttpNetworkLayer* network =
465 static_cast<net::HttpNetworkLayer*>(network_layer_.get()); 476 static_cast<net::HttpNetworkLayer*>(network_layer_.get());
(...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after
1147 building_backend_ = false; 1158 building_backend_ = false;
1148 DeletePendingOp(pending_op); 1159 DeletePendingOp(pending_op);
1149 } 1160 }
1150 1161
1151 // The cache may be gone when we return from the callback. 1162 // The cache may be gone when we return from the callback.
1152 if (!item->DoCallback(result, backend)) 1163 if (!item->DoCallback(result, backend))
1153 item->NotifyTransaction(result, NULL); 1164 item->NotifyTransaction(result, NULL);
1154 } 1165 }
1155 1166
1156 } // namespace net 1167 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698