Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Unified Diff: net/url_request/url_request_throttler_manager.cc

Issue 6711046: Add an opt-out header for HTTP throttling. Never throttle for localhost. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to head. Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/url_request/url_request_throttler_manager.cc
diff --git a/net/url_request/url_request_throttler_manager.cc b/net/url_request/url_request_throttler_manager.cc
index de8b8178e9615c18c8f34f643b44af0860860171..3a217402867f87e83eacef488330fa74a2200ebd 100644
--- a/net/url_request/url_request_throttler_manager.cc
+++ b/net/url_request/url_request_throttler_manager.cc
@@ -6,6 +6,7 @@
#include "base/logging.h"
#include "base/string_util.h"
+#include "net/base/net_util.h"
namespace net {
@@ -28,12 +29,37 @@ scoped_refptr<URLRequestThrottlerEntryInterface>
// Find the entry in the map or create it.
scoped_refptr<URLRequestThrottlerEntry>& entry = url_entries_[url_id];
- if (entry.get() == NULL)
- entry = new URLRequestThrottlerEntry();
+ if (entry.get() == NULL) {
+ entry = new URLRequestThrottlerEntry(this);
+
+ // We only disable back-off throttling on an entry that we have
+ // just constructed. This is to allow unit tests to explicitly override
+ // the entry for localhost URLs. Given that we do not attempt to
+ // disable throttling for entries already handed out (see comment
+ // in AddToOptOutList), this is not a problem.
+ std::string host = url.host();
+ if (opt_out_hosts_.find(host) != opt_out_hosts_.end() ||
+ IsLocalhost(host)) {
+ // TODO(joi): Once sliding window is separate from back-off throttling,
+ // we can simply return a dummy implementation of
+ // URLRequestThrottlerEntryInterface here that never blocks anything (and
+ // not keep entries in url_entries_ for opted-out sites).
+ entry->DisableBackoffThrottling();
+ }
+ }
return entry;
}
+void URLRequestThrottlerManager::AddToOptOutList(const std::string& host) {
+ // There is an edge case here that we are not handling, to keep things
+ // simple. If a host starts adding the opt-out header to its responses
+ // after there are already one or more entries in url_entries_ for that
+ // host, the pre-existing entries may still perform back-off throttling.
+ // In practice, this would almost never occur.
+ opt_out_hosts_.insert(host);
+}
+
void URLRequestThrottlerManager::OverrideEntryForTests(
const GURL& url,
URLRequestThrottlerEntry* entry) {
@@ -88,6 +114,18 @@ URLRequestThrottlerManager::~URLRequestThrottlerManager() {
// Destruction is on main thread (AtExit), but real use is on I/O thread.
DetachFromThread();
+ // Since, for now, the manager object might conceivably go away before
+ // the entries, detach the entries' back-pointer to the manager.
+ //
+ // TODO(joi): Revisit whether to make entries non-refcounted.
+ UrlEntryMap::iterator i = url_entries_.begin();
+ while (i != url_entries_.end()) {
+ if (i->second != NULL) {
+ i->second->DetachManager();
+ }
+ ++i;
+ }
+
// Delete all entries.
url_entries_.clear();
}

Powered by Google App Engine
This is Rietveld 408576698