| 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 "net/url_request/url_request_throttler_manager.h" | 5 #include "net/url_request/url_request_throttler_manager.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 // We only disable back-off throttling on an entry that we have | 76 // We only disable back-off throttling on an entry that we have |
| 77 // just constructed. This is to allow unit tests to explicitly override | 77 // just constructed. This is to allow unit tests to explicitly override |
| 78 // the entry for localhost URLs. Given that we do not attempt to | 78 // the entry for localhost URLs. Given that we do not attempt to |
| 79 // disable throttling for entries already handed out (see comment | 79 // disable throttling for entries already handed out (see comment |
| 80 // in AddToOptOutList), this is not a problem. | 80 // in AddToOptOutList), this is not a problem. |
| 81 std::string host = url.host(); | 81 std::string host = url.host(); |
| 82 if (opt_out_hosts_.find(host) != opt_out_hosts_.end() || | 82 if (opt_out_hosts_.find(host) != opt_out_hosts_.end() || |
| 83 IsLocalhost(host)) { | 83 IsLocalhost(host)) { |
| 84 if (!logged_for_localhost_disabled_ && IsLocalhost(host)) { | 84 if (!logged_for_localhost_disabled_ && IsLocalhost(host)) { |
| 85 logged_for_localhost_disabled_ = true; | 85 logged_for_localhost_disabled_ = true; |
| 86 net_log_.AddEvent( | 86 net_log_.AddEvent(NetLog::TYPE_THROTTLING_DISABLED_FOR_HOST, |
| 87 NetLog::TYPE_THROTTLING_DISABLED_FOR_HOST, | 87 NetLog::StringCallback("host", &host)); |
| 88 make_scoped_refptr(new NetLogStringParameter("host", host))); | |
| 89 } | 88 } |
| 90 | 89 |
| 91 // TODO(joi): Once sliding window is separate from back-off throttling, | 90 // TODO(joi): Once sliding window is separate from back-off throttling, |
| 92 // we can simply return a dummy implementation of | 91 // we can simply return a dummy implementation of |
| 93 // URLRequestThrottlerEntryInterface here that never blocks anything (and | 92 // URLRequestThrottlerEntryInterface here that never blocks anything (and |
| 94 // not keep entries in url_entries_ for opted-out sites). | 93 // not keep entries in url_entries_ for opted-out sites). |
| 95 entry->DisableBackoffThrottling(); | 94 entry->DisableBackoffThrottling(); |
| 96 } | 95 } |
| 97 } | 96 } |
| 98 | 97 |
| 99 return entry; | 98 return entry; |
| 100 } | 99 } |
| 101 | 100 |
| 102 void URLRequestThrottlerManager::AddToOptOutList(const std::string& host) { | 101 void URLRequestThrottlerManager::AddToOptOutList(const std::string& host) { |
| 103 // There is an edge case here that we are not handling, to keep things | 102 // There is an edge case here that we are not handling, to keep things |
| 104 // simple. If a host starts adding the opt-out header to its responses | 103 // simple. If a host starts adding the opt-out header to its responses |
| 105 // after there are already one or more entries in url_entries_ for that | 104 // after there are already one or more entries in url_entries_ for that |
| 106 // host, the pre-existing entries may still perform back-off throttling. | 105 // host, the pre-existing entries may still perform back-off throttling. |
| 107 // In practice, this would almost never occur. | 106 // In practice, this would almost never occur. |
| 108 if (opt_out_hosts_.find(host) == opt_out_hosts_.end()) { | 107 if (opt_out_hosts_.find(host) == opt_out_hosts_.end()) { |
| 109 UMA_HISTOGRAM_COUNTS("Throttling.SiteOptedOut", 1); | 108 UMA_HISTOGRAM_COUNTS("Throttling.SiteOptedOut", 1); |
| 110 | 109 |
| 111 net_log_.EndEvent( | 110 net_log_.EndEvent(NetLog::TYPE_THROTTLING_DISABLED_FOR_HOST, |
| 112 NetLog::TYPE_THROTTLING_DISABLED_FOR_HOST, | 111 NetLog::StringCallback("host", &host)); |
| 113 make_scoped_refptr(new NetLogStringParameter("host", host))); | |
| 114 opt_out_hosts_.insert(host); | 112 opt_out_hosts_.insert(host); |
| 115 } | 113 } |
| 116 } | 114 } |
| 117 | 115 |
| 118 void URLRequestThrottlerManager::OverrideEntryForTests( | 116 void URLRequestThrottlerManager::OverrideEntryForTests( |
| 119 const GURL& url, | 117 const GURL& url, |
| 120 URLRequestThrottlerEntry* entry) { | 118 URLRequestThrottlerEntry* entry) { |
| 121 // Normalize the url. | 119 // Normalize the url. |
| 122 std::string url_id = GetIdFromUrl(url); | 120 std::string url_id = GetIdFromUrl(url); |
| 123 | 121 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 void URLRequestThrottlerManager::OnNetworkChange() { | 194 void URLRequestThrottlerManager::OnNetworkChange() { |
| 197 // Remove all entries. Any entries that in-flight requests have a reference | 195 // Remove all entries. Any entries that in-flight requests have a reference |
| 198 // to will live until those requests end, and these entries may be | 196 // to will live until those requests end, and these entries may be |
| 199 // inconsistent with new entries for the same URLs, but since what we | 197 // inconsistent with new entries for the same URLs, but since what we |
| 200 // want is a clean slate for the new connection type, this is OK. | 198 // want is a clean slate for the new connection type, this is OK. |
| 201 url_entries_.clear(); | 199 url_entries_.clear(); |
| 202 requests_since_last_gc_ = 0; | 200 requests_since_last_gc_ = 0; |
| 203 } | 201 } |
| 204 | 202 |
| 205 } // namespace net | 203 } // namespace net |
| OLD | NEW |