summaryrefslogtreecommitdiffstats
path: root/net/proxy
diff options
context:
space:
mode:
Diffstat (limited to 'net/proxy')
-rw-r--r--net/proxy/dhcp_proxy_script_adapter_fetcher_win.cc69
-rw-r--r--net/proxy/dhcp_proxy_script_adapter_fetcher_win.h61
-rw-r--r--net/proxy/dhcp_proxy_script_adapter_fetcher_win_unittest.cc24
-rw-r--r--net/proxy/dhcp_proxy_script_fetcher_win.cc78
-rw-r--r--net/proxy/dhcp_proxy_script_fetcher_win.h62
-rw-r--r--net/proxy/dhcp_proxy_script_fetcher_win_unittest.cc56
6 files changed, 134 insertions, 216 deletions
diff --git a/net/proxy/dhcp_proxy_script_adapter_fetcher_win.cc b/net/proxy/dhcp_proxy_script_adapter_fetcher_win.cc
index eae0ba4..32baeb7 100644
--- a/net/proxy/dhcp_proxy_script_adapter_fetcher_win.cc
+++ b/net/proxy/dhcp_proxy_script_adapter_fetcher_win.cc
@@ -4,10 +4,10 @@
#include "net/proxy/dhcp_proxy_script_adapter_fetcher_win.h"
+#include "base/bind.h"
#include "base/message_loop_proxy.h"
#include "base/metrics/histogram.h"
#include "base/sys_string_conversions.h"
-#include "base/task.h"
#include "base/threading/worker_pool.h"
#include "base/time.h"
#include "net/base/net_errors.h"
@@ -60,8 +60,18 @@ void DhcpProxyScriptAdapterFetcher::Fetch(
wait_timer_.Start(FROM_HERE, ImplGetTimeout(),
this, &DhcpProxyScriptAdapterFetcher::OnTimeout);
- worker_thread_ = ImplCreateWorkerThread(AsWeakPtr());
- worker_thread_->Start(adapter_name);
+ scoped_refptr<DhcpQuery> dhcp_query(ImplCreateDhcpQuery());
+ base::WorkerPool::PostTaskAndReply(
+ FROM_HERE,
+ base::Bind(
+ &DhcpProxyScriptAdapterFetcher::DhcpQuery::GetPacURLForAdapter,
+ dhcp_query.get(),
+ adapter_name),
+ base::Bind(
+ &DhcpProxyScriptAdapterFetcher::OnDhcpQueryDone,
+ AsWeakPtr(),
+ dhcp_query),
+ true);
}
void DhcpProxyScriptAdapterFetcher::Cancel() {
@@ -109,55 +119,29 @@ GURL DhcpProxyScriptAdapterFetcher::GetPacURL() const {
return pac_url_;
}
-DhcpProxyScriptAdapterFetcher::WorkerThread::WorkerThread(
- const base::WeakPtr<DhcpProxyScriptAdapterFetcher>& owner)
- : owner_(owner),
- origin_loop_(base::MessageLoopProxy::current()) {
+DhcpProxyScriptAdapterFetcher::DhcpQuery::DhcpQuery() {
}
-DhcpProxyScriptAdapterFetcher::WorkerThread::~WorkerThread() {
+DhcpProxyScriptAdapterFetcher::DhcpQuery::~DhcpQuery() {
}
-void DhcpProxyScriptAdapterFetcher::WorkerThread::Start(
+void DhcpProxyScriptAdapterFetcher::DhcpQuery::GetPacURLForAdapter(
const std::string& adapter_name) {
- bool succeeded = base::WorkerPool::PostTask(
- FROM_HERE,
- NewRunnableMethod(
- this,
- &DhcpProxyScriptAdapterFetcher::WorkerThread::ThreadFunc,
- adapter_name),
- true);
- DCHECK(succeeded);
-}
-
-void DhcpProxyScriptAdapterFetcher::WorkerThread::ThreadFunc(
- const std::string& adapter_name) {
- std::string url = ImplGetPacURLFromDhcp(adapter_name);
-
- bool succeeded = origin_loop_->PostTask(
- FROM_HERE,
- NewRunnableMethod(
- this,
- &DhcpProxyScriptAdapterFetcher::WorkerThread::OnThreadDone,
- url));
- DCHECK(succeeded);
+ url_ = ImplGetPacURLFromDhcp(adapter_name);
}
-void DhcpProxyScriptAdapterFetcher::WorkerThread::OnThreadDone(
- const std::string& url) {
- DCHECK(thread_checker_.CalledOnValidThread());
- if (owner_)
- owner_->OnQueryDhcpDone(url);
+const std::string& DhcpProxyScriptAdapterFetcher::DhcpQuery::url() const {
+ return url_;
}
std::string
- DhcpProxyScriptAdapterFetcher::WorkerThread::ImplGetPacURLFromDhcp(
+ DhcpProxyScriptAdapterFetcher::DhcpQuery::ImplGetPacURLFromDhcp(
const std::string& adapter_name) {
return DhcpProxyScriptAdapterFetcher::GetPacURLFromDhcp(adapter_name);
}
-void DhcpProxyScriptAdapterFetcher::OnQueryDhcpDone(
- const std::string& url) {
+void DhcpProxyScriptAdapterFetcher::OnDhcpQueryDone(
+ scoped_refptr<DhcpQuery> dhcp_query) {
DCHECK(CalledOnValidThread());
// Because we can't cancel the call to the Win32 API, we can expect
// it to finish while we are in a few different states. The expected
@@ -170,7 +154,7 @@ void DhcpProxyScriptAdapterFetcher::OnQueryDhcpDone(
wait_timer_.Stop();
- pac_url_ = GURL(url);
+ pac_url_ = GURL(dhcp_query->url());
if (pac_url_.is_empty() || !pac_url_.is_valid()) {
result_ = ERR_PAC_NOT_IN_DHCP;
TransitionToFinish();
@@ -219,10 +203,9 @@ ProxyScriptFetcher* DhcpProxyScriptAdapterFetcher::ImplCreateScriptFetcher() {
return new ProxyScriptFetcherImpl(url_request_context_);
}
-DhcpProxyScriptAdapterFetcher::WorkerThread*
- DhcpProxyScriptAdapterFetcher::ImplCreateWorkerThread(
- const base::WeakPtr<DhcpProxyScriptAdapterFetcher>& owner) {
- return new WorkerThread(owner);
+DhcpProxyScriptAdapterFetcher::DhcpQuery*
+ DhcpProxyScriptAdapterFetcher::ImplCreateDhcpQuery() {
+ return new DhcpQuery();
}
base::TimeDelta DhcpProxyScriptAdapterFetcher::ImplGetTimeout() const {
diff --git a/net/proxy/dhcp_proxy_script_adapter_fetcher_win.h b/net/proxy/dhcp_proxy_script_adapter_fetcher_win.h
index a8fc43c..ffbe9c0 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.
+ const std::string& url() const;
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_;
diff --git a/net/proxy/dhcp_proxy_script_adapter_fetcher_win_unittest.cc b/net/proxy/dhcp_proxy_script_adapter_fetcher_win_unittest.cc
index b46bbad..57f02f5 100644
--- a/net/proxy/dhcp_proxy_script_adapter_fetcher_win_unittest.cc
+++ b/net/proxy/dhcp_proxy_script_adapter_fetcher_win_unittest.cc
@@ -60,11 +60,10 @@ class MockDhcpProxyScriptAdapterFetcher
return fetcher_;
}
- class DelayingWorkerThread : public WorkerThread {
+ class DelayingDhcpQuery : public DhcpQuery {
public:
- explicit DelayingWorkerThread(
- const base::WeakPtr<DhcpProxyScriptAdapterFetcher>& owner)
- : WorkerThread(owner),
+ explicit DelayingDhcpQuery()
+ : DhcpQuery(),
test_finished_event_(true, false) {
}
@@ -80,12 +79,11 @@ class MockDhcpProxyScriptAdapterFetcher
std::string configured_url_;
};
- virtual WorkerThread* ImplCreateWorkerThread(
- const base::WeakPtr<DhcpProxyScriptAdapterFetcher>& owner) OVERRIDE {
- worker_thread_ = new DelayingWorkerThread(owner);
- worker_thread_->dhcp_delay_ = TimeDelta::FromMilliseconds(dhcp_delay_ms_);
- worker_thread_->configured_url_ = configured_url_;
- return worker_thread_;
+ virtual DhcpQuery* ImplCreateDhcpQuery() OVERRIDE {
+ dhcp_query_ = new DelayingDhcpQuery();
+ dhcp_query_->dhcp_delay_ = TimeDelta::FromMilliseconds(dhcp_delay_ms_);
+ dhcp_query_->configured_url_ = configured_url_;
+ return dhcp_query_;
}
// Use a shorter timeout so tests can finish more quickly.
@@ -115,8 +113,8 @@ class MockDhcpProxyScriptAdapterFetcher
}
void FinishTest() {
- DCHECK(worker_thread_);
- worker_thread_->test_finished_event_.Signal();
+ DCHECK(dhcp_query_);
+ dhcp_query_->test_finished_event_.Signal();
}
int dhcp_delay_ms_;
@@ -127,7 +125,7 @@ class MockDhcpProxyScriptAdapterFetcher
std::string pac_script_;
MockProxyScriptFetcher* fetcher_;
base::OneShotTimer<MockDhcpProxyScriptAdapterFetcher> fetcher_timer_;
- scoped_refptr<DelayingWorkerThread> worker_thread_;
+ scoped_refptr<DelayingDhcpQuery> dhcp_query_;
};
class FetcherClient {
diff --git a/net/proxy/dhcp_proxy_script_fetcher_win.cc b/net/proxy/dhcp_proxy_script_fetcher_win.cc
index dced471..9ec7113 100644
--- a/net/proxy/dhcp_proxy_script_fetcher_win.cc
+++ b/net/proxy/dhcp_proxy_script_fetcher_win.cc
@@ -4,6 +4,7 @@
#include "net/proxy/dhcp_proxy_script_fetcher_win.h"
+#include "base/bind.h"
#include "base/metrics/histogram.h"
#include "base/perftimer.h"
#include "base/threading/worker_pool.h"
@@ -67,8 +68,17 @@ int DhcpProxyScriptFetcherWin::Fetch(string16* utf16_text,
client_callback_ = callback;
destination_string_ = utf16_text;
- worker_thread_ = ImplCreateWorkerThread(AsWeakPtr());
- worker_thread_->Start();
+ last_query_ = ImplCreateAdapterQuery();
+ base::WorkerPool::PostTaskAndReply(
+ FROM_HERE,
+ base::Bind(
+ &DhcpProxyScriptFetcherWin::AdapterQuery::GetCandidateAdapterNames,
+ last_query_.get()),
+ base::Bind(
+ &DhcpProxyScriptFetcherWin::OnGetCandidateAdapterNamesDone,
+ AsWeakPtr(),
+ last_query_),
+ true);
return ERR_IO_PENDING;
}
@@ -105,15 +115,27 @@ void DhcpProxyScriptFetcherWin::CancelImpl() {
}
void DhcpProxyScriptFetcherWin::OnGetCandidateAdapterNamesDone(
- const std::set<std::string>& adapter_names) {
+ scoped_refptr<AdapterQuery> query) {
DCHECK(CalledOnValidThread());
+ // This can happen if this object is reused for multiple queries,
+ // and a previous query was cancelled before it completed.
+ if (query.get() != last_query_.get())
+ return;
+ last_query_ = NULL;
+
+ // Enable unit tests to wait for this to happen; in production this function
+ // call is a no-op.
+ ImplOnGetCandidateAdapterNamesDone();
+
// We may have been cancelled.
if (state_ != STATE_WAIT_ADAPTERS)
return;
state_ = STATE_NO_RESULTS;
+ const std::set<std::string>& adapter_names = query->adapter_names();
+
if (adapter_names.empty()) {
TransitionToDone();
return;
@@ -254,10 +276,9 @@ DhcpProxyScriptAdapterFetcher*
return new DhcpProxyScriptAdapterFetcher(url_request_context_);
}
-DhcpProxyScriptFetcherWin::WorkerThread*
- DhcpProxyScriptFetcherWin::ImplCreateWorkerThread(
- const base::WeakPtr<DhcpProxyScriptFetcherWin>& owner) {
- return new WorkerThread(owner);
+DhcpProxyScriptFetcherWin::AdapterQuery*
+ DhcpProxyScriptFetcherWin::ImplCreateAdapterQuery() {
+ return new AdapterQuery();
}
int DhcpProxyScriptFetcherWin::ImplGetMaxWaitMs() {
@@ -330,51 +351,22 @@ bool DhcpProxyScriptFetcherWin::GetCandidateAdapterNames(
return true;
}
-DhcpProxyScriptFetcherWin::WorkerThread::WorkerThread(
- const base::WeakPtr<DhcpProxyScriptFetcherWin>& owner) {
- Init(owner);
-}
-
-DhcpProxyScriptFetcherWin::WorkerThread::~WorkerThread() {
+DhcpProxyScriptFetcherWin::AdapterQuery::AdapterQuery() {
}
-void DhcpProxyScriptFetcherWin::WorkerThread::Start() {
- bool succeeded = base::WorkerPool::PostTask(
- FROM_HERE,
- NewRunnableMethod(
- this,
- &DhcpProxyScriptFetcherWin::WorkerThread::ThreadFunc),
- true);
- DCHECK(succeeded);
+DhcpProxyScriptFetcherWin::AdapterQuery::~AdapterQuery() {
}
-void DhcpProxyScriptFetcherWin::WorkerThread::ThreadFunc() {
+void DhcpProxyScriptFetcherWin::AdapterQuery::GetCandidateAdapterNames() {
ImplGetCandidateAdapterNames(&adapter_names_);
-
- bool succeeded = origin_loop_->PostTask(
- FROM_HERE,
- NewRunnableMethod(
- this,
- &DhcpProxyScriptFetcherWin::WorkerThread::OnThreadDone));
- DCHECK(succeeded);
-}
-
-void DhcpProxyScriptFetcherWin::WorkerThread::OnThreadDone() {
- DCHECK(thread_checker_.CalledOnValidThread());
- if (owner_)
- owner_->OnGetCandidateAdapterNamesDone(adapter_names_);
-}
-
-DhcpProxyScriptFetcherWin::WorkerThread::WorkerThread() {
}
-void DhcpProxyScriptFetcherWin::WorkerThread::Init(
- const base::WeakPtr<DhcpProxyScriptFetcherWin>& owner) {
- owner_ = owner;
- origin_loop_ = base::MessageLoopProxy::current();
+const std::set<std::string>&
+ DhcpProxyScriptFetcherWin::AdapterQuery::adapter_names() const {
+ return adapter_names_;
}
-bool DhcpProxyScriptFetcherWin::WorkerThread::ImplGetCandidateAdapterNames(
+bool DhcpProxyScriptFetcherWin::AdapterQuery::ImplGetCandidateAdapterNames(
std::set<std::string>* adapter_names) {
return DhcpProxyScriptFetcherWin::GetCandidateAdapterNames(adapter_names);
}
diff --git a/net/proxy/dhcp_proxy_script_fetcher_win.h b/net/proxy/dhcp_proxy_script_fetcher_win.h
index ea14eff..0d7dc3e 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_;
diff --git a/net/proxy/dhcp_proxy_script_fetcher_win_unittest.cc b/net/proxy/dhcp_proxy_script_fetcher_win_unittest.cc
index 8f17456..9c2dc24 100644
--- a/net/proxy/dhcp_proxy_script_fetcher_win_unittest.cc
+++ b/net/proxy/dhcp_proxy_script_fetcher_win_unittest.cc
@@ -160,23 +160,21 @@ class DelayingDhcpProxyScriptAdapterFetcher
: DhcpProxyScriptAdapterFetcher(url_request_context) {
}
- class DelayingWorkerThread : public WorkerThread {
+ class DelayingDhcpQuery : public DhcpQuery {
public:
- explicit DelayingWorkerThread(
- const base::WeakPtr<DhcpProxyScriptAdapterFetcher>& owner)
- : WorkerThread(owner) {
+ explicit DelayingDhcpQuery()
+ : DhcpQuery() {
}
std::string ImplGetPacURLFromDhcp(
const std::string& adapter_name) OVERRIDE {
base::PlatformThread::Sleep(20);
- return WorkerThread::ImplGetPacURLFromDhcp(adapter_name);
+ return DhcpQuery::ImplGetPacURLFromDhcp(adapter_name);
}
};
- WorkerThread* ImplCreateWorkerThread(
- const base::WeakPtr<DhcpProxyScriptAdapterFetcher>& owner) OVERRIDE {
- return new DelayingWorkerThread(owner);
+ DhcpQuery* ImplCreateDhcpQuery() OVERRIDE {
+ return new DelayingDhcpQuery();
}
};
@@ -268,16 +266,12 @@ class DummyDhcpProxyScriptAdapterFetcher
class MockDhcpProxyScriptFetcherWin : public DhcpProxyScriptFetcherWin {
public:
- class MockWorkerThread : public WorkerThread {
+ class MockAdapterQuery : public AdapterQuery {
public:
- MockWorkerThread() : worker_finished_event_(true, false) {
+ MockAdapterQuery() {
}
- virtual ~MockWorkerThread() {
- }
-
- void Init(const base::WeakPtr<DhcpProxyScriptFetcherWin>& owner) {
- WorkerThread::Init(owner);
+ virtual ~MockAdapterQuery() {
}
virtual bool ImplGetCandidateAdapterNames(
@@ -287,18 +281,13 @@ class MockDhcpProxyScriptFetcherWin : public DhcpProxyScriptFetcherWin {
return true;
}
- virtual void OnThreadDone() OVERRIDE {
- WorkerThread::OnThreadDone();
- worker_finished_event_.Signal();
- }
-
std::vector<std::string> mock_adapter_names_;
- base::WaitableEvent worker_finished_event_;
};
MockDhcpProxyScriptFetcherWin()
: DhcpProxyScriptFetcherWin(new TestURLRequestContext()),
- num_fetchers_created_(0) {
+ num_fetchers_created_(0),
+ worker_finished_event_(true, false) {
ResetTestState();
}
@@ -311,7 +300,7 @@ class MockDhcpProxyScriptFetcherWin : public DhcpProxyScriptFetcherWin {
// returned by ImplGetCandidateAdapterNames.
void PushBackAdapter(const std::string& adapter_name,
DhcpProxyScriptAdapterFetcher* fetcher) {
- worker_thread_->mock_adapter_names_.push_back(adapter_name);
+ adapter_query_->mock_adapter_names_.push_back(adapter_name);
adapter_fetchers_.push_back(fetcher);
}
@@ -331,17 +320,19 @@ class MockDhcpProxyScriptFetcherWin : public DhcpProxyScriptFetcherWin {
return adapter_fetchers_[next_adapter_fetcher_index_++];
}
- virtual WorkerThread* ImplCreateWorkerThread(
- const base::WeakPtr<DhcpProxyScriptFetcherWin>& owner) OVERRIDE {
- DCHECK(worker_thread_);
- worker_thread_->Init(owner);
- return worker_thread_.get();
+ virtual AdapterQuery* ImplCreateAdapterQuery() OVERRIDE {
+ DCHECK(adapter_query_);
+ return adapter_query_.get();
}
int ImplGetMaxWaitMs() OVERRIDE {
return max_wait_ms_;
}
+ void ImplOnGetCandidateAdapterNamesDone() OVERRIDE {
+ worker_finished_event_.Signal();
+ }
+
void ResetTestState() {
// Delete any adapter fetcher objects we didn't hand out.
std::vector<DhcpProxyScriptAdapterFetcher*>::const_iterator it
@@ -355,7 +346,7 @@ class MockDhcpProxyScriptFetcherWin : public DhcpProxyScriptFetcherWin {
next_adapter_fetcher_index_ = 0;
num_fetchers_created_ = 0;
adapter_fetchers_.clear();
- worker_thread_ = new MockWorkerThread();
+ adapter_query_ = new MockAdapterQuery();
max_wait_ms_ = TestTimeouts::tiny_timeout_ms();
}
@@ -370,10 +361,11 @@ class MockDhcpProxyScriptFetcherWin : public DhcpProxyScriptFetcherWin {
// deleted on destruction.
std::vector<DhcpProxyScriptAdapterFetcher*> adapter_fetchers_;
- scoped_refptr<MockWorkerThread> worker_thread_;
+ scoped_refptr<MockAdapterQuery> adapter_query_;
int max_wait_ms_;
int num_fetchers_created_;
+ base::WaitableEvent worker_finished_event_;
};
class FetcherClient {
@@ -398,8 +390,8 @@ public:
}
void RunMessageLoopUntilWorkerDone() {
- DCHECK(fetcher_.worker_thread_.get());
- while (!fetcher_.worker_thread_->worker_finished_event_.TimedWait(
+ DCHECK(fetcher_.adapter_query_.get());
+ while (!fetcher_.worker_finished_event_.TimedWait(
base::TimeDelta::FromMilliseconds(10))) {
MessageLoop::current()->RunAllPending();
}