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

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

Issue 8139028: Add WorkerPool::PostTaskAndReply and use in DHCP code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Mark private Created 9 years, 2 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
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_PROXY_SCRIPT_FETCHER_WIN_H_ 5 #ifndef NET_PROXY_DHCP_PROXY_SCRIPT_FETCHER_WIN_H_
6 #define NET_PROXY_DHCP_PROXY_SCRIPT_FETCHER_WIN_H_ 6 #define NET_PROXY_DHCP_PROXY_SCRIPT_FETCHER_WIN_H_
7 #pragma once 7 #pragma once
8 8
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 // Sets |adapter_names| to contain the name of each network adapter on 43 // Sets |adapter_names| to contain the name of each network adapter on
44 // this machine that has DHCP enabled and is not a loop-back adapter. Returns 44 // this machine that has DHCP enabled and is not a loop-back adapter. Returns
45 // false on error. 45 // false on error.
46 static bool GetCandidateAdapterNames(std::set<std::string>* adapter_names); 46 static bool GetCandidateAdapterNames(std::set<std::string>* adapter_names);
47 47
48 protected: 48 protected:
49 int num_pending_fetchers() const; 49 int num_pending_fetchers() const;
50 50
51 URLRequestContext* url_request_context() const; 51 URLRequestContext* url_request_context() const;
52 52
53 // This inner class is used to encapsulate a worker thread that calls 53 // This inner class encapsulate work done on a worker pool thread.
54 // GetCandidateAdapterNames as it can take a couple of hundred 54 // The class calls GetCandidateAdapterNames, which can take a couple of
55 // milliseconds. 55 // hundred milliseconds.
56 // 56 class NET_EXPORT_PRIVATE AdapterQuery
57 // TODO(joi): Replace with PostTaskAndReply once http://crbug.com/86301 57 : public base::RefCountedThreadSafe<AdapterQuery> {
58 // has been implemented.
59 class NET_EXPORT_PRIVATE WorkerThread
60 : public base::RefCountedThreadSafe<WorkerThread> {
61 public: 58 public:
62 // Creates and initializes (but does not start) the worker thread. 59 AdapterQuery();
63 explicit WorkerThread( 60 virtual ~AdapterQuery();
64 const base::WeakPtr<DhcpProxyScriptFetcherWin>& owner);
65 virtual ~WorkerThread();
66 61
67 // Starts the worker thread. 62 // This is the method that runs on the worker pool thread.
68 void Start(); 63 void GetCandidateAdapterNames();
64
65 // This set is valid after GetCandidateAdapterNames has
66 // been run. Its lifetime is scoped by this object.
67 const std::set<std::string>& adapter_names() const;
69 68
70 protected: 69 protected:
71 WorkerThread(); // To override in unit tests only.
72 void Init(const base::WeakPtr<DhcpProxyScriptFetcherWin>& owner);
73
74 // Virtual method introduced to allow unit testing. 70 // Virtual method introduced to allow unit testing.
75 virtual bool ImplGetCandidateAdapterNames( 71 virtual bool ImplGetCandidateAdapterNames(
76 std::set<std::string>* adapter_names); 72 std::set<std::string>* adapter_names);
77 73
78 // Callback for ThreadFunc; this executes back on the main thread,
79 // not the worker thread. May be overridden by unit tests.
80 virtual void OnThreadDone();
81
82 private: 74 private:
83 // This is the method that runs on the worker thread.
84 void ThreadFunc();
85
86 // All work except ThreadFunc and (sometimes) destruction should occur
87 // on the thread that constructs the object.
88 base::ThreadChecker thread_checker_;
89
90 // May only be accessed on the thread that constructs the object.
91 base::WeakPtr<DhcpProxyScriptFetcherWin> owner_;
92
93 // Used by worker thread to post a message back to the original
94 // thread. Fine to use a proxy since in the case where the original
95 // thread has gone away, that would mean the |owner_| object is gone
96 // anyway, so there is nobody to receive the result.
97 scoped_refptr<base::MessageLoopProxy> origin_loop_;
98
99 // This is constructed on the originating thread, then used on the 75 // This is constructed on the originating thread, then used on the
100 // worker thread, then used again on the originating thread only when 76 // worker thread, then used again on the originating thread only when
101 // the task has completed on the worker thread. No locking required. 77 // the task has completed on the worker thread. No locking required.
102 std::set<std::string> adapter_names_; 78 std::set<std::string> adapter_names_;
103 79
104 DISALLOW_COPY_AND_ASSIGN(WorkerThread); 80 DISALLOW_COPY_AND_ASSIGN(AdapterQuery);
105 }; 81 };
106 82
107 // Virtual methods introduced to allow unit testing. 83 // Virtual methods introduced to allow unit testing.
108 virtual DhcpProxyScriptAdapterFetcher* ImplCreateAdapterFetcher(); 84 virtual DhcpProxyScriptAdapterFetcher* ImplCreateAdapterFetcher();
109 virtual WorkerThread* ImplCreateWorkerThread( 85 virtual AdapterQuery* ImplCreateAdapterQuery();
110 const base::WeakPtr<DhcpProxyScriptFetcherWin>& owner);
111 virtual int ImplGetMaxWaitMs(); 86 virtual int ImplGetMaxWaitMs();
87 virtual void ImplOnGetCandidateAdapterNamesDone() {}
112 88
113 private: 89 private:
114 // Event/state transition handlers 90 // Event/state transition handlers
115 void CancelImpl(); 91 void CancelImpl();
116 void OnGetCandidateAdapterNamesDone( 92 void OnGetCandidateAdapterNamesDone(scoped_refptr<AdapterQuery> query);
117 const std::set<std::string>& adapter_names);
118 void OnFetcherDone(int result); 93 void OnFetcherDone(int result);
119 void OnWaitTimer(); 94 void OnWaitTimer();
120 void TransitionToDone(); 95 void TransitionToDone();
121 96
122 // This is the outer state machine for fetching PAC configuration from 97 // This is the outer state machine for fetching PAC configuration from
123 // DHCP. It relies for sub-states on the state machine of the 98 // DHCP. It relies for sub-states on the state machine of the
124 // DhcpProxyScriptAdapterFetcher class. 99 // DhcpProxyScriptAdapterFetcher class.
125 // 100 //
126 // The goal of the implementation is to the following work in parallel 101 // The goal of the implementation is to the following work in parallel
127 // for all network adapters that are using DHCP: 102 // for all network adapters that are using DHCP:
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 // START and DONE. 151 // START and DONE.
177 string16* destination_string_; 152 string16* destination_string_;
178 153
179 // PAC URL retrieved from DHCP, if any. Valid only in state STATE_DONE. 154 // PAC URL retrieved from DHCP, if any. Valid only in state STATE_DONE.
180 GURL pac_url_; 155 GURL pac_url_;
181 156
182 base::OneShotTimer<DhcpProxyScriptFetcherWin> wait_timer_; 157 base::OneShotTimer<DhcpProxyScriptFetcherWin> wait_timer_;
183 158
184 scoped_refptr<URLRequestContext> url_request_context_; 159 scoped_refptr<URLRequestContext> url_request_context_;
185 160
186 scoped_refptr<WorkerThread> worker_thread_; 161 // NULL or the AdapterQuery currently in flight.
162 scoped_refptr<AdapterQuery> last_query_;
187 163
188 // Time |Fetch()| was last called, 0 if never. 164 // Time |Fetch()| was last called, 0 if never.
189 base::TimeTicks fetch_start_time_; 165 base::TimeTicks fetch_start_time_;
190 166
191 DISALLOW_IMPLICIT_CONSTRUCTORS(DhcpProxyScriptFetcherWin); 167 DISALLOW_IMPLICIT_CONSTRUCTORS(DhcpProxyScriptFetcherWin);
192 }; 168 };
193 169
194 } // namespace net 170 } // namespace net
195 171
196 #endif // NET_PROXY_DHCP_PROXY_SCRIPT_FETCHER_WIN_H_ 172 #endif // NET_PROXY_DHCP_PROXY_SCRIPT_FETCHER_WIN_H_
OLDNEW
« no previous file with comments | « net/proxy/dhcp_proxy_script_adapter_fetcher_win_unittest.cc ('k') | net/proxy/dhcp_proxy_script_fetcher_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698