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 "net/url_request/url_request.h" | 15 #include "net/url_request/url_request.h" |
16 | 16 |
17 // This class is responsible for managing the set of protocol factories and | 17 // This class is responsible for managing the set of protocol factories and |
18 // request interceptors that determine how an URLRequestJob gets created to | 18 // request interceptors that determine how an URLRequestJob gets created to |
19 // handle an URLRequest. | 19 // handle an net::URLRequest. |
20 // | 20 // |
21 // MULTI-THREADING NOTICE: | 21 // MULTI-THREADING NOTICE: |
22 // URLRequest is designed to have all consumers on a single thread, and so no | 22 // net::URLRequest is designed to have all consumers on a single thread, and |
23 // attempt is made to support ProtocolFactory or Interceptor instances being | 23 // so no attempt is made to support ProtocolFactory or Interceptor instances |
24 // registered/unregistered or in any way poked on multiple threads. However, | 24 // being registered/unregistered or in any way poked on multiple threads. |
25 // we do support checking for supported schemes FROM ANY THREAD (i.e., it is | 25 // However, we do support checking for supported schemes FROM ANY THREAD |
26 // safe to call SupportsScheme on any thread). | 26 // (i.e., it is safe to call SupportsScheme on any thread). |
27 // | 27 // |
28 class URLRequestJobManager { | 28 class URLRequestJobManager { |
29 public: | 29 public: |
30 URLRequestJobManager(); | 30 URLRequestJobManager(); |
31 ~URLRequestJobManager(); | 31 ~URLRequestJobManager(); |
32 | 32 |
33 // Instantiate an URLRequestJob implementation based on the registered | 33 // Instantiate an URLRequestJob implementation based on the registered |
34 // interceptors and protocol factories. This will always succeed in | 34 // interceptors and protocol factories. This will always succeed in |
35 // returning a job unless we are--in the extreme case--out of memory. | 35 // returning a job unless we are--in the extreme case--out of memory. |
36 net::URLRequestJob* CreateJob(net::URLRequest* request) const; | 36 net::URLRequestJob* CreateJob(net::URLRequest* request) const; |
(...skipping 10 matching lines...) Loading... |
47 net::URLRequestJob* MaybeInterceptResponse(net::URLRequest* request) const; | 47 net::URLRequestJob* MaybeInterceptResponse(net::URLRequest* request) const; |
48 | 48 |
49 // Returns true if there is a protocol factory registered for the given | 49 // Returns true if there is a protocol factory registered for the given |
50 // scheme. Note: also returns true if there is a built-in handler for the | 50 // scheme. Note: also returns true if there is a built-in handler for the |
51 // given scheme. | 51 // given scheme. |
52 bool SupportsScheme(const std::string& scheme) const; | 52 bool SupportsScheme(const std::string& scheme) const; |
53 | 53 |
54 // Register a protocol factory associated with the given scheme. The factory | 54 // Register a protocol factory associated with the given scheme. The factory |
55 // parameter may be null to clear any existing association. Returns the | 55 // parameter may be null to clear any existing association. Returns the |
56 // previously registered protocol factory if any. | 56 // previously registered protocol factory if any. |
57 URLRequest::ProtocolFactory* RegisterProtocolFactory( | 57 net::URLRequest::ProtocolFactory* RegisterProtocolFactory( |
58 const std::string& scheme, URLRequest::ProtocolFactory* factory); | 58 const std::string& scheme, net::URLRequest::ProtocolFactory* factory); |
59 | 59 |
60 // Register/unregister a request interceptor. | 60 // Register/unregister a request interceptor. |
61 void RegisterRequestInterceptor(URLRequest::Interceptor* interceptor); | 61 void RegisterRequestInterceptor(net::URLRequest::Interceptor* interceptor); |
62 void UnregisterRequestInterceptor(URLRequest::Interceptor* interceptor); | 62 void UnregisterRequestInterceptor(net::URLRequest::Interceptor* interceptor); |
63 | 63 |
64 void set_enable_file_access(bool enable) { enable_file_access_ = enable; } | 64 void set_enable_file_access(bool enable) { enable_file_access_ = enable; } |
65 bool enable_file_access() const { return enable_file_access_; } | 65 bool enable_file_access() const { return enable_file_access_; } |
66 | 66 |
67 private: | 67 private: |
68 typedef std::map<std::string, URLRequest::ProtocolFactory*> FactoryMap; | 68 typedef std::map<std::string, net::URLRequest::ProtocolFactory*> FactoryMap; |
69 typedef std::vector<URLRequest::Interceptor*> InterceptorList; | 69 typedef std::vector<net::URLRequest::Interceptor*> InterceptorList; |
70 | 70 |
71 mutable Lock lock_; | 71 mutable Lock lock_; |
72 FactoryMap factories_; | 72 FactoryMap factories_; |
73 InterceptorList interceptors_; | 73 InterceptorList interceptors_; |
74 bool enable_file_access_; | 74 bool enable_file_access_; |
75 | 75 |
76 #ifndef NDEBUG | 76 #ifndef NDEBUG |
77 // We use this to assert that CreateJob and the registration functions all | 77 // We use this to assert that CreateJob and the registration functions all |
78 // run on the same thread. | 78 // run on the same thread. |
79 mutable PlatformThreadId allowed_thread_; | 79 mutable PlatformThreadId allowed_thread_; |
(...skipping 21 matching lines...) Loading... |
101 // check back on. | 101 // check back on. |
102 return true; | 102 return true; |
103 #endif | 103 #endif |
104 } | 104 } |
105 #endif | 105 #endif |
106 | 106 |
107 DISALLOW_COPY_AND_ASSIGN(URLRequestJobManager); | 107 DISALLOW_COPY_AND_ASSIGN(URLRequestJobManager); |
108 }; | 108 }; |
109 | 109 |
110 #endif // NET_URL_REQUEST_URL_REQUEST_JOB_MANAGER_H__ | 110 #endif // NET_URL_REQUEST_URL_REQUEST_JOB_MANAGER_H__ |
OLD | NEW |