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_PROXY_PROXY_SERVICE_H_ | 5 #ifndef NET_PROXY_PROXY_SERVICE_H_ |
6 #define NET_PROXY_PROXY_SERVICE_H_ | 6 #define NET_PROXY_PROXY_SERVICE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/synchronization/waitable_event.h" | 14 #include "base/synchronization/waitable_event.h" |
15 #include "base/threading/non_thread_safe.h" | 15 #include "base/threading/non_thread_safe.h" |
16 #include "net/base/completion_callback.h" | 16 #include "net/base/completion_callback.h" |
17 #include "net/base/net_log.h" | 17 #include "net/base/net_log.h" |
18 #include "net/base/network_change_notifier.h" | 18 #include "net/base/network_change_notifier.h" |
19 #include "net/proxy/proxy_config_service.h" | 19 #include "net/proxy/proxy_config_service.h" |
20 #include "net/proxy/proxy_info.h" | 20 #include "net/proxy/proxy_info.h" |
21 #include "net/proxy/proxy_server.h" | 21 #include "net/proxy/proxy_server.h" |
22 | 22 |
23 class GURL; | 23 class GURL; |
24 class MessageLoop; | 24 class MessageLoop; |
25 | 25 |
26 namespace net { | 26 namespace net { |
27 | 27 |
28 class DhcpProxyScriptFetcher; | |
29 class HostResolver; | 28 class HostResolver; |
30 class InitProxyResolver; | 29 class InitProxyResolver; |
31 class NetworkDelegate; | 30 class NetworkDelegate; |
32 class ProxyResolver; | 31 class ProxyResolver; |
33 class ProxyScriptFetcher; | 32 class ProxyScriptFetcher; |
34 class URLRequestContext; | 33 class URLRequestContext; |
35 | 34 |
36 // This class can be used to resolve the proxy server to use when loading a | 35 // This class can be used to resolve the proxy server to use when loading a |
37 // HTTP(S) URL. It uses the given ProxyResolver to handle the actual proxy | 36 // HTTP(S) URL. It uses the given ProxyResolver to handle the actual proxy |
38 // resolution. See ProxyResolverV8 for example. | 37 // resolution. See ProxyResolverV8 for example. |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 // Profiling information for the request is saved to |net_log| if non-NULL. | 91 // Profiling information for the request is saved to |net_log| if non-NULL. |
93 int ReconsiderProxyAfterError(const GURL& url, | 92 int ReconsiderProxyAfterError(const GURL& url, |
94 ProxyInfo* results, | 93 ProxyInfo* results, |
95 CompletionCallback* callback, | 94 CompletionCallback* callback, |
96 PacRequest** pac_request, | 95 PacRequest** pac_request, |
97 const BoundNetLog& net_log); | 96 const BoundNetLog& net_log); |
98 | 97 |
99 // Call this method with a non-null |pac_request| to cancel the PAC request. | 98 // Call this method with a non-null |pac_request| to cancel the PAC request. |
100 void CancelPacRequest(PacRequest* pac_request); | 99 void CancelPacRequest(PacRequest* pac_request); |
101 | 100 |
102 // Sets the ProxyScriptFetcher and DhcpProxyScriptFetcher dependencies. This | 101 // Sets the ProxyScriptFetcher dependency. This is needed if the ProxyResolver |
103 // is needed if the ProxyResolver is of type ProxyResolverWithoutFetch. | 102 // is of type ProxyResolverWithoutFetch. ProxyService takes ownership of |
104 // ProxyService takes ownership of both objects. | 103 // |proxy_script_fetcher|. |
105 void SetProxyScriptFetchers( | 104 void SetProxyScriptFetcher(ProxyScriptFetcher* proxy_script_fetcher); |
106 ProxyScriptFetcher* proxy_script_fetcher, | |
107 DhcpProxyScriptFetcher* dhcp_proxy_script_fetcher); | |
108 ProxyScriptFetcher* GetProxyScriptFetcher() const; | 105 ProxyScriptFetcher* GetProxyScriptFetcher() const; |
109 | 106 |
110 // Tells this ProxyService to start using a new ProxyConfigService to | 107 // Tells this ProxyService to start using a new ProxyConfigService to |
111 // retrieve its ProxyConfig from. The new ProxyConfigService will immediately | 108 // retrieve its ProxyConfig from. The new ProxyConfigService will immediately |
112 // be queried for new config info which will be used for all subsequent | 109 // be queried for new config info which will be used for all subsequent |
113 // ResolveProxy calls. ProxyService takes ownership of | 110 // ResolveProxy calls. ProxyService takes ownership of |
114 // |new_proxy_config_service|. | 111 // |new_proxy_config_service|. |
115 void ResetConfigService(ProxyConfigService* new_proxy_config_service); | 112 void ResetConfigService(ProxyConfigService* new_proxy_config_service); |
116 | 113 |
117 // Tells the resolver to purge any memory it does not need. | 114 // Tells the resolver to purge any memory it does not need. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 // | 154 // |
158 // However, the disadvantages of using more than 1 thread are: | 155 // However, the disadvantages of using more than 1 thread are: |
159 // (a) can cause compatibility issues for scripts that rely on side effects | 156 // (a) can cause compatibility issues for scripts that rely on side effects |
160 // between runs (such scripts should not be common though). | 157 // between runs (such scripts should not be common though). |
161 // (b) increases the memory used by proxy resolving, as each thread will | 158 // (b) increases the memory used by proxy resolving, as each thread will |
162 // duplicate its own script context. | 159 // duplicate its own script context. |
163 | 160 |
164 // |proxy_script_fetcher| specifies the dependency to use for downloading | 161 // |proxy_script_fetcher| specifies the dependency to use for downloading |
165 // any PAC scripts. The resulting ProxyService will take ownership of it. | 162 // any PAC scripts. The resulting ProxyService will take ownership of it. |
166 // | 163 // |
167 // |dhcp_proxy_script_fetcher| specifies the dependency to use for attempting | |
168 // to retrieve the most appropriate PAC script configured in DHCP. The | |
169 // resulting ProxyService will take ownership of it. | |
170 // | |
171 // |host_resolver| points to the host resolving dependency the PAC script | 164 // |host_resolver| points to the host resolving dependency the PAC script |
172 // should use for any DNS queries. It must remain valid throughout the | 165 // should use for any DNS queries. It must remain valid throughout the |
173 // lifetime of the ProxyService. | 166 // lifetime of the ProxyService. |
174 // | 167 // |
175 // ########################################################################## | 168 // ########################################################################## |
176 // # See the warnings in net/proxy/proxy_resolver_v8.h describing the | 169 // # See the warnings in net/proxy/proxy_resolver_v8.h describing the |
177 // # multi-threading model. In order for this to be safe to use, *ALL* the | 170 // # multi-threading model. In order for this to be safe to use, *ALL* the |
178 // # other V8's running in the process must use v8::Locker. | 171 // # other V8's running in the process must use v8::Locker. |
179 // ########################################################################## | 172 // ########################################################################## |
180 static ProxyService* CreateUsingV8ProxyResolver( | 173 static ProxyService* CreateUsingV8ProxyResolver( |
181 ProxyConfigService* proxy_config_service, | 174 ProxyConfigService* proxy_config_service, |
182 size_t num_pac_threads, | 175 size_t num_pac_threads, |
183 ProxyScriptFetcher* proxy_script_fetcher, | 176 ProxyScriptFetcher* proxy_script_fetcher, |
184 DhcpProxyScriptFetcher* dhcp_proxy_script_fetcher, | |
185 HostResolver* host_resolver, | 177 HostResolver* host_resolver, |
186 NetLog* net_log, | 178 NetLog* net_log, |
187 NetworkDelegate* network_delegate); | 179 NetworkDelegate* network_delegate); |
188 | 180 |
189 // Same as CreateUsingV8ProxyResolver, except it uses system libraries | 181 // Same as CreateUsingV8ProxyResolver, except it uses system libraries |
190 // for evaluating the PAC script if available, otherwise skips | 182 // for evaluating the PAC script if available, otherwise skips |
191 // proxy autoconfig. | 183 // proxy autoconfig. |
192 static ProxyService* CreateUsingSystemProxyResolver( | 184 static ProxyService* CreateUsingSystemProxyResolver( |
193 ProxyConfigService* proxy_config_service, | 185 ProxyConfigService* proxy_config_service, |
194 size_t num_pac_threads, | 186 size_t num_pac_threads, |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 ProxyRetryInfoMap proxy_retry_info_; | 312 ProxyRetryInfoMap proxy_retry_info_; |
321 | 313 |
322 // Set of pending/inprogress requests. | 314 // Set of pending/inprogress requests. |
323 PendingRequests pending_requests_; | 315 PendingRequests pending_requests_; |
324 | 316 |
325 // The fetcher to use when downloading PAC scripts for the ProxyResolver. | 317 // The fetcher to use when downloading PAC scripts for the ProxyResolver. |
326 // This dependency can be NULL if our ProxyResolver has no need for | 318 // This dependency can be NULL if our ProxyResolver has no need for |
327 // external PAC script fetching. | 319 // external PAC script fetching. |
328 scoped_ptr<ProxyScriptFetcher> proxy_script_fetcher_; | 320 scoped_ptr<ProxyScriptFetcher> proxy_script_fetcher_; |
329 | 321 |
330 // The fetcher to use when attempting to download the most appropriate PAC | |
331 // script configured in DHCP, if any. Can be NULL if the ProxyResolver has | |
332 // no need for DHCP PAC script fetching. | |
333 scoped_ptr<DhcpProxyScriptFetcher> dhcp_proxy_script_fetcher_; | |
334 | |
335 // Callback for when |init_proxy_resolver_| is done. | 322 // Callback for when |init_proxy_resolver_| is done. |
336 CompletionCallbackImpl<ProxyService> init_proxy_resolver_callback_; | 323 CompletionCallbackImpl<ProxyService> init_proxy_resolver_callback_; |
337 | 324 |
338 // Helper to download the PAC script (wpad + custom) and apply fallback rules. | 325 // Helper to download the PAC script (wpad + custom) and apply fallback rules. |
339 // | 326 // |
340 // Note that the declaration is important here: |proxy_script_fetcher_| and | 327 // Note that the declaration is important here: |proxy_script_fetcher_| and |
341 // |proxy_resolver_| must outlive |init_proxy_resolver_|. | 328 // |proxy_resolver_| must outlive |init_proxy_resolver_|. |
342 scoped_ptr<InitProxyResolver> init_proxy_resolver_; | 329 scoped_ptr<InitProxyResolver> init_proxy_resolver_; |
343 | 330 |
344 State current_state_; | 331 State current_state_; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 | 377 |
391 base::WaitableEvent event_; | 378 base::WaitableEvent event_; |
392 CompletionCallbackImpl<SyncProxyServiceHelper> callback_; | 379 CompletionCallbackImpl<SyncProxyServiceHelper> callback_; |
393 ProxyInfo proxy_info_; | 380 ProxyInfo proxy_info_; |
394 int result_; | 381 int result_; |
395 }; | 382 }; |
396 | 383 |
397 } // namespace net | 384 } // namespace net |
398 | 385 |
399 #endif // NET_PROXY_PROXY_SERVICE_H_ | 386 #endif // NET_PROXY_PROXY_SERVICE_H_ |
OLD | NEW |