| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_JOB_MANAGER_H_ | 5 #ifndef NET_URL_REQUEST_URL_REQUEST_JOB_MANAGER_H_ |
| 6 #define NET_URL_REQUEST_URL_REQUEST_JOB_MANAGER_H_ | 6 #define NET_URL_REQUEST_URL_REQUEST_JOB_MANAGER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 // Register a protocol factory associated with the given scheme. The factory | 58 // Register a protocol factory associated with the given scheme. The factory |
| 59 // parameter may be null to clear any existing association. Returns the | 59 // parameter may be null to clear any existing association. Returns the |
| 60 // previously registered protocol factory if any. | 60 // previously registered protocol factory if any. |
| 61 URLRequest::ProtocolFactory* RegisterProtocolFactory( | 61 URLRequest::ProtocolFactory* RegisterProtocolFactory( |
| 62 const std::string& scheme, URLRequest::ProtocolFactory* factory); | 62 const std::string& scheme, URLRequest::ProtocolFactory* factory); |
| 63 | 63 |
| 64 // Register/unregister a request interceptor. | 64 // Register/unregister a request interceptor. |
| 65 void RegisterRequestInterceptor(URLRequest::Interceptor* interceptor); | 65 void RegisterRequestInterceptor(URLRequest::Interceptor* interceptor); |
| 66 void UnregisterRequestInterceptor(URLRequest::Interceptor* interceptor); | 66 void UnregisterRequestInterceptor(URLRequest::Interceptor* interceptor); |
| 67 | 67 |
| 68 void set_enable_file_access(bool enable) { enable_file_access_ = enable; } | |
| 69 bool enable_file_access() const { return enable_file_access_; } | |
| 70 | |
| 71 private: | 68 private: |
| 72 typedef std::map<std::string, URLRequest::ProtocolFactory*> FactoryMap; | 69 typedef std::map<std::string, URLRequest::ProtocolFactory*> FactoryMap; |
| 73 typedef std::vector<URLRequest::Interceptor*> InterceptorList; | 70 typedef std::vector<URLRequest::Interceptor*> InterceptorList; |
| 74 friend struct DefaultSingletonTraits<URLRequestJobManager>; | 71 friend struct DefaultSingletonTraits<URLRequestJobManager>; |
| 75 | 72 |
| 76 URLRequestJobManager(); | 73 URLRequestJobManager(); |
| 77 ~URLRequestJobManager(); | 74 ~URLRequestJobManager(); |
| 78 | 75 |
| 79 // The first guy to call this function sets the allowed thread. This way we | 76 // The first guy to call this function sets the allowed thread. This way we |
| 80 // avoid needing to define that thread externally. Since we expect all | 77 // avoid needing to define that thread externally. Since we expect all |
| 81 // callers to be on the same thread, we don't worry about threads racing to | 78 // callers to be on the same thread, we don't worry about threads racing to |
| 82 // set the allowed thread. | 79 // set the allowed thread. |
| 83 bool IsAllowedThread() const { | 80 bool IsAllowedThread() const { |
| 84 #if 0 | 81 #if 0 |
| 85 if (!allowed_thread_initialized_) { | 82 if (!allowed_thread_initialized_) { |
| 86 allowed_thread_ = base::PlatformThread::CurrentId(); | 83 allowed_thread_ = base::PlatformThread::CurrentId(); |
| 87 allowed_thread_initialized_ = true; | 84 allowed_thread_initialized_ = true; |
| 88 } | 85 } |
| 89 return allowed_thread_ == base::PlatformThread::CurrentId(); | 86 return allowed_thread_ == base::PlatformThread::CurrentId(); |
| 90 #else | 87 #else |
| 91 // The previous version of this check used GetCurrentThread on Windows to | 88 // The previous version of this check used GetCurrentThread on Windows to |
| 92 // get thread handles to compare. Unfortunately, GetCurrentThread returns | 89 // get thread handles to compare. Unfortunately, GetCurrentThread returns |
| 93 // a constant psuedo-handle (0xFFFFFFFE), and therefore IsAllowedThread | 90 // a constant pseudo-handle (0xFFFFFFFE), and therefore IsAllowedThread |
| 94 // always returned true. The above code that's turned off is the correct | 91 // always returned true. The above code that's turned off is the correct |
| 95 // code, but causes the tree to turn red because some caller isn't | 92 // code, but causes the tree to turn red because some caller isn't |
| 96 // respecting our thread requirements. We're turning off the check for now; | 93 // respecting our thread requirements. We're turning off the check for now; |
| 97 // bug http://b/issue?id=1338969 has been filed to fix things and turn the | 94 // bug http://b/issue?id=1338969 has been filed to fix things and turn the |
| 98 // check back on. | 95 // check back on. |
| 99 return true; | 96 return true; |
| 100 } | 97 } |
| 101 | 98 |
| 102 // We use this to assert that CreateJob and the registration functions all | 99 // We use this to assert that CreateJob and the registration functions all |
| 103 // run on the same thread. | 100 // run on the same thread. |
| 104 mutable base::PlatformThreadId allowed_thread_; | 101 mutable base::PlatformThreadId allowed_thread_; |
| 105 mutable bool allowed_thread_initialized_; | 102 mutable bool allowed_thread_initialized_; |
| 106 #endif | 103 #endif |
| 107 | 104 |
| 108 mutable base::Lock lock_; | 105 mutable base::Lock lock_; |
| 109 FactoryMap factories_; | 106 FactoryMap factories_; |
| 110 InterceptorList interceptors_; | 107 InterceptorList interceptors_; |
| 111 bool enable_file_access_; | |
| 112 | 108 |
| 113 DISALLOW_COPY_AND_ASSIGN(URLRequestJobManager); | 109 DISALLOW_COPY_AND_ASSIGN(URLRequestJobManager); |
| 114 }; | 110 }; |
| 115 | 111 |
| 116 } // namespace net | 112 } // namespace net |
| 117 | 113 |
| 118 #endif // NET_URL_REQUEST_URL_REQUEST_JOB_MANAGER_H_ | 114 #endif // NET_URL_REQUEST_URL_REQUEST_JOB_MANAGER_H_ |
| OLD | NEW |