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" |
11 #include "base/metrics/field_trial.h" | 11 #include "base/metrics/field_trial.h" |
12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "extensions/browser/extension_request_limiting_throttle.h" | 14 #include "extensions/browser/extension_request_limiting_throttle.h" |
15 #include "extensions/common/constants.h" | 15 #include "extensions/common/constants.h" |
16 #include "net/base/url_util.h" | 16 #include "net/base/url_util.h" |
17 #include "net/log/net_log.h" | 17 #include "net/log/net_log.h" |
| 18 #include "net/log/net_log_event_type.h" |
| 19 #include "net/log/net_log_source_type.h" |
18 #include "net/url_request/url_request.h" | 20 #include "net/url_request/url_request.h" |
19 | 21 |
20 namespace extensions { | 22 namespace extensions { |
21 | 23 |
22 const unsigned int ExtensionThrottleManager::kMaximumNumberOfEntries = 1500; | 24 const unsigned int ExtensionThrottleManager::kMaximumNumberOfEntries = 1500; |
23 const unsigned int ExtensionThrottleManager::kRequestsBetweenCollecting = 200; | 25 const unsigned int ExtensionThrottleManager::kRequestsBetweenCollecting = 200; |
24 | 26 |
25 ExtensionThrottleManager::ExtensionThrottleManager() | 27 ExtensionThrottleManager::ExtensionThrottleManager() |
26 : requests_since_last_gc_(0), | 28 : requests_since_last_gc_(0), |
27 enable_thread_checks_(false), | 29 enable_thread_checks_(false), |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 this, url_id, ignore_user_gesture_load_flag_for_tests_); | 99 this, url_id, ignore_user_gesture_load_flag_for_tests_); |
98 } | 100 } |
99 | 101 |
100 // We only disable back-off throttling on an entry that we have | 102 // We only disable back-off throttling on an entry that we have |
101 // just constructed. This is to allow unit tests to explicitly override | 103 // just constructed. This is to allow unit tests to explicitly override |
102 // the entry for localhost URLs. | 104 // the entry for localhost URLs. |
103 std::string host = url.host(); | 105 std::string host = url.host(); |
104 if (net::IsLocalhost(host)) { | 106 if (net::IsLocalhost(host)) { |
105 if (!logged_for_localhost_disabled_ && net::IsLocalhost(host)) { | 107 if (!logged_for_localhost_disabled_ && net::IsLocalhost(host)) { |
106 logged_for_localhost_disabled_ = true; | 108 logged_for_localhost_disabled_ = true; |
107 net_log_.AddEvent(net::NetLog::TYPE_THROTTLING_DISABLED_FOR_HOST, | 109 net_log_.AddEvent(net::NetLogEventType::THROTTLING_DISABLED_FOR_HOST, |
108 net::NetLog::StringCallback("host", &host)); | 110 net::NetLog::StringCallback("host", &host)); |
109 } | 111 } |
110 | 112 |
111 // TODO(joi): Once sliding window is separate from back-off throttling, | 113 // TODO(joi): Once sliding window is separate from back-off throttling, |
112 // we can simply return a dummy implementation of | 114 // we can simply return a dummy implementation of |
113 // ExtensionThrottleEntryInterface here that never blocks anything. | 115 // ExtensionThrottleEntryInterface here that never blocks anything. |
114 entry->DisableBackoffThrottling(); | 116 entry->DisableBackoffThrottling(); |
115 } | 117 } |
116 } | 118 } |
117 | 119 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 enable_thread_checks_ = enable; | 152 enable_thread_checks_ = enable; |
151 } | 153 } |
152 | 154 |
153 bool ExtensionThrottleManager::enable_thread_checks() const { | 155 bool ExtensionThrottleManager::enable_thread_checks() const { |
154 return enable_thread_checks_; | 156 return enable_thread_checks_; |
155 } | 157 } |
156 | 158 |
157 void ExtensionThrottleManager::set_net_log(net::NetLog* net_log) { | 159 void ExtensionThrottleManager::set_net_log(net::NetLog* net_log) { |
158 DCHECK(net_log); | 160 DCHECK(net_log); |
159 net_log_ = net::BoundNetLog::Make( | 161 net_log_ = net::BoundNetLog::Make( |
160 net_log, net::NetLog::SOURCE_EXPONENTIAL_BACKOFF_THROTTLING); | 162 net_log, net::NetLogSourceType::EXPONENTIAL_BACKOFF_THROTTLING); |
161 } | 163 } |
162 | 164 |
163 net::NetLog* ExtensionThrottleManager::net_log() const { | 165 net::NetLog* ExtensionThrottleManager::net_log() const { |
164 return net_log_.net_log(); | 166 return net_log_.net_log(); |
165 } | 167 } |
166 | 168 |
167 void ExtensionThrottleManager::OnIPAddressChanged() { | 169 void ExtensionThrottleManager::OnIPAddressChanged() { |
168 OnNetworkChange(); | 170 OnNetworkChange(); |
169 } | 171 } |
170 | 172 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 void ExtensionThrottleManager::OnNetworkChange() { | 211 void ExtensionThrottleManager::OnNetworkChange() { |
210 // Remove all entries. Any entries that in-flight requests have a reference | 212 // Remove all entries. Any entries that in-flight requests have a reference |
211 // to will live until those requests end, and these entries may be | 213 // to will live until those requests end, and these entries may be |
212 // inconsistent with new entries for the same URLs, but since what we | 214 // inconsistent with new entries for the same URLs, but since what we |
213 // want is a clean slate for the new connection type, this is OK. | 215 // want is a clean slate for the new connection type, this is OK. |
214 url_entries_.clear(); | 216 url_entries_.clear(); |
215 requests_since_last_gc_ = 0; | 217 requests_since_last_gc_ = 0; |
216 } | 218 } |
217 | 219 |
218 } // namespace extensions | 220 } // namespace extensions |
OLD | NEW |