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_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> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/lock.h" | 13 #include "base/lock.h" |
14 #include "base/platform_thread.h" | 14 #include "base/platform_thread.h" |
| 15 #include "base/singleton.h" |
15 #include "net/url_request/url_request.h" | 16 #include "net/url_request/url_request.h" |
16 | 17 |
17 // This class is responsible for managing the set of protocol factories and | 18 // This class is responsible for managing the set of protocol factories and |
18 // request interceptors that determine how an URLRequestJob gets created to | 19 // request interceptors that determine how an URLRequestJob gets created to |
19 // handle an net::URLRequest. | 20 // handle an net::URLRequest. |
20 // | 21 // |
21 // MULTI-THREADING NOTICE: | 22 // MULTI-THREADING NOTICE: |
22 // net::URLRequest is designed to have all consumers on a single thread, and | 23 // net::URLRequest is designed to have all consumers on a single thread, and |
23 // so no attempt is made to support ProtocolFactory or Interceptor instances | 24 // so no attempt is made to support ProtocolFactory or Interceptor instances |
24 // being registered/unregistered or in any way poked on multiple threads. | 25 // being registered/unregistered or in any way poked on multiple threads. |
25 // However, we do support checking for supported schemes FROM ANY THREAD | 26 // However, we do support checking for supported schemes FROM ANY THREAD |
26 // (i.e., it is safe to call SupportsScheme on any thread). | 27 // (i.e., it is safe to call SupportsScheme on any thread). |
27 // | 28 // |
28 class URLRequestJobManager { | 29 class URLRequestJobManager { |
29 public: | 30 public: |
30 URLRequestJobManager(); | 31 // Returns the singleton instance. |
31 ~URLRequestJobManager(); | 32 static URLRequestJobManager* GetInstance(); |
32 | 33 |
33 // Instantiate an URLRequestJob implementation based on the registered | 34 // Instantiate an URLRequestJob implementation based on the registered |
34 // interceptors and protocol factories. This will always succeed in | 35 // interceptors and protocol factories. This will always succeed in |
35 // returning a job unless we are--in the extreme case--out of memory. | 36 // returning a job unless we are--in the extreme case--out of memory. |
36 net::URLRequestJob* CreateJob(net::URLRequest* request) const; | 37 net::URLRequestJob* CreateJob(net::URLRequest* request) const; |
37 | 38 |
38 // Allows interceptors to hijack the request after examining the new location | 39 // Allows interceptors to hijack the request after examining the new location |
39 // of a redirect. Returns NULL if no interceptor intervenes. | 40 // of a redirect. Returns NULL if no interceptor intervenes. |
40 net::URLRequestJob* MaybeInterceptRedirect(net::URLRequest* request, | 41 net::URLRequestJob* MaybeInterceptRedirect(net::URLRequest* request, |
41 const GURL& location) const; | 42 const GURL& location) const; |
(...skipping 18 matching lines...) Expand all Loading... |
60 // Register/unregister a request interceptor. | 61 // Register/unregister a request interceptor. |
61 void RegisterRequestInterceptor(net::URLRequest::Interceptor* interceptor); | 62 void RegisterRequestInterceptor(net::URLRequest::Interceptor* interceptor); |
62 void UnregisterRequestInterceptor(net::URLRequest::Interceptor* interceptor); | 63 void UnregisterRequestInterceptor(net::URLRequest::Interceptor* interceptor); |
63 | 64 |
64 void set_enable_file_access(bool enable) { enable_file_access_ = enable; } | 65 void set_enable_file_access(bool enable) { enable_file_access_ = enable; } |
65 bool enable_file_access() const { return enable_file_access_; } | 66 bool enable_file_access() const { return enable_file_access_; } |
66 | 67 |
67 private: | 68 private: |
68 typedef std::map<std::string, net::URLRequest::ProtocolFactory*> FactoryMap; | 69 typedef std::map<std::string, net::URLRequest::ProtocolFactory*> FactoryMap; |
69 typedef std::vector<net::URLRequest::Interceptor*> InterceptorList; | 70 typedef std::vector<net::URLRequest::Interceptor*> InterceptorList; |
| 71 friend struct DefaultSingletonTraits<URLRequestJobManager>; |
| 72 |
| 73 URLRequestJobManager(); |
| 74 ~URLRequestJobManager(); |
70 | 75 |
71 mutable Lock lock_; | 76 mutable Lock lock_; |
72 FactoryMap factories_; | 77 FactoryMap factories_; |
73 InterceptorList interceptors_; | 78 InterceptorList interceptors_; |
74 bool enable_file_access_; | 79 bool enable_file_access_; |
75 | 80 |
76 #ifndef NDEBUG | 81 #ifndef NDEBUG |
77 // We use this to assert that CreateJob and the registration functions all | 82 // We use this to assert that CreateJob and the registration functions all |
78 // run on the same thread. | 83 // run on the same thread. |
79 mutable PlatformThreadId allowed_thread_; | 84 mutable PlatformThreadId allowed_thread_; |
(...skipping 21 matching lines...) Expand all Loading... |
101 // check back on. | 106 // check back on. |
102 return true; | 107 return true; |
103 #endif | 108 #endif |
104 } | 109 } |
105 #endif | 110 #endif |
106 | 111 |
107 DISALLOW_COPY_AND_ASSIGN(URLRequestJobManager); | 112 DISALLOW_COPY_AND_ASSIGN(URLRequestJobManager); |
108 }; | 113 }; |
109 | 114 |
110 #endif // NET_URL_REQUEST_URL_REQUEST_JOB_MANAGER_H__ | 115 #endif // NET_URL_REQUEST_URL_REQUEST_JOB_MANAGER_H__ |
OLD | NEW |