| 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 #ifndef NET_URL_REQUEST_URL_REQUEST_THROTTLER_MANAGER_H_ | 5 #ifndef NET_URL_REQUEST_URL_REQUEST_THROTTLER_MANAGER_H_ |
| 6 #define NET_URL_REQUEST_URL_REQUEST_THROTTLER_MANAGER_H_ | 6 #define NET_URL_REQUEST_URL_REQUEST_THROTTLER_MANAGER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
| 13 #include "base/singleton.h" | 13 #include "base/singleton.h" |
| 14 #include "base/synchronization/lock.h" // ThreadCheckerForRelease | 14 #include "base/threading/thread_checker_impl.h" |
| 15 #include "base/threading/platform_thread.h" // ThreadCheckerForRelease | |
| 16 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
| 17 #include "net/url_request/url_request_throttler_entry.h" | 16 #include "net/url_request/url_request_throttler_entry.h" |
| 18 | 17 |
| 19 namespace net { | 18 namespace net { |
| 20 | 19 |
| 21 // TODO(joi): Delete this temporary copy of base::ThreadChecker (needed to | |
| 22 // enable it in release builds) and go back to simply inheriting from | |
| 23 // NonThreadSafe once crbug.com/71721 has been tracked down. | |
| 24 class ThreadCheckerForRelease { | |
| 25 public: | |
| 26 ThreadCheckerForRelease(); | |
| 27 ~ThreadCheckerForRelease(); | |
| 28 | |
| 29 bool CalledOnValidThread() const; | |
| 30 | |
| 31 // Changes the thread that is checked for in CalledOnValidThread. This may | |
| 32 // be useful when an object may be created on one thread and then used | |
| 33 // exclusively on another thread. | |
| 34 void DetachFromThread(); | |
| 35 | |
| 36 private: | |
| 37 void EnsureThreadIdAssigned() const; | |
| 38 | |
| 39 mutable base::Lock lock_; | |
| 40 // This is mutable so that CalledOnValidThread can set it. | |
| 41 // It's guarded by |lock_|. | |
| 42 mutable base::PlatformThreadId valid_thread_id_; | |
| 43 }; | |
| 44 | |
| 45 // Class that registers URL request throttler entries for URLs being accessed | 20 // Class that registers URL request throttler entries for URLs being accessed |
| 46 // in order to supervise traffic. URL requests for HTTP contents should | 21 // in order to supervise traffic. URL requests for HTTP contents should |
| 47 // register their URLs in this manager on each request. | 22 // register their URLs in this manager on each request. |
| 48 // | 23 // |
| 49 // URLRequestThrottlerManager maintains a map of URL IDs to URL request | 24 // URLRequestThrottlerManager maintains a map of URL IDs to URL request |
| 50 // throttler entries. It creates URL request throttler entries when new URLs | 25 // throttler entries. It creates URL request throttler entries when new URLs |
| 51 // are registered, and does garbage collection from time to time in order to | 26 // are registered, and does garbage collection from time to time in order to |
| 52 // clean out outdated entries. URL ID consists of lowercased scheme, host, port | 27 // clean out outdated entries. URL ID consists of lowercased scheme, host, port |
| 53 // and path. All URLs converted to the same ID will share the same entry. | 28 // and path. All URLs converted to the same ID will share the same entry. |
| 54 // | 29 // |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 bool enforce_throttling_; | 119 bool enforce_throttling_; |
| 145 | 120 |
| 146 // Certain tests do not obey the net component's threading policy, so we | 121 // Certain tests do not obey the net component's threading policy, so we |
| 147 // keep track of whether we're being used by tests, and turn off certain | 122 // keep track of whether we're being used by tests, and turn off certain |
| 148 // checks. | 123 // checks. |
| 149 // | 124 // |
| 150 // TODO(joi): See if we can fix the offending unit tests and remove this | 125 // TODO(joi): See if we can fix the offending unit tests and remove this |
| 151 // workaround. | 126 // workaround. |
| 152 bool being_tested_; | 127 bool being_tested_; |
| 153 | 128 |
| 154 ThreadCheckerForRelease thread_checker_; | 129 base::ThreadCheckerImpl thread_checker_; |
| 155 | 130 |
| 156 DISALLOW_COPY_AND_ASSIGN(URLRequestThrottlerManager); | 131 DISALLOW_COPY_AND_ASSIGN(URLRequestThrottlerManager); |
| 157 }; | 132 }; |
| 158 | 133 |
| 159 } // namespace net | 134 } // namespace net |
| 160 | 135 |
| 161 #endif // NET_URL_REQUEST_URL_REQUEST_THROTTLER_MANAGER_H_ | 136 #endif // NET_URL_REQUEST_URL_REQUEST_THROTTLER_MANAGER_H_ |
| OLD | NEW |