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

Unified 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: Addressing review comments. Fixing flakiness in reuse test. 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 side-by-side diff with in-line comments
Download patch
Index: net/proxy/dhcp_proxy_script_fetcher_win.h
diff --git a/net/proxy/dhcp_proxy_script_fetcher_win.h b/net/proxy/dhcp_proxy_script_fetcher_win.h
index ea14eff2ed7102af8b52814a0385c4bcf29498ba..0d7dc3ec5297328fed72e5531acbde6060053f66 100644
--- a/net/proxy/dhcp_proxy_script_fetcher_win.h
+++ b/net/proxy/dhcp_proxy_script_fetcher_win.h
@@ -50,71 +50,46 @@ class NET_EXPORT_PRIVATE DhcpProxyScriptFetcherWin
URLRequestContext* url_request_context() const;
- // This inner class is used to encapsulate a worker thread that calls
- // GetCandidateAdapterNames as it can take a couple of hundred
- // milliseconds.
- //
- // TODO(joi): Replace with PostTaskAndReply once http://crbug.com/86301
- // has been implemented.
- class NET_EXPORT_PRIVATE WorkerThread
- : public base::RefCountedThreadSafe<WorkerThread> {
+ // This inner class encapsulate work done on a worker pool thread.
+ // The class calls GetCandidateAdapterNames, which can take a couple of
+ // hundred milliseconds.
+ class NET_EXPORT_PRIVATE AdapterQuery
+ : public base::RefCountedThreadSafe<AdapterQuery> {
public:
- // Creates and initializes (but does not start) the worker thread.
- explicit WorkerThread(
- const base::WeakPtr<DhcpProxyScriptFetcherWin>& owner);
- virtual ~WorkerThread();
+ AdapterQuery();
+ virtual ~AdapterQuery();
- // Starts the worker thread.
- void Start();
+ // This is the method that runs on the worker pool thread.
+ void GetCandidateAdapterNames();
- protected:
- WorkerThread(); // To override in unit tests only.
- void Init(const base::WeakPtr<DhcpProxyScriptFetcherWin>& owner);
+ // This set is valid after GetCandidateAdapterNames has
+ // been run. Its lifetime is scoped by this object.
+ const std::set<std::string>& adapter_names() const;
+ protected:
// Virtual method introduced to allow unit testing.
virtual bool ImplGetCandidateAdapterNames(
std::set<std::string>* adapter_names);
- // Callback for ThreadFunc; this executes back on the main thread,
- // not the worker thread. May be overridden by unit tests.
- virtual void OnThreadDone();
-
private:
- // This is the method that runs on the worker thread.
- void ThreadFunc();
-
- // All work except ThreadFunc and (sometimes) destruction should occur
- // on the thread that constructs the object.
- base::ThreadChecker thread_checker_;
-
- // May only be accessed on the thread that constructs the object.
- base::WeakPtr<DhcpProxyScriptFetcherWin> owner_;
-
- // Used by worker thread to post a message back to the original
- // thread. Fine to use a proxy since in the case where the original
- // thread has gone away, that would mean the |owner_| object is gone
- // anyway, so there is nobody to receive the result.
- scoped_refptr<base::MessageLoopProxy> origin_loop_;
-
// This is constructed on the originating thread, then used on the
// worker thread, then used again on the originating thread only when
// the task has completed on the worker thread. No locking required.
std::set<std::string> adapter_names_;
- DISALLOW_COPY_AND_ASSIGN(WorkerThread);
+ DISALLOW_COPY_AND_ASSIGN(AdapterQuery);
};
// Virtual methods introduced to allow unit testing.
virtual DhcpProxyScriptAdapterFetcher* ImplCreateAdapterFetcher();
- virtual WorkerThread* ImplCreateWorkerThread(
- const base::WeakPtr<DhcpProxyScriptFetcherWin>& owner);
+ virtual AdapterQuery* ImplCreateAdapterQuery();
virtual int ImplGetMaxWaitMs();
+ virtual void ImplOnGetCandidateAdapterNamesDone() {}
private:
// Event/state transition handlers
void CancelImpl();
- void OnGetCandidateAdapterNamesDone(
- const std::set<std::string>& adapter_names);
+ void OnGetCandidateAdapterNamesDone(scoped_refptr<AdapterQuery> query);
void OnFetcherDone(int result);
void OnWaitTimer();
void TransitionToDone();
@@ -183,7 +158,8 @@ class NET_EXPORT_PRIVATE DhcpProxyScriptFetcherWin
scoped_refptr<URLRequestContext> url_request_context_;
- scoped_refptr<WorkerThread> worker_thread_;
+ // NULL or the AdapterQuery currently in flight.
+ scoped_refptr<AdapterQuery> last_query_;
// Time |Fetch()| was last called, 0 if never.
base::TimeTicks fetch_start_time_;

Powered by Google App Engine
This is Rietveld 408576698