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

Unified Diff: net/proxy/dhcp_proxy_script_adapter_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: Merge to lkgr 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_adapter_fetcher_win.h
diff --git a/net/proxy/dhcp_proxy_script_adapter_fetcher_win.h b/net/proxy/dhcp_proxy_script_adapter_fetcher_win.h
index a8fc43cea0f7899178403d12f4eb49b674fef82b..651fefc7413a7a0fea9863f27d81488a9f18fb2f 100644
--- a/net/proxy/dhcp_proxy_script_adapter_fetcher_win.h
+++ b/net/proxy/dhcp_proxy_script_adapter_fetcher_win.h
@@ -107,62 +107,42 @@ class NET_EXPORT_PRIVATE DhcpProxyScriptAdapterFetcher
State state() const;
- // This inner class is used to encapsulate the worker thread, which has
- // only a weak reference back to the main object, so that the main object
- // can be destroyed before the thread ends. This also keeps the main
- // object completely thread safe and allows it to be non-refcounted.
- //
- // 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 encapsulates work done on a worker pool thread.
+ // By using a separate object, we can keep the main object completely
+ // thread safe and let it be non-refcounted.
+ class NET_EXPORT_PRIVATE DhcpQuery
+ : public base::RefCountedThreadSafe<DhcpQuery> {
public:
- // Creates and initializes (but does not start) the worker thread.
- explicit WorkerThread(
- const base::WeakPtr<DhcpProxyScriptAdapterFetcher>& owner);
- virtual ~WorkerThread();
+ DhcpQuery();
+ virtual ~DhcpQuery();
+
+ // This method should run on a worker pool thread, via PostTaskAndReply.
+ // After it has run, the |url()| method on this object will return the
+ // URL retrieved.
+ void GetPacURLForAdapter(const std::string& adapter_name);
- // Starts the worker thread, fetching information for |adapter_name| using
- // |get_pac_from_url_func|.
- void Start(const std::string& adapter_name);
+ // Returns the URL retrieved for the given adapter, once the task has run.
+ std::string url() const;
willchan no longer on Chromium 2011/10/13 22:33:45 Any reason not to make this return const std::stri
Jói 2011/10/13 22:46:07 Good catch, fixed.
protected:
// Virtual method introduced to allow unit testing.
virtual std::string ImplGetPacURLFromDhcp(const std::string& adapter_name);
private:
- // This is the method that runs on the worker thread.
- void ThreadFunc(const std::string& adapter_name);
-
- // Callback for the above; this executes back on the main thread,
- // not the worker thread.
- void OnThreadDone(const std::string& url);
-
- // All work except ThreadFunc and (sometimes) destruction should occur
- // on the thread that constructs the object.
- base::ThreadChecker thread_checker_;
+ // The URL retrieved for the given adapter.
+ std::string url_;
- // May only be accessed on the thread that constructs the object.
- base::WeakPtr<DhcpProxyScriptAdapterFetcher> 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_;
-
- DISALLOW_COPY_AND_ASSIGN(WorkerThread);
+ DISALLOW_COPY_AND_ASSIGN(DhcpQuery);
};
// Virtual methods introduced to allow unit testing.
virtual ProxyScriptFetcher* ImplCreateScriptFetcher();
- virtual WorkerThread* ImplCreateWorkerThread(
- const base::WeakPtr<DhcpProxyScriptAdapterFetcher>& owner);
+ virtual DhcpQuery* ImplCreateDhcpQuery();
virtual base::TimeDelta ImplGetTimeout() const;
private:
// Event/state transition handlers
- void OnQueryDhcpDone(const std::string& url);
+ void OnDhcpQueryDone(scoped_refptr<DhcpQuery> dhcp_query);
void OnTimeout();
void OnFetcherDone(int result);
void TransitionToFinish();
@@ -183,9 +163,6 @@ class NET_EXPORT_PRIVATE DhcpProxyScriptAdapterFetcher
// START, FINISH and CANCEL.
OldCompletionCallback* callback_;
- // Container for our worker thread. NULL if not currently running.
- scoped_refptr<WorkerThread> worker_thread_;
-
// Fetcher to retrieve PAC files once URL is known.
scoped_ptr<ProxyScriptFetcher> script_fetcher_;

Powered by Google App Engine
This is Rietveld 408576698