| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <list> | 7 #include <list> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 | 11 |
| 12 namespace net { | 12 namespace net { |
| 13 | 13 |
| 14 ThreadCheckerForRelease::ThreadCheckerForRelease() | |
| 15 : valid_thread_id_(base::kInvalidThreadId) { | |
| 16 EnsureThreadIdAssigned(); | |
| 17 } | |
| 18 | |
| 19 ThreadCheckerForRelease::~ThreadCheckerForRelease() {} | |
| 20 | |
| 21 bool ThreadCheckerForRelease::CalledOnValidThread() const { | |
| 22 EnsureThreadIdAssigned(); | |
| 23 base::AutoLock auto_lock(lock_); | |
| 24 return valid_thread_id_ == base::PlatformThread::CurrentId(); | |
| 25 } | |
| 26 | |
| 27 void ThreadCheckerForRelease::DetachFromThread() { | |
| 28 base::AutoLock auto_lock(lock_); | |
| 29 valid_thread_id_ = base::kInvalidThreadId; | |
| 30 } | |
| 31 | |
| 32 void ThreadCheckerForRelease::EnsureThreadIdAssigned() const { | |
| 33 base::AutoLock auto_lock(lock_); | |
| 34 if (valid_thread_id_ != base::kInvalidThreadId) | |
| 35 return; | |
| 36 valid_thread_id_ = base::PlatformThread::CurrentId(); | |
| 37 } | |
| 38 | |
| 39 const unsigned int URLRequestThrottlerManager::kMaximumNumberOfEntries = 1500; | 14 const unsigned int URLRequestThrottlerManager::kMaximumNumberOfEntries = 1500; |
| 40 const unsigned int URLRequestThrottlerManager::kRequestsBetweenCollecting = 200; | 15 const unsigned int URLRequestThrottlerManager::kRequestsBetweenCollecting = 200; |
| 41 | 16 |
| 42 URLRequestThrottlerManager* URLRequestThrottlerManager::GetInstance() { | 17 URLRequestThrottlerManager* URLRequestThrottlerManager::GetInstance() { |
| 43 return Singleton<URLRequestThrottlerManager>::get(); | 18 return Singleton<URLRequestThrottlerManager>::get(); |
| 44 } | 19 } |
| 45 | 20 |
| 46 scoped_refptr<URLRequestThrottlerEntryInterface> | 21 scoped_refptr<URLRequestThrottlerEntryInterface> |
| 47 URLRequestThrottlerManager::RegisterRequestUrl(const GURL &url) { | 22 URLRequestThrottlerManager::RegisterRequestUrl(const GURL &url) { |
| 48 CHECK(being_tested_ || thread_checker_.CalledOnValidThread()); | 23 CHECK(being_tested_ || thread_checker_.CalledOnValidThread()); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 } | 117 } |
| 143 } | 118 } |
| 144 | 119 |
| 145 // In case something broke we want to make sure not to grow indefinitely. | 120 // In case something broke we want to make sure not to grow indefinitely. |
| 146 while (url_entries_.size() > kMaximumNumberOfEntries) { | 121 while (url_entries_.size() > kMaximumNumberOfEntries) { |
| 147 url_entries_.erase(url_entries_.begin()); | 122 url_entries_.erase(url_entries_.begin()); |
| 148 } | 123 } |
| 149 } | 124 } |
| 150 | 125 |
| 151 } // namespace net | 126 } // namespace net |
| OLD | NEW |