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; |
28 class HostResolver; | 29 class HostResolver; |
29 class InitProxyResolver; | 30 class InitProxyResolver; |
30 class ProxyResolver; | 31 class ProxyResolver; |
31 class ProxyScriptFetcher; | 32 class ProxyScriptFetcher; |
32 class URLRequestContext; | 33 class URLRequestContext; |
33 | 34 |
34 // 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 |
35 // 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 |
36 // resolution. See ProxyResolverV8 for example. | 37 // resolution. See ProxyResolverV8 for example. |
37 class ProxyService : public NetworkChangeNotifier::IPAddressObserver, | 38 class ProxyService : public NetworkChangeNotifier::IPAddressObserver, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 // 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. |
91 int ReconsiderProxyAfterError(const GURL& url, | 92 int ReconsiderProxyAfterError(const GURL& url, |
92 ProxyInfo* results, | 93 ProxyInfo* results, |
93 CompletionCallback* callback, | 94 CompletionCallback* callback, |
94 PacRequest** pac_request, | 95 PacRequest** pac_request, |
95 const BoundNetLog& net_log); | 96 const BoundNetLog& net_log); |
96 | 97 |
97 // 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. |
98 void CancelPacRequest(PacRequest* pac_request); | 99 void CancelPacRequest(PacRequest* pac_request); |
99 | 100 |
100 // Sets the ProxyScriptFetcher dependency. This is needed if the ProxyResolver | 101 // Sets the ProxyScriptFetcher and DhcpProxyScriptFetcher dependencies. This |
101 // is of type ProxyResolverWithoutFetch. ProxyService takes ownership of | 102 // is needed if the ProxyResolver is of type ProxyResolverWithoutFetch. |
102 // |proxy_script_fetcher|. | 103 // ProxyService takes ownership of both objects. |
103 void SetProxyScriptFetcher(ProxyScriptFetcher* proxy_script_fetcher); | 104 void SetProxyScriptFetchers( |
| 105 ProxyScriptFetcher* proxy_script_fetcher, |
| 106 DhcpProxyScriptFetcher* dhcp_proxy_script_fetcher); |
104 ProxyScriptFetcher* GetProxyScriptFetcher() const; | 107 ProxyScriptFetcher* GetProxyScriptFetcher() const; |
| 108 DhcpProxyScriptFetcher* GetDhcpProxyScriptFetcher() const; |
105 | 109 |
106 // Tells this ProxyService to start using a new ProxyConfigService to | 110 // Tells this ProxyService to start using a new ProxyConfigService to |
107 // retrieve its ProxyConfig from. The new ProxyConfigService will immediately | 111 // retrieve its ProxyConfig from. The new ProxyConfigService will immediately |
108 // be queried for new config info which will be used for all subsequent | 112 // be queried for new config info which will be used for all subsequent |
109 // ResolveProxy calls. ProxyService takes ownership of | 113 // ResolveProxy calls. ProxyService takes ownership of |
110 // |new_proxy_config_service|. | 114 // |new_proxy_config_service|. |
111 void ResetConfigService(ProxyConfigService* new_proxy_config_service); | 115 void ResetConfigService(ProxyConfigService* new_proxy_config_service); |
112 | 116 |
113 // Tells the resolver to purge any memory it does not need. | 117 // Tells the resolver to purge any memory it does not need. |
114 void PurgeMemory(); | 118 void PurgeMemory(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 // | 157 // |
154 // However, the disadvantages of using more than 1 thread are: | 158 // However, the disadvantages of using more than 1 thread are: |
155 // (a) can cause compatibility issues for scripts that rely on side effects | 159 // (a) can cause compatibility issues for scripts that rely on side effects |
156 // between runs (such scripts should not be common though). | 160 // between runs (such scripts should not be common though). |
157 // (b) increases the memory used by proxy resolving, as each thread will | 161 // (b) increases the memory used by proxy resolving, as each thread will |
158 // duplicate its own script context. | 162 // duplicate its own script context. |
159 | 163 |
160 // |proxy_script_fetcher| specifies the dependency to use for downloading | 164 // |proxy_script_fetcher| specifies the dependency to use for downloading |
161 // any PAC scripts. The resulting ProxyService will take ownership of it. | 165 // any PAC scripts. The resulting ProxyService will take ownership of it. |
162 // | 166 // |
| 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 // |
163 // |host_resolver| points to the host resolving dependency the PAC script | 171 // |host_resolver| points to the host resolving dependency the PAC script |
164 // should use for any DNS queries. It must remain valid throughout the | 172 // should use for any DNS queries. It must remain valid throughout the |
165 // lifetime of the ProxyService. | 173 // lifetime of the ProxyService. |
166 // | 174 // |
167 // ########################################################################## | 175 // ########################################################################## |
168 // # See the warnings in net/proxy/proxy_resolver_v8.h describing the | 176 // # See the warnings in net/proxy/proxy_resolver_v8.h describing the |
169 // # multi-threading model. In order for this to be safe to use, *ALL* the | 177 // # multi-threading model. In order for this to be safe to use, *ALL* the |
170 // # other V8's running in the process must use v8::Locker. | 178 // # other V8's running in the process must use v8::Locker. |
171 // ########################################################################## | 179 // ########################################################################## |
172 static ProxyService* CreateUsingV8ProxyResolver( | 180 static ProxyService* CreateUsingV8ProxyResolver( |
173 ProxyConfigService* proxy_config_service, | 181 ProxyConfigService* proxy_config_service, |
174 size_t num_pac_threads, | 182 size_t num_pac_threads, |
175 ProxyScriptFetcher* proxy_script_fetcher, | 183 ProxyScriptFetcher* proxy_script_fetcher, |
| 184 DhcpProxyScriptFetcher* dhcp_proxy_script_fetcher, |
176 HostResolver* host_resolver, | 185 HostResolver* host_resolver, |
177 NetLog* net_log); | 186 NetLog* net_log); |
178 | 187 |
179 // Same as CreateUsingV8ProxyResolver, except it uses system libraries | 188 // Same as CreateUsingV8ProxyResolver, except it uses system libraries |
180 // for evaluating the PAC script if available, otherwise skips | 189 // for evaluating the PAC script if available, otherwise skips |
181 // proxy autoconfig. | 190 // proxy autoconfig. |
182 static ProxyService* CreateUsingSystemProxyResolver( | 191 static ProxyService* CreateUsingSystemProxyResolver( |
183 ProxyConfigService* proxy_config_service, | 192 ProxyConfigService* proxy_config_service, |
184 size_t num_pac_threads, | 193 size_t num_pac_threads, |
185 NetLog* net_log); | 194 NetLog* net_log); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 ProxyRetryInfoMap proxy_retry_info_; | 319 ProxyRetryInfoMap proxy_retry_info_; |
311 | 320 |
312 // Set of pending/inprogress requests. | 321 // Set of pending/inprogress requests. |
313 PendingRequests pending_requests_; | 322 PendingRequests pending_requests_; |
314 | 323 |
315 // The fetcher to use when downloading PAC scripts for the ProxyResolver. | 324 // The fetcher to use when downloading PAC scripts for the ProxyResolver. |
316 // This dependency can be NULL if our ProxyResolver has no need for | 325 // This dependency can be NULL if our ProxyResolver has no need for |
317 // external PAC script fetching. | 326 // external PAC script fetching. |
318 scoped_ptr<ProxyScriptFetcher> proxy_script_fetcher_; | 327 scoped_ptr<ProxyScriptFetcher> proxy_script_fetcher_; |
319 | 328 |
| 329 // The fetcher to use when attempting to download the most appropriate PAC |
| 330 // script configured in DHCP, if any. Can be NULL if the ProxyResolver has |
| 331 // no need for DHCP PAC script fetching. |
| 332 scoped_ptr<DhcpProxyScriptFetcher> dhcp_proxy_script_fetcher_; |
| 333 |
320 // Callback for when |init_proxy_resolver_| is done. | 334 // Callback for when |init_proxy_resolver_| is done. |
321 CompletionCallbackImpl<ProxyService> init_proxy_resolver_callback_; | 335 CompletionCallbackImpl<ProxyService> init_proxy_resolver_callback_; |
322 | 336 |
323 // Helper to download the PAC script (wpad + custom) and apply fallback rules. | 337 // Helper to download the PAC script (wpad + custom) and apply fallback rules. |
324 // | 338 // |
325 // Note that the declaration is important here: |proxy_script_fetcher_| and | 339 // Note that the declaration is important here: |proxy_script_fetcher_| and |
326 // |proxy_resolver_| must outlive |init_proxy_resolver_|. | 340 // |proxy_resolver_| must outlive |init_proxy_resolver_|. |
327 scoped_ptr<InitProxyResolver> init_proxy_resolver_; | 341 scoped_ptr<InitProxyResolver> init_proxy_resolver_; |
328 | 342 |
329 State current_state_; | 343 State current_state_; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 | 385 |
372 base::WaitableEvent event_; | 386 base::WaitableEvent event_; |
373 CompletionCallbackImpl<SyncProxyServiceHelper> callback_; | 387 CompletionCallbackImpl<SyncProxyServiceHelper> callback_; |
374 ProxyInfo proxy_info_; | 388 ProxyInfo proxy_info_; |
375 int result_; | 389 int result_; |
376 }; | 390 }; |
377 | 391 |
378 } // namespace net | 392 } // namespace net |
379 | 393 |
380 #endif // NET_PROXY_PROXY_SERVICE_H_ | 394 #endif // NET_PROXY_PROXY_SERVICE_H_ |
OLD | NEW |