OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/lock.h" | 7 #include "base/lock.h" |
8 #include "base/message_loop_proxy.h" | 8 #include "base/message_loop_proxy.h" |
9 #include "base/observer_list.h" | 9 #include "base/observer_list.h" |
10 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
11 #include "base/worker_pool.h" | 11 #include "base/threading/worker_pool.h" |
12 #include "net/proxy/proxy_config.h" | 12 #include "net/proxy/proxy_config.h" |
13 | 13 |
14 namespace net { | 14 namespace net { |
15 | 15 |
16 // Reference-counted wrapper that does all the work (needs to be | 16 // Reference-counted wrapper that does all the work (needs to be |
17 // reference-counted since we post tasks between threads; may outlive | 17 // reference-counted since we post tasks between threads; may outlive |
18 // the parent PollingProxyConfigService). | 18 // the parent PollingProxyConfigService). |
19 class PollingProxyConfigService::Core | 19 class PollingProxyConfigService::Core |
20 : public base::RefCountedThreadSafe<PollingProxyConfigService::Core> { | 20 : public base::RefCountedThreadSafe<PollingProxyConfigService::Core> { |
21 public: | 21 public: |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 // Only allow one task to be outstanding at a time. If we get a poll | 81 // Only allow one task to be outstanding at a time. If we get a poll |
82 // request while we are busy, we will defer it until the current poll | 82 // request while we are busy, we will defer it until the current poll |
83 // completes. | 83 // completes. |
84 poll_task_queued_ = true; | 84 poll_task_queued_ = true; |
85 return; | 85 return; |
86 } | 86 } |
87 | 87 |
88 last_poll_time_ = base::TimeTicks::Now(); | 88 last_poll_time_ = base::TimeTicks::Now(); |
89 poll_task_outstanding_ = true; | 89 poll_task_outstanding_ = true; |
90 poll_task_queued_ = false; | 90 poll_task_queued_ = false; |
91 WorkerPool::PostTask( | 91 base::WorkerPool::PostTask( |
92 FROM_HERE, | 92 FROM_HERE, |
93 NewRunnableMethod( | 93 NewRunnableMethod(this, &Core::PollOnWorkerThread, get_config_func_), |
94 this, &Core::PollOnWorkerThread, get_config_func_), true); | 94 true); |
95 } | 95 } |
96 | 96 |
97 private: | 97 private: |
98 void PollOnWorkerThread(GetConfigFunction func) { | 98 void PollOnWorkerThread(GetConfigFunction func) { |
99 ProxyConfig config; | 99 ProxyConfig config; |
100 func(&config); | 100 func(&config); |
101 | 101 |
102 AutoLock l(lock_); | 102 AutoLock l(lock_); |
103 if (origin_loop_proxy_) { | 103 if (origin_loop_proxy_) { |
104 origin_loop_proxy_->PostTask( | 104 origin_loop_proxy_->PostTask( |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 | 178 |
179 void PollingProxyConfigService::OnLazyPoll() { | 179 void PollingProxyConfigService::OnLazyPoll() { |
180 core_->OnLazyPoll(); | 180 core_->OnLazyPoll(); |
181 } | 181 } |
182 | 182 |
183 void PollingProxyConfigService::CheckForChangesNow() { | 183 void PollingProxyConfigService::CheckForChangesNow() { |
184 core_->CheckForChangesNow(); | 184 core_->CheckForChangesNow(); |
185 } | 185 } |
186 | 186 |
187 } // namespace net | 187 } // namespace net |
OLD | NEW |