| OLD | NEW | 
|    1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |    1 // Copyright (c) 2009 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  |    7  | 
|    8 #include <string> |    8 #include <string> | 
|    9 #include <vector> |    9 #include <vector> | 
|   10  |   10  | 
|   11 #include "base/ref_counted.h" |   11 #include "base/ref_counted.h" | 
|   12 #include "base/scoped_ptr.h" |   12 #include "base/scoped_ptr.h" | 
|   13 #include "base/waitable_event.h" |   13 #include "base/waitable_event.h" | 
|   14 #include "net/base/completion_callback.h" |   14 #include "net/base/completion_callback.h" | 
 |   15 #include "net/base/network_change_notifier.h" | 
|   15 #include "net/proxy/proxy_server.h" |   16 #include "net/proxy/proxy_server.h" | 
|   16 #include "net/proxy/proxy_info.h" |   17 #include "net/proxy/proxy_info.h" | 
|   17 #include "testing/gtest/include/gtest/gtest_prod.h" |   18 #include "testing/gtest/include/gtest/gtest_prod.h" | 
|   18  |   19  | 
|   19 class GURL; |   20 class GURL; | 
|   20 class MessageLoop; |   21 class MessageLoop; | 
|   21 class URLRequestContext; |   22 class URLRequestContext; | 
|   22  |   23  | 
|   23 namespace net { |   24 namespace net { | 
|   24  |   25  | 
|   25 class InitProxyResolver; |   26 class InitProxyResolver; | 
|   26 class LoadLog; |   27 class LoadLog; | 
|   27 class ProxyConfigService; |   28 class ProxyConfigService; | 
|   28 class ProxyResolver; |   29 class ProxyResolver; | 
|   29 class ProxyScriptFetcher; |   30 class ProxyScriptFetcher; | 
|   30  |   31  | 
|   31 // This class can be used to resolve the proxy server to use when loading a |   32 // This class can be used to resolve the proxy server to use when loading a | 
|   32 // HTTP(S) URL.  It uses the given ProxyResolver to handle the actual proxy |   33 // HTTP(S) URL.  It uses the given ProxyResolver to handle the actual proxy | 
|   33 // resolution.  See ProxyResolverV8 for example. |   34 // resolution.  See ProxyResolverV8 for example. | 
|   34 class ProxyService : public base::RefCountedThreadSafe<ProxyService> { |   35 class ProxyService : public base::RefCountedThreadSafe<ProxyService>, | 
 |   36                      public NetworkChangeNotifier::Observer { | 
|   35  public: |   37  public: | 
|   36   // The instance takes ownership of |config_service| and |resolver|. |   38   // The instance takes ownership of |config_service| and |resolver|. | 
|   37   ProxyService(ProxyConfigService* config_service, ProxyResolver* resolver); |   39   // If |network_change_notifier| is non-NULL, the proxy service will register | 
 |   40   // with it to detect when the network setup has changed. This is used to | 
 |   41   // decide when to re-configure the proxy discovery. | 
 |   42   ProxyService(ProxyConfigService* config_service, ProxyResolver* resolver, | 
 |   43                NetworkChangeNotifier* network_change_notifier); | 
|   38  |   44  | 
|   39   // Used internally to handle PAC queries. |   45   // Used internally to handle PAC queries. | 
|   40   // TODO(eroman): consider naming this simply "Request". |   46   // TODO(eroman): consider naming this simply "Request". | 
|   41   class PacRequest; |   47   class PacRequest; | 
|   42  |   48  | 
|   43   // Returns ERR_IO_PENDING if the proxy information could not be provided |   49   // Returns ERR_IO_PENDING if the proxy information could not be provided | 
|   44   // synchronously, to indicate that the result will be available when the |   50   // synchronously, to indicate that the result will be available when the | 
|   45   // callback is run.  The callback is run on the thread that calls |   51   // callback is run.  The callback is run on the thread that calls | 
|   46   // ResolveProxy. |   52   // ResolveProxy. | 
|   47   // |   53   // | 
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  119     return config_; |  125     return config_; | 
|  120   } |  126   } | 
|  121  |  127  | 
|  122   // Creates a proxy service that polls |proxy_config_service| to notice when |  128   // Creates a proxy service that polls |proxy_config_service| to notice when | 
|  123   // the proxy settings change. We take ownership of |proxy_config_service|. |  129   // the proxy settings change. We take ownership of |proxy_config_service|. | 
|  124   // Iff |use_v8_resolver| is true, then the V8 implementation is |  130   // Iff |use_v8_resolver| is true, then the V8 implementation is | 
|  125   // used. |  131   // used. | 
|  126   // |url_request_context| is only used when use_v8_resolver is true: |  132   // |url_request_context| is only used when use_v8_resolver is true: | 
|  127   // it specifies the URL request context that will be used if a PAC |  133   // it specifies the URL request context that will be used if a PAC | 
|  128   // script needs to be fetched. |  134   // script needs to be fetched. | 
 |  135   // |network_change_notifier| may be NULL. Otherwise it will be used to | 
 |  136   // signal the ProxyService when the network setup has changed. | 
|  129   // |io_loop| points to the IO thread's message loop. It is only used |  137   // |io_loop| points to the IO thread's message loop. It is only used | 
|  130   // when pc is NULL. |  138   // when pc is NULL. | 
|  131   // ########################################################################## |  139   // ########################################################################## | 
|  132   // # See the warnings in net/proxy/proxy_resolver_v8.h describing the |  140   // # See the warnings in net/proxy/proxy_resolver_v8.h describing the | 
|  133   // # multi-threading model. In order for this to be safe to use, *ALL* the |  141   // # multi-threading model. In order for this to be safe to use, *ALL* the | 
|  134   // # other V8's running in the process must use v8::Locker. |  142   // # other V8's running in the process must use v8::Locker. | 
|  135   // ########################################################################## |  143   // ########################################################################## | 
|  136   static ProxyService* Create( |  144   static ProxyService* Create( | 
|  137       ProxyConfigService* proxy_config_service, |  145       ProxyConfigService* proxy_config_service, | 
|  138       bool use_v8_resolver, |  146       bool use_v8_resolver, | 
|  139       URLRequestContext* url_request_context, |  147       URLRequestContext* url_request_context, | 
 |  148       NetworkChangeNotifier* network_change_notifier, | 
|  140       MessageLoop* io_loop); |  149       MessageLoop* io_loop); | 
|  141  |  150  | 
|  142   // Convenience method that creates a proxy service using the |  151   // Convenience method that creates a proxy service using the | 
|  143   // specified fixed settings. |pc| must not be NULL. |  152   // specified fixed settings. |pc| must not be NULL. | 
|  144   static ProxyService* CreateFixed(const ProxyConfig& pc); |  153   static ProxyService* CreateFixed(const ProxyConfig& pc); | 
|  145  |  154  | 
|  146   // Creates a proxy service that always fails to fetch the proxy configuration, |  155   // Creates a proxy service that always fails to fetch the proxy configuration, | 
|  147   // so it falls back to direct connect. |  156   // so it falls back to direct connect. | 
|  148   static ProxyService* CreateNull(); |  157   static ProxyService* CreateNull(); | 
|  149  |  158  | 
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  231  |  240  | 
|  232   // Returns true if the URL passed in should not go through the proxy server. |  241   // Returns true if the URL passed in should not go through the proxy server. | 
|  233   // 1. If the proxy settings say to bypass local names, and |IsLocalName(url)|. |  242   // 1. If the proxy settings say to bypass local names, and |IsLocalName(url)|. | 
|  234   // 2. The URL matches one of the entities in the proxy bypass list. |  243   // 2. The URL matches one of the entities in the proxy bypass list. | 
|  235   bool ShouldBypassProxyForURL(const GURL& url); |  244   bool ShouldBypassProxyForURL(const GURL& url); | 
|  236  |  245  | 
|  237   // Returns true if |url| is to an intranet site (using non-FQDN as the |  246   // Returns true if |url| is to an intranet site (using non-FQDN as the | 
|  238   // heuristic). |  247   // heuristic). | 
|  239   static bool IsLocalName(const GURL& url); |  248   static bool IsLocalName(const GURL& url); | 
|  240  |  249  | 
 |  250   // NetworkChangeNotifier::Observer methods: | 
 |  251   virtual void OnIPAddressChanged(); | 
 |  252  | 
|  241   scoped_ptr<ProxyConfigService> config_service_; |  253   scoped_ptr<ProxyConfigService> config_service_; | 
|  242   scoped_ptr<ProxyResolver> resolver_; |  254   scoped_ptr<ProxyResolver> resolver_; | 
|  243  |  255  | 
|  244   // We store the proxy config and a counter (ID) that is incremented each time |  256   // We store the proxy config and a counter (ID) that is incremented each time | 
|  245   // the config changes. |  257   // the config changes. | 
|  246   ProxyConfig config_; |  258   ProxyConfig config_; | 
|  247  |  259  | 
|  248   // Increasing ID to give to the next ProxyConfig that we set. |  260   // Increasing ID to give to the next ProxyConfig that we set. | 
|  249   int next_config_id_; |  261   int next_config_id_; | 
|  250  |  262  | 
| (...skipping 19 matching lines...) Expand all  Loading... | 
|  270  |  282  | 
|  271   // Helper to download the PAC script (wpad + custom) and apply fallback rules. |  283   // Helper to download the PAC script (wpad + custom) and apply fallback rules. | 
|  272   // |  284   // | 
|  273   // Note that the declaration is important here: |proxy_script_fetcher_| and |  285   // Note that the declaration is important here: |proxy_script_fetcher_| and | 
|  274   // |proxy_resolver_| must outlive |init_proxy_resolver_|. |  286   // |proxy_resolver_| must outlive |init_proxy_resolver_|. | 
|  275   scoped_ptr<InitProxyResolver> init_proxy_resolver_; |  287   scoped_ptr<InitProxyResolver> init_proxy_resolver_; | 
|  276  |  288  | 
|  277   // Log from the *last* time |init_proxy_resolver_.Init()| was called, or NULL. |  289   // Log from the *last* time |init_proxy_resolver_.Init()| was called, or NULL. | 
|  278   scoped_refptr<LoadLog> init_proxy_resolver_log_; |  290   scoped_refptr<LoadLog> init_proxy_resolver_log_; | 
|  279  |  291  | 
 |  292   // The (possibly NULL) network change notifier that we use to decide when | 
 |  293   // to refetch PAC scripts or re-run WPAD. | 
 |  294   scoped_refptr<NetworkChangeNotifier> network_change_notifier_; | 
 |  295  | 
|  280   DISALLOW_COPY_AND_ASSIGN(ProxyService); |  296   DISALLOW_COPY_AND_ASSIGN(ProxyService); | 
|  281 }; |  297 }; | 
|  282  |  298  | 
|  283 // Wrapper for invoking methods on a ProxyService synchronously. |  299 // Wrapper for invoking methods on a ProxyService synchronously. | 
|  284 class SyncProxyServiceHelper |  300 class SyncProxyServiceHelper | 
|  285     : public base::RefCountedThreadSafe<SyncProxyServiceHelper> { |  301     : public base::RefCountedThreadSafe<SyncProxyServiceHelper> { | 
|  286  public: |  302  public: | 
|  287   SyncProxyServiceHelper(MessageLoop* io_message_loop, |  303   SyncProxyServiceHelper(MessageLoop* io_message_loop, | 
|  288                          ProxyService* proxy_service); |  304                          ProxyService* proxy_service); | 
|  289  |  305  | 
| (...skipping 16 matching lines...) Expand all  Loading... | 
|  306  |  322  | 
|  307   base::WaitableEvent event_; |  323   base::WaitableEvent event_; | 
|  308   CompletionCallbackImpl<SyncProxyServiceHelper> callback_; |  324   CompletionCallbackImpl<SyncProxyServiceHelper> callback_; | 
|  309   ProxyInfo proxy_info_; |  325   ProxyInfo proxy_info_; | 
|  310   int result_; |  326   int result_; | 
|  311 }; |  327 }; | 
|  312  |  328  | 
|  313 }  // namespace net |  329 }  // namespace net | 
|  314  |  330  | 
|  315 #endif  // NET_PROXY_PROXY_SERVICE_H_ |  331 #endif  // NET_PROXY_PROXY_SERVICE_H_ | 
| OLD | NEW |