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

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

Issue 4067002: First pass at adding http/backend cache to NetLog (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Add back mysteriously missing files Created 10 years 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/callback.h" 15 #include "base/callback.h"
16 #include "base/format_macros.h" 16 #include "base/format_macros.h"
17 #include "base/message_loop.h" 17 #include "base/message_loop.h"
18 #include "base/pickle.h" 18 #include "base/pickle.h"
19 #include "base/ref_counted.h" 19 #include "base/ref_counted.h"
20 #include "base/stl_util-inl.h" 20 #include "base/stl_util-inl.h"
21 #include "base/string_number_conversions.h" 21 #include "base/string_number_conversions.h"
22 #include "base/string_util.h" 22 #include "base/string_util.h"
23 #include "base/stringprintf.h" 23 #include "base/stringprintf.h"
24 #include "base/values.h"
24 #include "net/base/io_buffer.h" 25 #include "net/base/io_buffer.h"
25 #include "net/base/load_flags.h" 26 #include "net/base/load_flags.h"
26 #include "net/base/net_errors.h" 27 #include "net/base/net_errors.h"
27 #include "net/disk_cache/disk_cache.h" 28 #include "net/disk_cache/disk_cache.h"
28 #include "net/http/disk_cache_based_ssl_host_info.h" 29 #include "net/http/disk_cache_based_ssl_host_info.h"
29 #include "net/http/http_cache_transaction.h" 30 #include "net/http/http_cache_transaction.h"
30 #include "net/http/http_network_layer.h" 31 #include "net/http/http_network_layer.h"
31 #include "net/http/http_network_session.h" 32 #include "net/http/http_network_session.h"
32 #include "net/http/http_request_info.h" 33 #include "net/http/http_request_info.h"
33 #include "net/http/http_response_headers.h" 34 #include "net/http/http_response_headers.h"
(...skipping 14 matching lines...) Expand all
48 thread_(thread) { 49 thread_(thread) {
49 } 50 }
50 51
51 HttpCache::DefaultBackend::~DefaultBackend() {} 52 HttpCache::DefaultBackend::~DefaultBackend() {}
52 53
53 // static 54 // static
54 HttpCache::BackendFactory* HttpCache::DefaultBackend::InMemory(int max_bytes) { 55 HttpCache::BackendFactory* HttpCache::DefaultBackend::InMemory(int max_bytes) {
55 return new DefaultBackend(MEMORY_CACHE, FilePath(), max_bytes, NULL); 56 return new DefaultBackend(MEMORY_CACHE, FilePath(), max_bytes, NULL);
56 } 57 }
57 58
58 int HttpCache::DefaultBackend::CreateBackend(disk_cache::Backend** backend, 59 int HttpCache::DefaultBackend::CreateBackend(NetLog* net_log,
60 disk_cache::Backend** backend,
59 CompletionCallback* callback) { 61 CompletionCallback* callback) {
60 DCHECK_GE(max_bytes_, 0); 62 DCHECK_GE(max_bytes_, 0);
61 return disk_cache::CreateCacheBackend(type_, path_, max_bytes_, true, 63 return disk_cache::CreateCacheBackend(type_, path_, max_bytes_, true,
62 thread_, backend, callback); 64 thread_, net_log, backend, callback);
63 } 65 }
64 66
65 //----------------------------------------------------------------------------- 67 //-----------------------------------------------------------------------------
66 68
67 HttpCache::ActiveEntry::ActiveEntry(disk_cache::Entry* e) 69 HttpCache::ActiveEntry::ActiveEntry(disk_cache::Entry* entry)
68 : disk_entry(e), 70 : disk_entry(entry),
69 writer(NULL), 71 writer(NULL),
70 will_process_pending_queue(false), 72 will_process_pending_queue(false),
71 doomed(false) { 73 doomed(false) {
72 } 74 }
73 75
74 HttpCache::ActiveEntry::~ActiveEntry() { 76 HttpCache::ActiveEntry::~ActiveEntry() {
75 if (disk_entry) { 77 if (disk_entry) {
76 disk_entry->Close(); 78 disk_entry->Close();
77 disk_entry = NULL; 79 disk_entry = NULL;
78 } 80 }
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 282
281 HttpCache::HttpCache(HostResolver* host_resolver, 283 HttpCache::HttpCache(HostResolver* host_resolver,
282 DnsRRResolver* dnsrr_resolver, 284 DnsRRResolver* dnsrr_resolver,
283 DnsCertProvenanceChecker* dns_cert_checker_, 285 DnsCertProvenanceChecker* dns_cert_checker_,
284 ProxyService* proxy_service, 286 ProxyService* proxy_service,
285 SSLConfigService* ssl_config_service, 287 SSLConfigService* ssl_config_service,
286 HttpAuthHandlerFactory* http_auth_handler_factory, 288 HttpAuthHandlerFactory* http_auth_handler_factory,
287 HttpNetworkDelegate* network_delegate, 289 HttpNetworkDelegate* network_delegate,
288 NetLog* net_log, 290 NetLog* net_log,
289 BackendFactory* backend_factory) 291 BackendFactory* backend_factory)
290 : backend_factory_(backend_factory), 292 : net_log_(net_log),
293 backend_factory_(backend_factory),
291 building_backend_(false), 294 building_backend_(false),
292 mode_(NORMAL), 295 mode_(NORMAL),
293 ssl_host_info_factory_(new SSLHostInfoFactoryAdaptor( 296 ssl_host_info_factory_(new SSLHostInfoFactoryAdaptor(
294 ALLOW_THIS_IN_INITIALIZER_LIST(this))), 297 ALLOW_THIS_IN_INITIALIZER_LIST(this))),
295 network_layer_(HttpNetworkLayer::CreateFactory(host_resolver, 298 network_layer_(HttpNetworkLayer::CreateFactory(host_resolver,
296 dnsrr_resolver, dns_cert_checker_, 299 dnsrr_resolver, dns_cert_checker_,
297 ssl_host_info_factory_.get(), 300 ssl_host_info_factory_.get(),
298 proxy_service, ssl_config_service, 301 proxy_service, ssl_config_service,
299 http_auth_handler_factory, network_delegate, net_log)), 302 http_auth_handler_factory, network_delegate, net_log)),
300 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)) { 303 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)) {
301 } 304 }
302 305
303 HttpCache::HttpCache(HttpNetworkSession* session, 306 HttpCache::HttpCache(HttpNetworkSession* session,
304 BackendFactory* backend_factory) 307 BackendFactory* backend_factory)
305 : backend_factory_(backend_factory), 308 : net_log_(session->net_log()),
309 backend_factory_(backend_factory),
306 building_backend_(false), 310 building_backend_(false),
307 mode_(NORMAL), 311 mode_(NORMAL),
308 network_layer_(HttpNetworkLayer::CreateFactory(session)), 312 network_layer_(HttpNetworkLayer::CreateFactory(session)),
309 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)) { 313 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)) {
310 } 314 }
311 315
312 HttpCache::HttpCache(HttpTransactionFactory* network_layer, 316 HttpCache::HttpCache(HttpTransactionFactory* network_layer,
313 BackendFactory* backend_factory) 317 BackendFactory* backend_factory,
314 : backend_factory_(backend_factory), 318 NetLog* net_log)
319 : net_log_(net_log),
320 backend_factory_(backend_factory),
315 building_backend_(false), 321 building_backend_(false),
316 mode_(NORMAL), 322 mode_(NORMAL),
317 network_layer_(network_layer), 323 network_layer_(network_layer),
318 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)) { 324 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)) {
319 } 325 }
320 326
321 HttpCache::~HttpCache() { 327 HttpCache::~HttpCache() {
322 // If we have any active entries remaining, then we need to deactivate them. 328 // If we have any active entries remaining, then we need to deactivate them.
323 // We may have some pending calls to OnProcessPendingQueue, but since those 329 // We may have some pending calls to OnProcessPendingQueue, but since those
324 // won't run (due to our destruction), we can simply ignore the corresponding 330 // won't run (due to our destruction), we can simply ignore the corresponding
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 pending_op->pending_queue.push_back(item.release()); 462 pending_op->pending_queue.push_back(item.release());
457 return ERR_IO_PENDING; 463 return ERR_IO_PENDING;
458 } 464 }
459 465
460 DCHECK(pending_op->pending_queue.empty()); 466 DCHECK(pending_op->pending_queue.empty());
461 467
462 pending_op->writer = item.release(); 468 pending_op->writer = item.release();
463 BackendCallback* my_callback = new BackendCallback(this, pending_op); 469 BackendCallback* my_callback = new BackendCallback(this, pending_op);
464 pending_op->callback = my_callback; 470 pending_op->callback = my_callback;
465 471
466 int rv = backend_factory_->CreateBackend(&pending_op->backend, my_callback); 472 int rv = backend_factory_->CreateBackend(net_log_, &pending_op->backend,
473 my_callback);
467 if (rv != ERR_IO_PENDING) { 474 if (rv != ERR_IO_PENDING) {
468 pending_op->writer->ClearCallback(); 475 pending_op->writer->ClearCallback();
469 my_callback->Run(rv); 476 my_callback->Run(rv);
470 } 477 }
471 478
472 return rv; 479 return rv;
473 } 480 }
474 481
475 int HttpCache::GetBackendForTransaction(Transaction* trans) { 482 int HttpCache::GetBackendForTransaction(Transaction* trans) {
476 if (disk_cache_.get()) 483 if (disk_cache_.get())
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 732
726 void HttpCache::DestroyEntry(ActiveEntry* entry) { 733 void HttpCache::DestroyEntry(ActiveEntry* entry) {
727 if (entry->doomed) { 734 if (entry->doomed) {
728 FinalizeDoomedEntry(entry); 735 FinalizeDoomedEntry(entry);
729 } else { 736 } else {
730 DeactivateEntry(entry); 737 DeactivateEntry(entry);
731 } 738 }
732 } 739 }
733 740
734 int HttpCache::AddTransactionToEntry(ActiveEntry* entry, Transaction* trans) { 741 int HttpCache::AddTransactionToEntry(ActiveEntry* entry, Transaction* trans) {
742 int result = AddTransactionToEntryInternal(entry, trans);
743 if (result == ERR_IO_PENDING) {
744 trans->net_log().BeginEvent(
745 NetLog::TYPE_ACTIVE_ENTRY_QUEUE,
rvargas (doing something else) 2010/12/13 23:34:39 This seems to do the same as TYPE_HTTP_CACHE_ADD_T
mmenke 2010/12/14 17:53:43 Removed. If we decide we really want queue length
746 new NetLogIntegerParameter("queue_size", entry->pending_queue.size()));
747 }
748 return result;
749 }
750
751 int HttpCache::AddTransactionToEntryInternal(ActiveEntry* entry,
752 Transaction* trans) {
735 DCHECK(entry); 753 DCHECK(entry);
736 DCHECK(entry->disk_entry); 754 DCHECK(entry->disk_entry);
737 755
738 // We implement a basic reader/writer lock for the disk cache entry. If 756 // We implement a basic reader/writer lock for the disk cache entry. If
739 // there is already a writer, then everyone has to wait for the writer to 757 // there is already a writer, then everyone has to wait for the writer to
740 // finish before they can access the cache entry. There can be multiple 758 // finish before they can access the cache entry. There can be multiple
741 // readers. 759 // readers.
742 // 760 //
743 // NOTE: If the transaction can only write, then the entry should not be in 761 // NOTE: If the transaction can only write, then the entry should not be in
744 // use (since any existing entry should have already been doomed). 762 // use (since any existing entry should have already been doomed).
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
949 return; 967 return;
950 } 968 }
951 969
952 // Promote next transaction from the pending queue. 970 // Promote next transaction from the pending queue.
953 Transaction* next = entry->pending_queue.front(); 971 Transaction* next = entry->pending_queue.front();
954 if ((next->mode() & Transaction::WRITE) && !entry->readers.empty()) 972 if ((next->mode() & Transaction::WRITE) && !entry->readers.empty())
955 return; // Have to wait. 973 return; // Have to wait.
956 974
957 entry->pending_queue.erase(entry->pending_queue.begin()); 975 entry->pending_queue.erase(entry->pending_queue.begin());
958 976
959 int rv = AddTransactionToEntry(entry, next); 977 int rv = AddTransactionToEntryInternal(entry, next);
960 if (rv != ERR_IO_PENDING) { 978 if (rv != ERR_IO_PENDING) {
979 next->net_log().EndEvent(NetLog::TYPE_ACTIVE_ENTRY_QUEUE, NULL);
961 next->io_callback()->Run(rv); 980 next->io_callback()->Run(rv);
962 } 981 }
963 } 982 }
964 983
965 void HttpCache::OnIOComplete(int result, PendingOp* pending_op) { 984 void HttpCache::OnIOComplete(int result, PendingOp* pending_op) {
966 WorkItemOperation op = pending_op->writer->operation(); 985 WorkItemOperation op = pending_op->writer->operation();
967 986
968 // Completing the creation of the backend is simpler than the other cases. 987 // Completing the creation of the backend is simpler than the other cases.
969 if (op == WI_CREATE_BACKEND) 988 if (op == WI_CREATE_BACKEND)
970 return OnBackendCreated(result, pending_op); 989 return OnBackendCreated(result, pending_op);
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
1086 building_backend_ = false; 1105 building_backend_ = false;
1087 DeletePendingOp(pending_op); 1106 DeletePendingOp(pending_op);
1088 } 1107 }
1089 1108
1090 // The cache may be gone when we return from the callback. 1109 // The cache may be gone when we return from the callback.
1091 if (!item->DoCallback(result, backend)) 1110 if (!item->DoCallback(result, backend))
1092 item->NotifyTransaction(result, NULL); 1111 item->NotifyTransaction(result, NULL);
1093 } 1112 }
1094 1113
1095 } // namespace net 1114 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698