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 |
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" |
34 #include "net/http/http_response_info.h" | 35 #include "net/http/http_response_info.h" |
35 #include "net/http/http_util.h" | 36 #include "net/http/http_util.h" |
36 #include "net/socket/ssl_host_info.h" | 37 #include "net/socket/ssl_host_info.h" |
37 #include "net/spdy/spdy_session_pool.h" | 38 #include "net/spdy/spdy_session_pool.h" |
38 | 39 |
39 namespace net { | 40 namespace net { |
40 | 41 |
| 42 namespace { |
| 43 |
| 44 class ActiveEntryCreationParameters : public NetLog::EventParameters { |
| 45 public: |
| 46 ActiveEntryCreationParameters(std::string key, const NetLog::Source& source) |
| 47 : key_(key), source_(source) { |
| 48 } |
| 49 |
| 50 virtual Value* ToValue() const { |
| 51 DictionaryValue* dict = new DictionaryValue(); |
| 52 dict->SetString("key", key_); |
| 53 dict->Set("source_dependency", source_.ToValue()); |
| 54 return dict; |
| 55 } |
| 56 |
| 57 private: |
| 58 const std::string key_; |
| 59 const NetLog::Source source_; |
| 60 }; |
| 61 |
| 62 // Used for adding and queuing both read and write transactions. |
| 63 class AddTransactionParams : public NetLog::EventParameters { |
| 64 public: |
| 65 AddTransactionParams(const NetLog::Source& source, size_t queue_length) |
| 66 : source_(source), queue_length_(queue_length) { |
| 67 } |
| 68 |
| 69 virtual Value* ToValue() const { |
| 70 DictionaryValue* dict = new DictionaryValue(); |
| 71 dict->Set("source_dependency", source_.ToValue()); |
| 72 if (queue_length_ > 0) |
| 73 dict->SetInteger("queue_length", queue_length_); |
| 74 return dict; |
| 75 } |
| 76 |
| 77 private: |
| 78 const NetLog::Source source_; |
| 79 size_t queue_length_; |
| 80 }; |
| 81 |
| 82 } // namespace |
| 83 |
41 HttpCache::DefaultBackend::DefaultBackend(CacheType type, | 84 HttpCache::DefaultBackend::DefaultBackend(CacheType type, |
42 const FilePath& path, | 85 const FilePath& path, |
43 int max_bytes, | 86 int max_bytes, |
44 base::MessageLoopProxy* thread) | 87 base::MessageLoopProxy* thread) |
45 : type_(type), | 88 : type_(type), |
46 path_(path), | 89 path_(path), |
47 max_bytes_(max_bytes), | 90 max_bytes_(max_bytes), |
48 thread_(thread) { | 91 thread_(thread) { |
49 } | 92 } |
50 | 93 |
51 HttpCache::DefaultBackend::~DefaultBackend() {} | 94 HttpCache::DefaultBackend::~DefaultBackend() {} |
52 | 95 |
53 // static | 96 // static |
54 HttpCache::BackendFactory* HttpCache::DefaultBackend::InMemory(int max_bytes) { | 97 HttpCache::BackendFactory* HttpCache::DefaultBackend::InMemory(int max_bytes) { |
55 return new DefaultBackend(MEMORY_CACHE, FilePath(), max_bytes, NULL); | 98 return new DefaultBackend(MEMORY_CACHE, FilePath(), max_bytes, NULL); |
56 } | 99 } |
57 | 100 |
58 int HttpCache::DefaultBackend::CreateBackend(disk_cache::Backend** backend, | 101 int HttpCache::DefaultBackend::CreateBackend(disk_cache::Backend** backend, |
59 CompletionCallback* callback) { | 102 CompletionCallback* callback, |
| 103 NetLog* net_log) { |
60 DCHECK_GE(max_bytes_, 0); | 104 DCHECK_GE(max_bytes_, 0); |
61 return disk_cache::CreateCacheBackend(type_, path_, max_bytes_, true, | 105 return disk_cache::CreateCacheBackend(type_, path_, max_bytes_, true, |
62 thread_, backend, callback); | 106 thread_, backend, callback, net_log); |
63 } | 107 } |
64 | 108 |
65 //----------------------------------------------------------------------------- | 109 //----------------------------------------------------------------------------- |
66 | 110 |
67 HttpCache::ActiveEntry::ActiveEntry(disk_cache::Entry* e) | 111 HttpCache::ActiveEntry::ActiveEntry(disk_cache::Entry* entry, NetLog* log) |
68 : disk_entry(e), | 112 : disk_entry(entry), |
69 writer(NULL), | 113 writer(NULL), |
70 will_process_pending_queue(false), | 114 will_process_pending_queue(false), |
71 doomed(false) { | 115 doomed(false), |
| 116 net_log(BoundNetLog::Make(log, NetLog::SOURCE_HTTP_CACHE_ACTIVE_ENTRY)) { |
| 117 net_log.BeginEvent(NetLog::TYPE_HTTP_CACHE_ACTIVE_ENTRY, |
| 118 new NetLogStringParameter("key", entry->GetKey())); |
72 } | 119 } |
73 | 120 |
74 HttpCache::ActiveEntry::~ActiveEntry() { | 121 HttpCache::ActiveEntry::~ActiveEntry() { |
| 122 net_log.EndEvent(NetLog::TYPE_HTTP_CACHE_ACTIVE_ENTRY, NULL); |
75 if (disk_entry) { | 123 if (disk_entry) { |
76 disk_entry->Close(); | 124 disk_entry->Close(); |
77 disk_entry = NULL; | 125 disk_entry = NULL; |
78 } | 126 } |
79 } | 127 } |
80 | 128 |
81 //----------------------------------------------------------------------------- | 129 //----------------------------------------------------------------------------- |
82 | 130 |
83 // This structure keeps track of work items that are attempting to create or | 131 // This structure keeps track of work items that are attempting to create or |
84 // open cache entries or the backend itself. | 132 // open cache entries or the backend itself. |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 | 328 |
281 HttpCache::HttpCache(HostResolver* host_resolver, | 329 HttpCache::HttpCache(HostResolver* host_resolver, |
282 DnsRRResolver* dnsrr_resolver, | 330 DnsRRResolver* dnsrr_resolver, |
283 DnsCertProvenanceChecker* dns_cert_checker_, | 331 DnsCertProvenanceChecker* dns_cert_checker_, |
284 ProxyService* proxy_service, | 332 ProxyService* proxy_service, |
285 SSLConfigService* ssl_config_service, | 333 SSLConfigService* ssl_config_service, |
286 HttpAuthHandlerFactory* http_auth_handler_factory, | 334 HttpAuthHandlerFactory* http_auth_handler_factory, |
287 HttpNetworkDelegate* network_delegate, | 335 HttpNetworkDelegate* network_delegate, |
288 NetLog* net_log, | 336 NetLog* net_log, |
289 BackendFactory* backend_factory) | 337 BackendFactory* backend_factory) |
290 : backend_factory_(backend_factory), | 338 : net_log_(net_log), |
| 339 backend_factory_(backend_factory), |
291 building_backend_(false), | 340 building_backend_(false), |
292 mode_(NORMAL), | 341 mode_(NORMAL), |
293 ssl_host_info_factory_(new SSLHostInfoFactoryAdaptor( | 342 ssl_host_info_factory_(new SSLHostInfoFactoryAdaptor( |
294 ALLOW_THIS_IN_INITIALIZER_LIST(this))), | 343 ALLOW_THIS_IN_INITIALIZER_LIST(this))), |
295 network_layer_(HttpNetworkLayer::CreateFactory(host_resolver, | 344 network_layer_(HttpNetworkLayer::CreateFactory(host_resolver, |
296 dnsrr_resolver, dns_cert_checker_, | 345 dnsrr_resolver, dns_cert_checker_, |
297 ssl_host_info_factory_.get(), | 346 ssl_host_info_factory_.get(), |
298 proxy_service, ssl_config_service, | 347 proxy_service, ssl_config_service, |
299 http_auth_handler_factory, network_delegate, net_log)), | 348 http_auth_handler_factory, network_delegate, net_log)), |
300 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)) { | 349 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)) { |
301 } | 350 } |
302 | 351 |
303 HttpCache::HttpCache(HttpNetworkSession* session, | 352 HttpCache::HttpCache(HttpNetworkSession* session, |
304 BackendFactory* backend_factory) | 353 BackendFactory* backend_factory) |
305 : backend_factory_(backend_factory), | 354 : net_log_(session->net_log()), |
| 355 backend_factory_(backend_factory), |
306 building_backend_(false), | 356 building_backend_(false), |
307 mode_(NORMAL), | 357 mode_(NORMAL), |
308 network_layer_(HttpNetworkLayer::CreateFactory(session)), | 358 network_layer_(HttpNetworkLayer::CreateFactory(session)), |
309 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)) { | 359 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)) { |
310 } | 360 } |
311 | 361 |
312 HttpCache::HttpCache(HttpTransactionFactory* network_layer, | 362 HttpCache::HttpCache(HttpTransactionFactory* network_layer, |
313 BackendFactory* backend_factory) | 363 BackendFactory* backend_factory, |
314 : backend_factory_(backend_factory), | 364 NetLog* net_log) |
| 365 : net_log_(net_log), |
| 366 backend_factory_(backend_factory), |
315 building_backend_(false), | 367 building_backend_(false), |
316 mode_(NORMAL), | 368 mode_(NORMAL), |
317 network_layer_(network_layer), | 369 network_layer_(network_layer), |
318 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)) { | 370 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)) { |
319 } | 371 } |
320 | 372 |
321 HttpCache::~HttpCache() { | 373 HttpCache::~HttpCache() { |
322 // If we have any active entries remaining, then we need to deactivate them. | 374 // 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 | 375 // 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 | 376 // 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()); | 508 pending_op->pending_queue.push_back(item.release()); |
457 return ERR_IO_PENDING; | 509 return ERR_IO_PENDING; |
458 } | 510 } |
459 | 511 |
460 DCHECK(pending_op->pending_queue.empty()); | 512 DCHECK(pending_op->pending_queue.empty()); |
461 | 513 |
462 pending_op->writer = item.release(); | 514 pending_op->writer = item.release(); |
463 BackendCallback* my_callback = new BackendCallback(this, pending_op); | 515 BackendCallback* my_callback = new BackendCallback(this, pending_op); |
464 pending_op->callback = my_callback; | 516 pending_op->callback = my_callback; |
465 | 517 |
466 int rv = backend_factory_->CreateBackend(&pending_op->backend, my_callback); | 518 int rv = backend_factory_->CreateBackend(&pending_op->backend, my_callback, |
| 519 net_log_); |
467 if (rv != ERR_IO_PENDING) { | 520 if (rv != ERR_IO_PENDING) { |
468 pending_op->writer->ClearCallback(); | 521 pending_op->writer->ClearCallback(); |
469 my_callback->Run(rv); | 522 my_callback->Run(rv); |
470 } | 523 } |
471 | 524 |
472 return rv; | 525 return rv; |
473 } | 526 } |
474 | 527 |
475 int HttpCache::GetBackendForTransaction(Transaction* trans) { | 528 int HttpCache::GetBackendForTransaction(Transaction* trans) { |
476 if (disk_cache_.get()) | 529 if (disk_cache_.get()) |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 // longer be returned by FindActiveEntry (and it will also be destroyed once | 584 // longer be returned by FindActiveEntry (and it will also be destroyed once |
532 // all consumers are finished with the entry). | 585 // all consumers are finished with the entry). |
533 ActiveEntriesMap::iterator it = active_entries_.find(key); | 586 ActiveEntriesMap::iterator it = active_entries_.find(key); |
534 if (it == active_entries_.end()) { | 587 if (it == active_entries_.end()) { |
535 return AsyncDoomEntry(key, trans); | 588 return AsyncDoomEntry(key, trans); |
536 } | 589 } |
537 | 590 |
538 ActiveEntry* entry = it->second; | 591 ActiveEntry* entry = it->second; |
539 active_entries_.erase(it); | 592 active_entries_.erase(it); |
540 | 593 |
| 594 entry->net_log.AddEvent(NetLog::TYPE_ACTIVE_ENTRY_DOOM, NULL); |
| 595 |
541 // We keep track of doomed entries so that we can ensure that they are | 596 // We keep track of doomed entries so that we can ensure that they are |
542 // cleaned up properly when the cache is destroyed. | 597 // cleaned up properly when the cache is destroyed. |
543 doomed_entries_.insert(entry); | 598 doomed_entries_.insert(entry); |
544 | 599 |
545 entry->disk_entry->Doom(); | 600 entry->disk_entry->Doom(); |
546 entry->doomed = true; | 601 entry->doomed = true; |
547 | 602 |
548 DCHECK(entry->writer || !entry->readers.empty()); | 603 DCHECK(entry->writer || !entry->readers.empty()); |
549 return OK; | 604 return OK; |
550 } | 605 } |
(...skipping 21 matching lines...) Expand all Loading... |
572 | 627 |
573 return rv; | 628 return rv; |
574 } | 629 } |
575 | 630 |
576 void HttpCache::FinalizeDoomedEntry(ActiveEntry* entry) { | 631 void HttpCache::FinalizeDoomedEntry(ActiveEntry* entry) { |
577 DCHECK(entry->doomed); | 632 DCHECK(entry->doomed); |
578 DCHECK(!entry->writer); | 633 DCHECK(!entry->writer); |
579 DCHECK(entry->readers.empty()); | 634 DCHECK(entry->readers.empty()); |
580 DCHECK(entry->pending_queue.empty()); | 635 DCHECK(entry->pending_queue.empty()); |
581 | 636 |
| 637 entry->net_log.AddEvent(NetLog::TYPE_ACTIVE_ENTRY_FINALIZE_DOOMED_ENTRY, |
| 638 NULL); |
| 639 |
582 ActiveEntriesSet::iterator it = doomed_entries_.find(entry); | 640 ActiveEntriesSet::iterator it = doomed_entries_.find(entry); |
583 DCHECK(it != doomed_entries_.end()); | 641 DCHECK(it != doomed_entries_.end()); |
584 doomed_entries_.erase(it); | 642 doomed_entries_.erase(it); |
585 | 643 |
586 delete entry; | 644 delete entry; |
587 } | 645 } |
588 | 646 |
589 HttpCache::ActiveEntry* HttpCache::FindActiveEntry(const std::string& key) { | 647 HttpCache::ActiveEntry* HttpCache::FindActiveEntry(const std::string& key) { |
590 ActiveEntriesMap::const_iterator it = active_entries_.find(key); | 648 ActiveEntriesMap::const_iterator it = active_entries_.find(key); |
591 return it != active_entries_.end() ? it->second : NULL; | 649 return it != active_entries_.end() ? it->second : NULL; |
592 } | 650 } |
593 | 651 |
594 HttpCache::ActiveEntry* HttpCache::ActivateEntry( | 652 HttpCache::ActiveEntry* HttpCache::ActivateEntry( |
595 disk_cache::Entry* disk_entry) { | 653 disk_cache::Entry* disk_entry) { |
596 DCHECK(!FindActiveEntry(disk_entry->GetKey())); | 654 DCHECK(!FindActiveEntry(disk_entry->GetKey())); |
597 ActiveEntry* entry = new ActiveEntry(disk_entry); | 655 ActiveEntry* entry = new ActiveEntry(disk_entry, net_log_); |
598 active_entries_[disk_entry->GetKey()] = entry; | 656 active_entries_[disk_entry->GetKey()] = entry; |
599 return entry; | 657 return entry; |
600 } | 658 } |
601 | 659 |
602 void HttpCache::DeactivateEntry(ActiveEntry* entry) { | 660 void HttpCache::DeactivateEntry(ActiveEntry* entry) { |
603 DCHECK(!entry->will_process_pending_queue); | 661 DCHECK(!entry->will_process_pending_queue); |
604 DCHECK(!entry->doomed); | 662 DCHECK(!entry->doomed); |
605 DCHECK(!entry->writer); | 663 DCHECK(!entry->writer); |
606 DCHECK(entry->disk_entry); | 664 DCHECK(entry->disk_entry); |
607 DCHECK(entry->readers.empty()); | 665 DCHECK(entry->readers.empty()); |
608 DCHECK(entry->pending_queue.empty()); | 666 DCHECK(entry->pending_queue.empty()); |
609 | 667 |
| 668 entry->net_log.AddEvent(NetLog::TYPE_ACTIVE_ENTRY_DEACTIVATE, NULL); |
| 669 |
610 std::string key = entry->disk_entry->GetKey(); | 670 std::string key = entry->disk_entry->GetKey(); |
611 if (key.empty()) | 671 if (key.empty()) |
612 return SlowDeactivateEntry(entry); | 672 return SlowDeactivateEntry(entry); |
613 | 673 |
614 ActiveEntriesMap::iterator it = active_entries_.find(key); | 674 ActiveEntriesMap::iterator it = active_entries_.find(key); |
615 DCHECK(it != active_entries_.end()); | 675 DCHECK(it != active_entries_.end()); |
616 DCHECK(it->second == entry); | 676 DCHECK(it->second == entry); |
617 | 677 |
618 active_entries_.erase(it); | 678 active_entries_.erase(it); |
619 delete entry; | 679 delete entry; |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 | 785 |
726 void HttpCache::DestroyEntry(ActiveEntry* entry) { | 786 void HttpCache::DestroyEntry(ActiveEntry* entry) { |
727 if (entry->doomed) { | 787 if (entry->doomed) { |
728 FinalizeDoomedEntry(entry); | 788 FinalizeDoomedEntry(entry); |
729 } else { | 789 } else { |
730 DeactivateEntry(entry); | 790 DeactivateEntry(entry); |
731 } | 791 } |
732 } | 792 } |
733 | 793 |
734 int HttpCache::AddTransactionToEntry(ActiveEntry* entry, Transaction* trans) { | 794 int HttpCache::AddTransactionToEntry(ActiveEntry* entry, Transaction* trans) { |
| 795 int result = AddTransactionToEntryInternal(entry, trans); |
| 796 if (result == ERR_IO_PENDING) { |
| 797 entry->net_log.AddEvent( |
| 798 NetLog::TYPE_ACTIVE_ENTRY_ADD_TO_QUEUE, |
| 799 new AddTransactionParams(trans->net_log().source(), |
| 800 entry->pending_queue.size())); |
| 801 } |
| 802 return result; |
| 803 } |
| 804 |
| 805 int HttpCache::AddTransactionToEntryInternal(ActiveEntry* entry, |
| 806 Transaction* trans) { |
735 DCHECK(entry); | 807 DCHECK(entry); |
736 DCHECK(entry->disk_entry); | 808 DCHECK(entry->disk_entry); |
737 | 809 |
738 // We implement a basic reader/writer lock for the disk cache entry. If | 810 // 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 | 811 // 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 | 812 // finish before they can access the cache entry. There can be multiple |
741 // readers. | 813 // readers. |
742 // | 814 // |
743 // NOTE: If the transaction can only write, then the entry should not be in | 815 // 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). | 816 // use (since any existing entry should have already been doomed). |
745 | 817 |
746 if (entry->writer || entry->will_process_pending_queue) { | 818 if (entry->writer || entry->will_process_pending_queue) { |
747 entry->pending_queue.push_back(trans); | 819 entry->pending_queue.push_back(trans); |
748 return ERR_IO_PENDING; | 820 return ERR_IO_PENDING; |
749 } | 821 } |
750 | 822 |
751 if (trans->mode() & Transaction::WRITE) { | 823 if (trans->mode() & Transaction::WRITE) { |
752 // transaction needs exclusive access to the entry | 824 // transaction needs exclusive access to the entry |
753 if (entry->readers.empty()) { | 825 if (entry->readers.empty()) { |
754 entry->writer = trans; | 826 entry->writer = trans; |
| 827 entry->net_log.BeginEvent( |
| 828 NetLog::TYPE_ACTIVE_ENTRY_SET_WRITER, |
| 829 new AddTransactionParams(trans->net_log().source(), |
| 830 entry->pending_queue.size())); |
755 } else { | 831 } else { |
756 entry->pending_queue.push_back(trans); | 832 entry->pending_queue.push_back(trans); |
757 return ERR_IO_PENDING; | 833 return ERR_IO_PENDING; |
758 } | 834 } |
759 } else { | 835 } else { |
760 // transaction needs read access to the entry | 836 // transaction needs read access to the entry |
761 entry->readers.push_back(trans); | 837 entry->readers.push_back(trans); |
| 838 entry->net_log.AddEvent( |
| 839 NetLog::TYPE_ACTIVE_ENTRY_ADD_READER, |
| 840 new AddTransactionParams(trans->net_log().source(), |
| 841 entry->pending_queue.size())); |
762 } | 842 } |
763 | 843 |
764 // We do this before calling EntryAvailable to force any further calls to | 844 // We do this before calling EntryAvailable to force any further calls to |
765 // AddTransactionToEntry to add their transaction to the pending queue, which | 845 // AddTransactionToEntry to add their transaction to the pending queue, which |
766 // ensures FIFO ordering. | 846 // ensures FIFO ordering. |
767 if (!entry->writer && !entry->pending_queue.empty()) | 847 if (!entry->writer && !entry->pending_queue.empty()) |
768 ProcessPendingQueue(entry); | 848 ProcessPendingQueue(entry); |
769 | 849 |
770 return OK; | 850 return OK; |
771 } | 851 } |
(...skipping 19 matching lines...) Expand all Loading... |
791 DoneWritingToEntry(entry, success); | 871 DoneWritingToEntry(entry, success); |
792 } else { | 872 } else { |
793 DoneReadingFromEntry(entry, trans); | 873 DoneReadingFromEntry(entry, trans); |
794 } | 874 } |
795 } | 875 } |
796 | 876 |
797 void HttpCache::DoneWritingToEntry(ActiveEntry* entry, bool success) { | 877 void HttpCache::DoneWritingToEntry(ActiveEntry* entry, bool success) { |
798 DCHECK(entry->readers.empty()); | 878 DCHECK(entry->readers.empty()); |
799 | 879 |
800 entry->writer = NULL; | 880 entry->writer = NULL; |
| 881 entry->net_log.EndEvent(NetLog::TYPE_ACTIVE_ENTRY_SET_WRITER, NULL); |
801 | 882 |
802 if (success) { | 883 if (success) { |
803 ProcessPendingQueue(entry); | 884 ProcessPendingQueue(entry); |
804 } else { | 885 } else { |
805 DCHECK(!entry->will_process_pending_queue); | 886 DCHECK(!entry->will_process_pending_queue); |
806 | 887 |
807 // We failed to create this entry. | 888 // We failed to create this entry. |
808 TransactionList pending_queue; | 889 TransactionList pending_queue; |
809 pending_queue.swap(entry->pending_queue); | 890 pending_queue.swap(entry->pending_queue); |
810 | 891 |
(...skipping 11 matching lines...) Expand all Loading... |
822 } | 903 } |
823 | 904 |
824 void HttpCache::DoneReadingFromEntry(ActiveEntry* entry, Transaction* trans) { | 905 void HttpCache::DoneReadingFromEntry(ActiveEntry* entry, Transaction* trans) { |
825 DCHECK(!entry->writer); | 906 DCHECK(!entry->writer); |
826 | 907 |
827 TransactionList::iterator it = | 908 TransactionList::iterator it = |
828 std::find(entry->readers.begin(), entry->readers.end(), trans); | 909 std::find(entry->readers.begin(), entry->readers.end(), trans); |
829 DCHECK(it != entry->readers.end()); | 910 DCHECK(it != entry->readers.end()); |
830 | 911 |
831 entry->readers.erase(it); | 912 entry->readers.erase(it); |
| 913 entry->net_log.AddEvent( |
| 914 NetLog::TYPE_ACTIVE_ENTRY_REMOVE_READER, |
| 915 new NetLogSourceParameter("source_dependency", |
| 916 trans->net_log().source())); |
832 | 917 |
833 ProcessPendingQueue(entry); | 918 ProcessPendingQueue(entry); |
834 } | 919 } |
835 | 920 |
836 void HttpCache::ConvertWriterToReader(ActiveEntry* entry) { | 921 void HttpCache::ConvertWriterToReader(ActiveEntry* entry) { |
837 DCHECK(entry->writer); | 922 DCHECK(entry->writer); |
838 DCHECK(entry->writer->mode() == Transaction::READ_WRITE); | 923 DCHECK(entry->writer->mode() == Transaction::READ_WRITE); |
839 DCHECK(entry->readers.empty()); | 924 DCHECK(entry->readers.empty()); |
840 | 925 |
841 Transaction* trans = entry->writer; | 926 Transaction* trans = entry->writer; |
842 | 927 |
843 entry->writer = NULL; | 928 entry->writer = NULL; |
| 929 entry->net_log.EndEvent(NetLog::TYPE_ACTIVE_ENTRY_SET_WRITER, NULL); |
844 entry->readers.push_back(trans); | 930 entry->readers.push_back(trans); |
| 931 entry->net_log.AddEvent( |
| 932 NetLog::TYPE_ACTIVE_ENTRY_ADD_READER, |
| 933 new NetLogSourceParameter("source_dependency", |
| 934 trans->net_log().source())); |
845 | 935 |
846 ProcessPendingQueue(entry); | 936 ProcessPendingQueue(entry); |
847 } | 937 } |
848 | 938 |
849 LoadState HttpCache::GetLoadStateForPendingTransaction( | 939 LoadState HttpCache::GetLoadStateForPendingTransaction( |
850 const Transaction* trans) { | 940 const Transaction* trans) { |
851 ActiveEntriesMap::const_iterator i = active_entries_.find(trans->key()); | 941 ActiveEntriesMap::const_iterator i = active_entries_.find(trans->key()); |
852 if (i == active_entries_.end()) { | 942 if (i == active_entries_.end()) { |
853 // If this is really a pending transaction, and it is not part of | 943 // If this is really a pending transaction, and it is not part of |
854 // active_entries_, we should be creating the backend or the entry. | 944 // active_entries_, we should be creating the backend or the entry. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
893 | 983 |
894 bool HttpCache::RemovePendingTransactionFromEntry(ActiveEntry* entry, | 984 bool HttpCache::RemovePendingTransactionFromEntry(ActiveEntry* entry, |
895 Transaction* trans) { | 985 Transaction* trans) { |
896 TransactionList& pending_queue = entry->pending_queue; | 986 TransactionList& pending_queue = entry->pending_queue; |
897 | 987 |
898 TransactionList::iterator j = | 988 TransactionList::iterator j = |
899 find(pending_queue.begin(), pending_queue.end(), trans); | 989 find(pending_queue.begin(), pending_queue.end(), trans); |
900 if (j == pending_queue.end()) | 990 if (j == pending_queue.end()) |
901 return false; | 991 return false; |
902 | 992 |
| 993 entry->net_log.AddEvent( |
| 994 NetLog::TYPE_ACTIVE_ENTRY_REMOVE_PENDING_TRANSACTION, |
| 995 new NetLogSourceParameter("source_dependency", |
| 996 trans->net_log().source())); |
903 pending_queue.erase(j); | 997 pending_queue.erase(j); |
904 return true; | 998 return true; |
905 } | 999 } |
906 | 1000 |
907 bool HttpCache::RemovePendingTransactionFromPendingOp(PendingOp* pending_op, | 1001 bool HttpCache::RemovePendingTransactionFromPendingOp(PendingOp* pending_op, |
908 Transaction* trans) { | 1002 Transaction* trans) { |
909 if (pending_op->writer->Matches(trans)) { | 1003 if (pending_op->writer->Matches(trans)) { |
910 pending_op->writer->ClearTransaction(); | 1004 pending_op->writer->ClearTransaction(); |
911 pending_op->writer->ClearEntry(); | 1005 pending_op->writer->ClearEntry(); |
912 return true; | 1006 return true; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
949 return; | 1043 return; |
950 } | 1044 } |
951 | 1045 |
952 // Promote next transaction from the pending queue. | 1046 // Promote next transaction from the pending queue. |
953 Transaction* next = entry->pending_queue.front(); | 1047 Transaction* next = entry->pending_queue.front(); |
954 if ((next->mode() & Transaction::WRITE) && !entry->readers.empty()) | 1048 if ((next->mode() & Transaction::WRITE) && !entry->readers.empty()) |
955 return; // Have to wait. | 1049 return; // Have to wait. |
956 | 1050 |
957 entry->pending_queue.erase(entry->pending_queue.begin()); | 1051 entry->pending_queue.erase(entry->pending_queue.begin()); |
958 | 1052 |
959 int rv = AddTransactionToEntry(entry, next); | 1053 int rv = AddTransactionToEntryInternal(entry, next); |
960 if (rv != ERR_IO_PENDING) { | 1054 if (rv != ERR_IO_PENDING) { |
961 next->io_callback()->Run(rv); | 1055 next->io_callback()->Run(rv); |
962 } | 1056 } |
963 } | 1057 } |
964 | 1058 |
965 void HttpCache::OnIOComplete(int result, PendingOp* pending_op) { | 1059 void HttpCache::OnIOComplete(int result, PendingOp* pending_op) { |
966 WorkItemOperation op = pending_op->writer->operation(); | 1060 WorkItemOperation op = pending_op->writer->operation(); |
967 | 1061 |
968 // Completing the creation of the backend is simpler than the other cases. | 1062 // Completing the creation of the backend is simpler than the other cases. |
969 if (op == WI_CREATE_BACKEND) | 1063 if (op == WI_CREATE_BACKEND) |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1086 building_backend_ = false; | 1180 building_backend_ = false; |
1087 DeletePendingOp(pending_op); | 1181 DeletePendingOp(pending_op); |
1088 } | 1182 } |
1089 | 1183 |
1090 // The cache may be gone when we return from the callback. | 1184 // The cache may be gone when we return from the callback. |
1091 if (!item->DoCallback(result, backend)) | 1185 if (!item->DoCallback(result, backend)) |
1092 item->NotifyTransaction(result, NULL); | 1186 item->NotifyTransaction(result, NULL); |
1093 } | 1187 } |
1094 | 1188 |
1095 } // namespace net | 1189 } // namespace net |
OLD | NEW |