| 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_DHCP_SCRIPT_ADAPTER_FETCHER_WIN_H_ | 5 #ifndef NET_PROXY_DHCP_SCRIPT_ADAPTER_FETCHER_WIN_H_ |
| 6 #define NET_PROXY_DHCP_SCRIPT_ADAPTER_FETCHER_WIN_H_ | 6 #define NET_PROXY_DHCP_SCRIPT_ADAPTER_FETCHER_WIN_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/string16.h" | 12 #include "base/string16.h" |
| 13 #include "base/threading/non_thread_safe.h" | 13 #include "base/threading/non_thread_safe.h" |
| 14 #include "base/timer.h" | 14 #include "base/timer.h" |
| 15 #include "net/base/completion_callback.h" | 15 #include "net/base/completion_callback.h" |
| 16 #include "net/base/net_api.h" |
| 16 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
| 17 | 18 |
| 18 namespace base { | 19 namespace base { |
| 19 class MessageLoopProxy; | 20 class MessageLoopProxy; |
| 20 } | 21 } |
| 21 | 22 |
| 22 namespace net { | 23 namespace net { |
| 23 | 24 |
| 24 class ProxyScriptFetcher; | 25 class ProxyScriptFetcher; |
| 25 class URLRequestContext; | 26 class URLRequestContext; |
| 26 | 27 |
| 27 // For a given adapter, this class takes care of first doing a DHCP lookup | 28 // For a given adapter, this class takes care of first doing a DHCP lookup |
| 28 // to get the PAC URL, then if there is one, trying to fetch it. | 29 // to get the PAC URL, then if there is one, trying to fetch it. |
| 29 class DhcpProxyScriptAdapterFetcher | 30 class NET_TEST DhcpProxyScriptAdapterFetcher |
| 30 : public base::SupportsWeakPtr<DhcpProxyScriptAdapterFetcher>, | 31 : public base::SupportsWeakPtr<DhcpProxyScriptAdapterFetcher>, |
| 31 public base::NonThreadSafe { | 32 NON_EXPORTED_BASE(public base::NonThreadSafe) { |
| 32 public: | 33 public: |
| 33 // |url_request_context| must outlive DhcpProxyScriptAdapterFetcher. | 34 // |url_request_context| must outlive DhcpProxyScriptAdapterFetcher. |
| 34 explicit DhcpProxyScriptAdapterFetcher( | 35 explicit DhcpProxyScriptAdapterFetcher( |
| 35 URLRequestContext* url_request_context); | 36 URLRequestContext* url_request_context); |
| 36 virtual ~DhcpProxyScriptAdapterFetcher(); | 37 virtual ~DhcpProxyScriptAdapterFetcher(); |
| 37 | 38 |
| 38 // Starts a fetch. On completion (but not cancellation), |callback| | 39 // Starts a fetch. On completion (but not cancellation), |callback| |
| 39 // will be invoked with the network error indicating success or failure | 40 // will be invoked with the network error indicating success or failure |
| 40 // of fetching a DHCP-configured PAC file on this adapter. | 41 // of fetching a DHCP-configured PAC file on this adapter. |
| 41 // | 42 // |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 // | 75 // |
| 75 // This function executes synchronously due to limitations of the Windows | 76 // This function executes synchronously due to limitations of the Windows |
| 76 // DHCP client API. | 77 // DHCP client API. |
| 77 static std::string GetPacURLFromDhcp(const std::string& adapter_name); | 78 static std::string GetPacURLFromDhcp(const std::string& adapter_name); |
| 78 | 79 |
| 79 protected: | 80 protected: |
| 80 // This inner class is used to encapsulate the worker thread, which has | 81 // This inner class is used to encapsulate the worker thread, which has |
| 81 // only a weak reference back to the main object, so that the main object | 82 // only a weak reference back to the main object, so that the main object |
| 82 // can be destroyed before the thread ends. This also keeps the main | 83 // can be destroyed before the thread ends. This also keeps the main |
| 83 // object completely thread safe and allows it to be non-refcounted. | 84 // object completely thread safe and allows it to be non-refcounted. |
| 84 class WorkerThread : public base::RefCountedThreadSafe<WorkerThread> { | 85 class NET_TEST WorkerThread |
| 86 : public base::RefCountedThreadSafe<WorkerThread> { |
| 85 public: | 87 public: |
| 86 // Creates and initializes (but does not start) the worker thread. | 88 // Creates and initializes (but does not start) the worker thread. |
| 87 explicit WorkerThread( | 89 explicit WorkerThread( |
| 88 const base::WeakPtr<DhcpProxyScriptAdapterFetcher>& owner); | 90 const base::WeakPtr<DhcpProxyScriptAdapterFetcher>& owner); |
| 89 virtual ~WorkerThread(); | 91 virtual ~WorkerThread(); |
| 90 | 92 |
| 91 // Starts the worker thread, fetching information for |adapter_name| using | 93 // Starts the worker thread, fetching information for |adapter_name| using |
| 92 // |get_pac_from_url_func|. | 94 // |get_pac_from_url_func|. |
| 93 void Start(const std::string& adapter_name); | 95 void Start(const std::string& adapter_name); |
| 94 | 96 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 base::OneShotTimer<DhcpProxyScriptAdapterFetcher> wait_timer_; | 191 base::OneShotTimer<DhcpProxyScriptAdapterFetcher> wait_timer_; |
| 190 | 192 |
| 191 scoped_refptr<URLRequestContext> url_request_context_; | 193 scoped_refptr<URLRequestContext> url_request_context_; |
| 192 | 194 |
| 193 DISALLOW_IMPLICIT_CONSTRUCTORS(DhcpProxyScriptAdapterFetcher); | 195 DISALLOW_IMPLICIT_CONSTRUCTORS(DhcpProxyScriptAdapterFetcher); |
| 194 }; | 196 }; |
| 195 | 197 |
| 196 } // namespace net | 198 } // namespace net |
| 197 | 199 |
| 198 #endif // NET_PROXY_DHCP_SCRIPT_ADAPTER_FETCHER_WIN_H_ | 200 #endif // NET_PROXY_DHCP_SCRIPT_ADAPTER_FETCHER_WIN_H_ |
| OLD | NEW |