Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: net/proxy/dhcp_proxy_script_fetcher_win.h

Issue 6831025: Adds support for the DHCP portion of the WPAD (proxy auto-discovery) protocol. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Isolate worker thread to separate object. Refcount context. Fix mandatory PAC. Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef NET_PROXY_DHCP_PROXY_SCRIPT_FETCHER_WIN_H_
6 #define NET_PROXY_DHCP_PROXY_SCRIPT_FETCHER_WIN_H_
7 #pragma once
8
9 #include <set>
10 #include <string>
11
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/scoped_vector.h"
14 #include "base/threading/non_thread_safe.h"
15 #include "base/timer.h"
16 #include "net/proxy/dhcp_proxy_script_fetcher.h"
17
18 namespace net {
19
20 class DhcpProxyScriptAdapterFetcher;
21 class URLRequestContext;
22
23 // Windows-specific implementation.
24 class WindowsDhcpProxyScriptFetcher
eroman 2011/05/17 04:39:39 nit: for consistency with the file name, I suggest
Jói 2011/05/17 15:38:35 Done.
25 : public DhcpProxyScriptFetcher,
26 public base::NonThreadSafe {
27 public:
28 // Creates a WindowsDhcpProxyScriptFetcher that issues requests through
29 // |url_request_context|. |url_request_context| must remain valid for
30 // the lifetime of WindowsDhcpProxyScriptFetcher.
31 explicit WindowsDhcpProxyScriptFetcher(
32 URLRequestContext* url_request_context);
33 virtual ~WindowsDhcpProxyScriptFetcher();
34
35 // DhcpProxyScriptFetcher implementation.
36 int Fetch(string16* utf16_text, CompletionCallback* callback) OVERRIDE;
37 void Cancel() OVERRIDE;
38 const GURL& GetPacURL() const OVERRIDE;
39 std::string GetFetcherName() const OVERRIDE;
40
41 // Sets |adapter_names| to contain the name of each network adapter on
42 // this machine that has DHCP enabled and is not a loop-back adapter. Returns
43 // false on error.
44 static bool GetCandidateAdapterNames(std::set<std::string>* adapter_names);
45
46 protected:
47 // Event/state transition handlers
48 void CancelImpl(bool clear_fetchers);
49 void OnFetcherDone(int result);
50 void OnWaitTimer();
51 void TransitionToDone();
52
53 // Virtual methods introduced to allow unit testing.
54 virtual DhcpProxyScriptAdapterFetcher* ImplCreateAdapterFetcher();
55 virtual bool ImplGetCandidateAdapterNames(
56 std::set<std::string>* adapter_names);
57 virtual int ImplGetMaxWaitMs();
58
59 // This is the outer state machine for fetching PAC configuration from
60 // DHCP. It relies for sub-states on the state machine of the
61 // DhcpProxyScriptAdapterFetcher class.
62 //
63 // The goal of the implementation is to the following work in parallel
64 // for all network adapters that are using DHCP:
65 // a) Try to get the PAC URL configured in DHCP;
66 // b) If one is configured, try to fetch the PAC URL.
67 // c) Once this is done for all adapters, or a timeout has passed after
68 // it has completed for the fastest adapter, return the PAC file
69 // available for the most preferred network adapter, if any.
70 //
71 // The state machine goes from START->NO_RESULTS when it creates
72 // and starts an DhcpProxyScriptAdapterFetcher for each adapter. It goes
73 // from NO_RESULTS->SOME_RESULTS when it gets the first result; at this
74 // point a wait timer is started. It goes from SOME_RESULTS->DONE in
75 // two cases: All results are known, or the wait timer expired. A call
76 // to Cancel() will also go straight to DONE from any state. Any
77 // way the DONE state is entered, we will at that point cancel any
78 // outstanding work and return the best known PAC script or the empty
79 // string.
80 //
81 // The state machine is reset for each Fetch(), a call to which is
82 // only valid in states START and DONE, as only one Fetch() is
83 // allowed to be outstanding at any given time.
84 enum State {
85 STATE_START,
86 STATE_NO_RESULTS,
87 STATE_SOME_RESULTS,
88 STATE_DONE,
89 };
90
91 // Current state of this state machine.
92 State state_;
93
94 // Vector, in Windows' network adapter preference order, of
95 // DhcpProxyScriptAdapterFetcher objects that are or were attempting
96 // to fetch a PAC file based on DHCP configuration.
97 typedef ScopedVector<DhcpProxyScriptAdapterFetcher> FetcherVector;
eroman 2011/05/17 04:39:39 cool, i didn't know about ScopedVector until readi
Jói 2011/05/17 15:38:35 Yep, it's nice :)
98 FetcherVector fetchers_;
99
100 // Callback invoked when any fetcher completes.
101 CompletionCallbackImpl<WindowsDhcpProxyScriptFetcher> fetcher_callback_;
102
103 // Number of fetchers we are waiting for.
104 int num_pending_fetchers_;
105
106 // Lets our client know we're done. Not valid in states START or DONE.
107 CompletionCallback* client_callback_;
108
109 // Pointer to string we will write results to. Not valid in states
110 // START and DONE.
111 string16* destination_string_;
112
113 // PAC URL retrieved from DHCP, if any. Valid only in state STATE_DONE.
114 GURL pac_url_;
115
116 base::OneShotTimer<WindowsDhcpProxyScriptFetcher> wait_timer_;
117
118 scoped_refptr<URLRequestContext> url_request_context_;
119
120 DISALLOW_IMPLICIT_CONSTRUCTORS(WindowsDhcpProxyScriptFetcher);
121 };
122
123 } // namespace net
124
125 #endif // NET_PROXY_DHCP_PROXY_SCRIPT_FETCHER_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698