| OLD | NEW |
| 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 "extensions/browser/extension_throttle_manager.h" | 5 #include "extensions/browser/extension_throttle_manager.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 url_id_replacements_.ClearPassword(); | 33 url_id_replacements_.ClearPassword(); |
| 34 url_id_replacements_.ClearUsername(); | 34 url_id_replacements_.ClearUsername(); |
| 35 url_id_replacements_.ClearQuery(); | 35 url_id_replacements_.ClearQuery(); |
| 36 url_id_replacements_.ClearRef(); | 36 url_id_replacements_.ClearRef(); |
| 37 | 37 |
| 38 net::NetworkChangeNotifier::AddIPAddressObserver(this); | 38 net::NetworkChangeNotifier::AddIPAddressObserver(this); |
| 39 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); | 39 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); |
| 40 } | 40 } |
| 41 | 41 |
| 42 ExtensionThrottleManager::~ExtensionThrottleManager() { | 42 ExtensionThrottleManager::~ExtensionThrottleManager() { |
| 43 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 43 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); | 44 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); |
| 44 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); | 45 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); |
| 45 | 46 |
| 46 // Since the manager object might conceivably go away before the | 47 // Since the manager object might conceivably go away before the |
| 47 // entries, detach the entries' back-pointer to the manager. | 48 // entries, detach the entries' back-pointer to the manager. |
| 48 UrlEntryMap::iterator i = url_entries_.begin(); | 49 UrlEntryMap::iterator i = url_entries_.begin(); |
| 49 while (i != url_entries_.end()) { | 50 while (i != url_entries_.end()) { |
| 50 if (i->second.get() != NULL) { | 51 if (i->second.get() != NULL) { |
| 51 i->second->DetachManager(); | 52 i->second->DetachManager(); |
| 52 } | 53 } |
| 53 ++i; | 54 ++i; |
| 54 } | 55 } |
| 55 | 56 |
| 56 // Delete all entries. | 57 // Delete all entries. |
| 57 url_entries_.clear(); | 58 url_entries_.clear(); |
| 58 } | 59 } |
| 59 | 60 |
| 60 std::unique_ptr<content::ResourceThrottle> | 61 std::unique_ptr<content::ResourceThrottle> |
| 61 ExtensionThrottleManager::MaybeCreateThrottle(const net::URLRequest* request) { | 62 ExtensionThrottleManager::MaybeCreateThrottle(const net::URLRequest* request) { |
| 62 if (request->first_party_for_cookies().scheme() != | 63 if (request->first_party_for_cookies().scheme() != |
| 63 extensions::kExtensionScheme) { | 64 extensions::kExtensionScheme) { |
| 64 return nullptr; | 65 return nullptr; |
| 65 } | 66 } |
| 66 return base::MakeUnique<extensions::ExtensionRequestLimitingThrottle>(request, | 67 return base::MakeUnique<extensions::ExtensionRequestLimitingThrottle>(request, |
| 67 this); | 68 this); |
| 68 } | 69 } |
| 69 | 70 |
| 70 scoped_refptr<ExtensionThrottleEntryInterface> | 71 scoped_refptr<ExtensionThrottleEntryInterface> |
| 71 ExtensionThrottleManager::RegisterRequestUrl(const GURL& url) { | 72 ExtensionThrottleManager::RegisterRequestUrl(const GURL& url) { |
| 72 DCHECK(!enable_thread_checks_ || CalledOnValidThread()); | 73 #if DCHECK_IS_ON() |
| 74 DCHECK(!enable_thread_checks_ || sequence_checker_.CalledOnValidSequence()); |
| 75 #endif // DCHECK_IS_ON() |
| 73 | 76 |
| 74 // Normalize the url. | 77 // Normalize the url. |
| 75 std::string url_id = GetIdFromUrl(url); | 78 std::string url_id = GetIdFromUrl(url); |
| 76 | 79 |
| 77 // Periodically garbage collect old entries. | 80 // Periodically garbage collect old entries. |
| 78 GarbageCollectEntriesIfNecessary(); | 81 GarbageCollectEntriesIfNecessary(); |
| 79 | 82 |
| 80 // Find the entry in the map or create a new NULL entry. | 83 // Find the entry in the map or create a new NULL entry. |
| 81 scoped_refptr<ExtensionThrottleEntry>& entry = url_entries_[url_id]; | 84 scoped_refptr<ExtensionThrottleEntry>& entry = url_entries_[url_id]; |
| 82 | 85 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 void ExtensionThrottleManager::OnNetworkChange() { | 214 void ExtensionThrottleManager::OnNetworkChange() { |
| 212 // Remove all entries. Any entries that in-flight requests have a reference | 215 // Remove all entries. Any entries that in-flight requests have a reference |
| 213 // to will live until those requests end, and these entries may be | 216 // to will live until those requests end, and these entries may be |
| 214 // inconsistent with new entries for the same URLs, but since what we | 217 // inconsistent with new entries for the same URLs, but since what we |
| 215 // want is a clean slate for the new connection type, this is OK. | 218 // want is a clean slate for the new connection type, this is OK. |
| 216 url_entries_.clear(); | 219 url_entries_.clear(); |
| 217 requests_since_last_gc_ = 0; | 220 requests_since_last_gc_ = 0; |
| 218 } | 221 } |
| 219 | 222 |
| 220 } // namespace extensions | 223 } // namespace extensions |
| OLD | NEW |