| OLD | NEW |
| 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 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 thread_(thread) { | 48 thread_(thread) { |
| 49 } | 49 } |
| 50 | 50 |
| 51 HttpCache::DefaultBackend::~DefaultBackend() {} | 51 HttpCache::DefaultBackend::~DefaultBackend() {} |
| 52 | 52 |
| 53 // static | 53 // static |
| 54 HttpCache::BackendFactory* HttpCache::DefaultBackend::InMemory(int max_bytes) { | 54 HttpCache::BackendFactory* HttpCache::DefaultBackend::InMemory(int max_bytes) { |
| 55 return new DefaultBackend(MEMORY_CACHE, FilePath(), max_bytes, NULL); | 55 return new DefaultBackend(MEMORY_CACHE, FilePath(), max_bytes, NULL); |
| 56 } | 56 } |
| 57 | 57 |
| 58 int HttpCache::DefaultBackend::CreateBackend(disk_cache::Backend** backend, | 58 int HttpCache::DefaultBackend::CreateBackend(NetLog* net_log, |
| 59 disk_cache::Backend** backend, |
| 59 CompletionCallback* callback) { | 60 CompletionCallback* callback) { |
| 60 DCHECK_GE(max_bytes_, 0); | 61 DCHECK_GE(max_bytes_, 0); |
| 61 return disk_cache::CreateCacheBackend(type_, path_, max_bytes_, true, | 62 return disk_cache::CreateCacheBackend(type_, path_, max_bytes_, true, |
| 62 thread_, backend, callback); | 63 thread_, net_log, backend, callback); |
| 63 } | 64 } |
| 64 | 65 |
| 65 //----------------------------------------------------------------------------- | 66 //----------------------------------------------------------------------------- |
| 66 | 67 |
| 67 HttpCache::ActiveEntry::ActiveEntry(disk_cache::Entry* e) | 68 HttpCache::ActiveEntry::ActiveEntry(disk_cache::Entry* entry) |
| 68 : disk_entry(e), | 69 : disk_entry(entry), |
| 69 writer(NULL), | 70 writer(NULL), |
| 70 will_process_pending_queue(false), | 71 will_process_pending_queue(false), |
| 71 doomed(false) { | 72 doomed(false) { |
| 72 } | 73 } |
| 73 | 74 |
| 74 HttpCache::ActiveEntry::~ActiveEntry() { | 75 HttpCache::ActiveEntry::~ActiveEntry() { |
| 75 if (disk_entry) { | 76 if (disk_entry) { |
| 76 disk_entry->Close(); | 77 disk_entry->Close(); |
| 77 disk_entry = NULL; | 78 disk_entry = NULL; |
| 78 } | 79 } |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 | 281 |
| 281 HttpCache::HttpCache(HostResolver* host_resolver, | 282 HttpCache::HttpCache(HostResolver* host_resolver, |
| 282 DnsRRResolver* dnsrr_resolver, | 283 DnsRRResolver* dnsrr_resolver, |
| 283 DnsCertProvenanceChecker* dns_cert_checker_, | 284 DnsCertProvenanceChecker* dns_cert_checker_, |
| 284 ProxyService* proxy_service, | 285 ProxyService* proxy_service, |
| 285 SSLConfigService* ssl_config_service, | 286 SSLConfigService* ssl_config_service, |
| 286 HttpAuthHandlerFactory* http_auth_handler_factory, | 287 HttpAuthHandlerFactory* http_auth_handler_factory, |
| 287 HttpNetworkDelegate* network_delegate, | 288 HttpNetworkDelegate* network_delegate, |
| 288 NetLog* net_log, | 289 NetLog* net_log, |
| 289 BackendFactory* backend_factory) | 290 BackendFactory* backend_factory) |
| 290 : backend_factory_(backend_factory), | 291 : net_log_(net_log), |
| 292 backend_factory_(backend_factory), |
| 291 building_backend_(false), | 293 building_backend_(false), |
| 292 mode_(NORMAL), | 294 mode_(NORMAL), |
| 293 ssl_host_info_factory_(new SSLHostInfoFactoryAdaptor( | 295 ssl_host_info_factory_(new SSLHostInfoFactoryAdaptor( |
| 294 ALLOW_THIS_IN_INITIALIZER_LIST(this))), | 296 ALLOW_THIS_IN_INITIALIZER_LIST(this))), |
| 295 network_layer_(HttpNetworkLayer::CreateFactory(host_resolver, | 297 network_layer_(HttpNetworkLayer::CreateFactory(host_resolver, |
| 296 dnsrr_resolver, dns_cert_checker_, | 298 dnsrr_resolver, dns_cert_checker_, |
| 297 ssl_host_info_factory_.get(), | 299 ssl_host_info_factory_.get(), |
| 298 proxy_service, ssl_config_service, | 300 proxy_service, ssl_config_service, |
| 299 http_auth_handler_factory, network_delegate, net_log)), | 301 http_auth_handler_factory, network_delegate, net_log)), |
| 300 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)) { | 302 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)) { |
| 301 } | 303 } |
| 302 | 304 |
| 303 HttpCache::HttpCache(HttpNetworkSession* session, | 305 HttpCache::HttpCache(HttpNetworkSession* session, |
| 304 BackendFactory* backend_factory) | 306 BackendFactory* backend_factory) |
| 305 : backend_factory_(backend_factory), | 307 : net_log_(session->net_log()), |
| 308 backend_factory_(backend_factory), |
| 306 building_backend_(false), | 309 building_backend_(false), |
| 307 mode_(NORMAL), | 310 mode_(NORMAL), |
| 308 network_layer_(HttpNetworkLayer::CreateFactory(session)), | 311 network_layer_(HttpNetworkLayer::CreateFactory(session)), |
| 309 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)) { | 312 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)) { |
| 310 } | 313 } |
| 311 | 314 |
| 312 HttpCache::HttpCache(HttpTransactionFactory* network_layer, | 315 HttpCache::HttpCache(HttpTransactionFactory* network_layer, |
| 316 NetLog* net_log, |
| 313 BackendFactory* backend_factory) | 317 BackendFactory* backend_factory) |
| 314 : backend_factory_(backend_factory), | 318 : net_log_(net_log), |
| 319 backend_factory_(backend_factory), |
| 315 building_backend_(false), | 320 building_backend_(false), |
| 316 mode_(NORMAL), | 321 mode_(NORMAL), |
| 317 network_layer_(network_layer), | 322 network_layer_(network_layer), |
| 318 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)) { | 323 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)) { |
| 319 } | 324 } |
| 320 | 325 |
| 321 HttpCache::~HttpCache() { | 326 HttpCache::~HttpCache() { |
| 322 // If we have any active entries remaining, then we need to deactivate them. | 327 // 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 | 328 // 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 | 329 // 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 Loading... |
| 456 pending_op->pending_queue.push_back(item.release()); | 461 pending_op->pending_queue.push_back(item.release()); |
| 457 return ERR_IO_PENDING; | 462 return ERR_IO_PENDING; |
| 458 } | 463 } |
| 459 | 464 |
| 460 DCHECK(pending_op->pending_queue.empty()); | 465 DCHECK(pending_op->pending_queue.empty()); |
| 461 | 466 |
| 462 pending_op->writer = item.release(); | 467 pending_op->writer = item.release(); |
| 463 BackendCallback* my_callback = new BackendCallback(this, pending_op); | 468 BackendCallback* my_callback = new BackendCallback(this, pending_op); |
| 464 pending_op->callback = my_callback; | 469 pending_op->callback = my_callback; |
| 465 | 470 |
| 466 int rv = backend_factory_->CreateBackend(&pending_op->backend, my_callback); | 471 int rv = backend_factory_->CreateBackend(net_log_, &pending_op->backend, |
| 472 my_callback); |
| 467 if (rv != ERR_IO_PENDING) { | 473 if (rv != ERR_IO_PENDING) { |
| 468 pending_op->writer->ClearCallback(); | 474 pending_op->writer->ClearCallback(); |
| 469 my_callback->Run(rv); | 475 my_callback->Run(rv); |
| 470 } | 476 } |
| 471 | 477 |
| 472 return rv; | 478 return rv; |
| 473 } | 479 } |
| 474 | 480 |
| 475 int HttpCache::GetBackendForTransaction(Transaction* trans) { | 481 int HttpCache::GetBackendForTransaction(Transaction* trans) { |
| 476 if (disk_cache_.get()) | 482 if (disk_cache_.get()) |
| (...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 950 } | 956 } |
| 951 | 957 |
| 952 // Promote next transaction from the pending queue. | 958 // Promote next transaction from the pending queue. |
| 953 Transaction* next = entry->pending_queue.front(); | 959 Transaction* next = entry->pending_queue.front(); |
| 954 if ((next->mode() & Transaction::WRITE) && !entry->readers.empty()) | 960 if ((next->mode() & Transaction::WRITE) && !entry->readers.empty()) |
| 955 return; // Have to wait. | 961 return; // Have to wait. |
| 956 | 962 |
| 957 entry->pending_queue.erase(entry->pending_queue.begin()); | 963 entry->pending_queue.erase(entry->pending_queue.begin()); |
| 958 | 964 |
| 959 int rv = AddTransactionToEntry(entry, next); | 965 int rv = AddTransactionToEntry(entry, next); |
| 960 if (rv != ERR_IO_PENDING) { | 966 if (rv != ERR_IO_PENDING) |
| 961 next->io_callback()->Run(rv); | 967 next->io_callback()->Run(rv); |
| 962 } | |
| 963 } | 968 } |
| 964 | 969 |
| 965 void HttpCache::OnIOComplete(int result, PendingOp* pending_op) { | 970 void HttpCache::OnIOComplete(int result, PendingOp* pending_op) { |
| 966 WorkItemOperation op = pending_op->writer->operation(); | 971 WorkItemOperation op = pending_op->writer->operation(); |
| 967 | 972 |
| 968 // Completing the creation of the backend is simpler than the other cases. | 973 // Completing the creation of the backend is simpler than the other cases. |
| 969 if (op == WI_CREATE_BACKEND) | 974 if (op == WI_CREATE_BACKEND) |
| 970 return OnBackendCreated(result, pending_op); | 975 return OnBackendCreated(result, pending_op); |
| 971 | 976 |
| 972 scoped_ptr<WorkItem> item(pending_op->writer); | 977 scoped_ptr<WorkItem> item(pending_op->writer); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1086 building_backend_ = false; | 1091 building_backend_ = false; |
| 1087 DeletePendingOp(pending_op); | 1092 DeletePendingOp(pending_op); |
| 1088 } | 1093 } |
| 1089 | 1094 |
| 1090 // The cache may be gone when we return from the callback. | 1095 // The cache may be gone when we return from the callback. |
| 1091 if (!item->DoCallback(result, backend)) | 1096 if (!item->DoCallback(result, backend)) |
| 1092 item->NotifyTransaction(result, NULL); | 1097 item->NotifyTransaction(result, NULL); |
| 1093 } | 1098 } |
| 1094 | 1099 |
| 1095 } // namespace net | 1100 } // namespace net |
| OLD | NEW |