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

Side by Side Diff: net/proxy/polling_proxy_config_service.cc

Issue 2679233003: Use TaskScheduler instead of WorkerPool in polling_proxy_config_service.cc. (Closed)
Patch Set: private Created 3 years, 10 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "net/proxy/polling_proxy_config_service.h" 5 #include "net/proxy/polling_proxy_config_service.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/observer_list.h" 11 #include "base/observer_list.h"
12 #include "base/single_thread_task_runner.h" 12 #include "base/single_thread_task_runner.h"
13 #include "base/synchronization/lock.h" 13 #include "base/synchronization/lock.h"
14 #include "base/task_scheduler/post_task.h"
14 #include "base/threading/thread_task_runner_handle.h" 15 #include "base/threading/thread_task_runner_handle.h"
15 #include "base/threading/worker_pool.h"
16 #include "net/proxy/proxy_config.h" 16 #include "net/proxy/proxy_config.h"
17 17
18 namespace net { 18 namespace net {
19 19
20 // Reference-counted wrapper that does all the work (needs to be 20 // Reference-counted wrapper that does all the work (needs to be
21 // reference-counted since we post tasks between threads; may outlive 21 // reference-counted since we post tasks between threads; may outlive
22 // the parent PollingProxyConfigService). 22 // the parent PollingProxyConfigService).
23 class PollingProxyConfigService::Core 23 class PollingProxyConfigService::Core
24 : public base::RefCountedThreadSafe<PollingProxyConfigService::Core> { 24 : public base::RefCountedThreadSafe<PollingProxyConfigService::Core> {
25 public: 25 public:
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 // Only allow one task to be outstanding at a time. If we get a poll 83 // Only allow one task to be outstanding at a time. If we get a poll
84 // request while we are busy, we will defer it until the current poll 84 // request while we are busy, we will defer it until the current poll
85 // completes. 85 // completes.
86 poll_task_queued_ = true; 86 poll_task_queued_ = true;
87 return; 87 return;
88 } 88 }
89 89
90 last_poll_time_ = base::TimeTicks::Now(); 90 last_poll_time_ = base::TimeTicks::Now();
91 poll_task_outstanding_ = true; 91 poll_task_outstanding_ = true;
92 poll_task_queued_ = false; 92 poll_task_queued_ = false;
93 base::WorkerPool::PostTask( 93 base::PostTaskWithTraits(
94 FROM_HERE, 94 FROM_HERE, base::TaskTraits().MayBlock().WithShutdownBehavior(
95 base::Bind(&Core::PollOnWorkerThread, this, get_config_func_), 95 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN),
96 true); 96 base::Bind(&Core::PollAsync, this, get_config_func_));
97 } 97 }
98 98
99 private: 99 private:
100 friend class base::RefCountedThreadSafe<Core>; 100 friend class base::RefCountedThreadSafe<Core>;
101 ~Core() {} 101 ~Core() {}
102 102
103 void PollOnWorkerThread(GetConfigFunction func) { 103 void PollAsync(GetConfigFunction func) {
104 ProxyConfig config; 104 ProxyConfig config;
105 func(&config); 105 func(&config);
106 106
107 base::AutoLock l(lock_); 107 base::AutoLock l(lock_);
108 if (origin_task_runner_.get()) { 108 if (origin_task_runner_.get()) {
109 origin_task_runner_->PostTask( 109 origin_task_runner_->PostTask(
110 FROM_HERE, base::Bind(&Core::GetConfigCompleted, this, config)); 110 FROM_HERE, base::Bind(&Core::GetConfigCompleted, this, config));
111 } 111 }
112 } 112 }
113 113
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 184
185 PollingProxyConfigService::~PollingProxyConfigService() { 185 PollingProxyConfigService::~PollingProxyConfigService() {
186 core_->Orphan(); 186 core_->Orphan();
187 } 187 }
188 188
189 void PollingProxyConfigService::CheckForChangesNow() { 189 void PollingProxyConfigService::CheckForChangesNow() {
190 core_->CheckForChangesNow(); 190 core_->CheckForChangesNow();
191 } 191 }
192 192
193 } // namespace net 193 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698