| 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 // TODO(joi): Remove once crbug.com/71721 is fixed. | 9 // TODO(joi): Remove once crbug.com/71721 is fixed. |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 char url[256]; | 26 char url[256]; |
| 27 | 27 |
| 28 // Not a refptr, we don't want to change behavior by keeping it alive. | 28 // Not a refptr, we don't want to change behavior by keeping it alive. |
| 29 net::URLRequestThrottlerEntryInterface* entry; | 29 net::URLRequestThrottlerEntryInterface* entry; |
| 30 }; | 30 }; |
| 31 | 31 |
| 32 } // namespace | 32 } // namespace |
| 33 | 33 |
| 34 namespace net { | 34 namespace net { |
| 35 | 35 |
| 36 ThreadCheckerForRelease::ThreadCheckerForRelease() | |
| 37 : valid_thread_id_(base::kInvalidThreadId) { | |
| 38 EnsureThreadIdAssigned(); | |
| 39 } | |
| 40 | |
| 41 ThreadCheckerForRelease::~ThreadCheckerForRelease() {} | |
| 42 | |
| 43 bool ThreadCheckerForRelease::CalledOnValidThread() const { | |
| 44 EnsureThreadIdAssigned(); | |
| 45 base::AutoLock auto_lock(lock_); | |
| 46 return valid_thread_id_ == base::PlatformThread::CurrentId(); | |
| 47 } | |
| 48 | |
| 49 void ThreadCheckerForRelease::DetachFromThread() { | |
| 50 base::AutoLock auto_lock(lock_); | |
| 51 valid_thread_id_ = base::kInvalidThreadId; | |
| 52 } | |
| 53 | |
| 54 void ThreadCheckerForRelease::EnsureThreadIdAssigned() const { | |
| 55 base::AutoLock auto_lock(lock_); | |
| 56 if (valid_thread_id_ != base::kInvalidThreadId) | |
| 57 return; | |
| 58 valid_thread_id_ = base::PlatformThread::CurrentId(); | |
| 59 } | |
| 60 | |
| 61 const unsigned int URLRequestThrottlerManager::kMaximumNumberOfEntries = 1500; | 36 const unsigned int URLRequestThrottlerManager::kMaximumNumberOfEntries = 1500; |
| 62 const unsigned int URLRequestThrottlerManager::kRequestsBetweenCollecting = 200; | 37 const unsigned int URLRequestThrottlerManager::kRequestsBetweenCollecting = 200; |
| 63 | 38 |
| 64 URLRequestThrottlerManager* URLRequestThrottlerManager::GetInstance() { | 39 URLRequestThrottlerManager* URLRequestThrottlerManager::GetInstance() { |
| 65 return Singleton<URLRequestThrottlerManager>::get(); | 40 return Singleton<URLRequestThrottlerManager>::get(); |
| 66 } | 41 } |
| 67 | 42 |
| 68 scoped_refptr<URLRequestThrottlerEntryInterface> | 43 scoped_refptr<URLRequestThrottlerEntryInterface> |
| 69 URLRequestThrottlerManager::RegisterRequestUrl(const GURL &url) { | 44 URLRequestThrottlerManager::RegisterRequestUrl(const GURL &url) { |
| 70 CHECK(being_tested_ || thread_checker_.CalledOnValidThread()); | 45 CHECK(being_tested_ || thread_checker_.CalledOnValidThread()); |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 | 183 |
| 209 CHECK(nulls_found == 0); | 184 CHECK(nulls_found == 0); |
| 210 | 185 |
| 211 // In case something broke we want to make sure not to grow indefinitely. | 186 // In case something broke we want to make sure not to grow indefinitely. |
| 212 while (url_entries_.size() > kMaximumNumberOfEntries) { | 187 while (url_entries_.size() > kMaximumNumberOfEntries) { |
| 213 url_entries_.erase(url_entries_.begin()); | 188 url_entries_.erase(url_entries_.begin()); |
| 214 } | 189 } |
| 215 } | 190 } |
| 216 | 191 |
| 217 } // namespace net | 192 } // namespace net |
| OLD | NEW |