| 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 048cc32cd228588b358ac397de60577718bc92e4..c2fa4300b6cb2de9c1d6ec2c4947aaeac0b476d8 100644
|
| --- a/net/url_request/url_request_throttler_manager.cc
|
| +++ b/net/url_request/url_request_throttler_manager.cc
|
| @@ -16,24 +16,45 @@ namespace net {
|
| const unsigned int URLRequestThrottlerManager::kMaximumNumberOfEntries = 1500;
|
| const unsigned int URLRequestThrottlerManager::kRequestsBetweenCollecting = 200;
|
|
|
| -URLRequestThrottlerManager* URLRequestThrottlerManager::GetInstance() {
|
| - return Singleton<URLRequestThrottlerManager>::get();
|
| +URLRequestThrottlerManager::URLRequestThrottlerManager()
|
| + : requests_since_last_gc_(0),
|
| + enforce_throttling_(true),
|
| + enable_thread_checks_(false),
|
| + logged_for_localhost_disabled_(false),
|
| + registered_from_thread_(base::kInvalidThreadId) {
|
| + url_id_replacements_.ClearPassword();
|
| + url_id_replacements_.ClearUsername();
|
| + url_id_replacements_.ClearQuery();
|
| + url_id_replacements_.ClearRef();
|
| +
|
| + NetworkChangeNotifier::AddIPAddressObserver(this);
|
| + NetworkChangeNotifier::AddOnlineStateObserver(this);
|
| +}
|
| +
|
| +URLRequestThrottlerManager::~URLRequestThrottlerManager() {
|
| + NetworkChangeNotifier::RemoveIPAddressObserver(this);
|
| + NetworkChangeNotifier::RemoveOnlineStateObserver(this);
|
| +
|
| + // 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();
|
| }
|
|
|
| scoped_refptr<URLRequestThrottlerEntryInterface>
|
| URLRequestThrottlerManager::RegisterRequestUrl(const GURL &url) {
|
| DCHECK(!enable_thread_checks_ || CalledOnValidThread());
|
|
|
| - if (registered_from_thread_ == base::kInvalidThreadId) {
|
| - // We can't currently do this in the constructor as it is run on the
|
| - // UI thread and notifications go to the thread from which they are
|
| - // registered.
|
| - // TODO(joi): Clean this up once this is no longer a Singleton.
|
| - NetworkChangeNotifier::AddIPAddressObserver(this);
|
| - NetworkChangeNotifier::AddOnlineStateObserver(this);
|
| - registered_from_thread_ = base::PlatformThread::CurrentId();
|
| - }
|
| -
|
| // Normalize the url.
|
| std::string url_id = GetIdFromUrl(url);
|
|
|
| @@ -149,53 +170,6 @@ void URLRequestThrottlerManager::OnOnlineStateChanged(bool online) {
|
| OnNetworkChange();
|
| }
|
|
|
| -URLRequestThrottlerManager::URLRequestThrottlerManager()
|
| - : requests_since_last_gc_(0),
|
| - enforce_throttling_(true),
|
| - enable_thread_checks_(false),
|
| - logged_for_localhost_disabled_(false),
|
| - registered_from_thread_(base::kInvalidThreadId) {
|
| - // Construction/destruction is on main thread (because BrowserMain
|
| - // retrieves an instance to call InitializeOptions), but is from then on
|
| - // used on I/O thread.
|
| - DetachFromThread();
|
| -
|
| - url_id_replacements_.ClearPassword();
|
| - url_id_replacements_.ClearUsername();
|
| - url_id_replacements_.ClearQuery();
|
| - url_id_replacements_.ClearRef();
|
| -}
|
| -
|
| -URLRequestThrottlerManager::~URLRequestThrottlerManager() {
|
| - // Destruction is on main thread (AtExit), but real use is on I/O thread.
|
| - // The AtExit manager does not run until the I/O thread has finished
|
| - // processing.
|
| - DetachFromThread();
|
| -
|
| - // We must currently skip this in the production case, where the destructor
|
| - // does not run on the thread we registered from.
|
| - // TODO(joi): Fix once we are no longer a Singleton.
|
| - if (base::PlatformThread::CurrentId() == registered_from_thread_) {
|
| - NetworkChangeNotifier::RemoveIPAddressObserver(this);
|
| - NetworkChangeNotifier::RemoveOnlineStateObserver(this);
|
| - }
|
| -
|
| - // 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();
|
| -}
|
| -
|
| std::string URLRequestThrottlerManager::GetIdFromUrl(const GURL& url) const {
|
| if (!url.is_valid())
|
| return url.possibly_invalid_spec();
|
|
|