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

Unified Diff: net/url_request/url_request_throttler_manager.cc

Issue 10203002: Make URLRequestThrottlerManager a member of URLRequestContext. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Respond to review comments. Created 8 years, 8 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
« no previous file with comments | « net/url_request/url_request_throttler_manager.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
« no previous file with comments | « net/url_request/url_request_throttler_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698