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

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

Issue 6142009: Upating the app, ceee, chrome, ipc, media, and net directories to use the correct lock.h file. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Unified patch updating all references to the new base/synchronization/lock.h Created 9 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « net/ocsp/nss_ocsp.cc ('k') | net/proxy/sync_host_resolver_bridge.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
8 #include "base/message_loop_proxy.h" 7 #include "base/message_loop_proxy.h"
9 #include "base/observer_list.h" 8 #include "base/observer_list.h"
10 #include "base/scoped_ptr.h" 9 #include "base/scoped_ptr.h"
10 #include "base/synchronization/lock.h"
11 #include "base/threading/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:
22 Core(base::TimeDelta poll_interval, 22 Core(base::TimeDelta poll_interval,
23 GetConfigFunction get_config_func) 23 GetConfigFunction get_config_func)
24 : get_config_func_(get_config_func), 24 : get_config_func_(get_config_func),
25 poll_interval_(poll_interval), 25 poll_interval_(poll_interval),
26 have_initialized_origin_loop_(false), 26 have_initialized_origin_loop_(false),
27 has_config_(false), 27 has_config_(false),
28 poll_task_outstanding_(false), 28 poll_task_outstanding_(false),
29 poll_task_queued_(false) { 29 poll_task_queued_(false) {
30 } 30 }
31 31
32 // Called when the parent PollingProxyConfigService is destroyed 32 // Called when the parent PollingProxyConfigService is destroyed
33 // (observers should not be called past this point). 33 // (observers should not be called past this point).
34 void Orphan() { 34 void Orphan() {
35 AutoLock l(lock_); 35 base::AutoLock l(lock_);
36 origin_loop_proxy_ = NULL; 36 origin_loop_proxy_ = NULL;
37 } 37 }
38 38
39 bool GetLatestProxyConfig(ProxyConfig* config) { 39 bool GetLatestProxyConfig(ProxyConfig* config) {
40 LazyInitializeOriginLoop(); 40 LazyInitializeOriginLoop();
41 DCHECK(origin_loop_proxy_->BelongsToCurrentThread()); 41 DCHECK(origin_loop_proxy_->BelongsToCurrentThread());
42 42
43 OnLazyPoll(); 43 OnLazyPoll();
44 44
45 // If we have already retrieved the proxy settings (on worker thread) 45 // If we have already retrieved the proxy settings (on worker thread)
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 FROM_HERE, 92 FROM_HERE,
93 NewRunnableMethod(this, &Core::PollOnWorkerThread, get_config_func_), 93 NewRunnableMethod(this, &Core::PollOnWorkerThread, get_config_func_),
94 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 base::AutoLock l(lock_);
103 if (origin_loop_proxy_) { 103 if (origin_loop_proxy_) {
104 origin_loop_proxy_->PostTask( 104 origin_loop_proxy_->PostTask(
105 FROM_HERE, 105 FROM_HERE,
106 NewRunnableMethod(this, &Core::GetConfigCompleted, config)); 106 NewRunnableMethod(this, &Core::GetConfigCompleted, config));
107 } 107 }
108 } 108 }
109 109
110 // Called after the worker thread has finished retrieving a configuration. 110 // Called after the worker thread has finished retrieving a configuration.
111 void GetConfigCompleted(const ProxyConfig& config) { 111 void GetConfigCompleted(const ProxyConfig& config) {
112 DCHECK(poll_task_outstanding_); 112 DCHECK(poll_task_outstanding_);
(...skipping 25 matching lines...) Expand all
138 have_initialized_origin_loop_ = true; 138 have_initialized_origin_loop_ = true;
139 } 139 }
140 } 140 }
141 141
142 GetConfigFunction get_config_func_; 142 GetConfigFunction get_config_func_;
143 ObserverList<Observer> observers_; 143 ObserverList<Observer> observers_;
144 ProxyConfig last_config_; 144 ProxyConfig last_config_;
145 base::TimeTicks last_poll_time_; 145 base::TimeTicks last_poll_time_;
146 base::TimeDelta poll_interval_; 146 base::TimeDelta poll_interval_;
147 147
148 Lock lock_; 148 base::Lock lock_;
149 scoped_refptr<base::MessageLoopProxy> origin_loop_proxy_; 149 scoped_refptr<base::MessageLoopProxy> origin_loop_proxy_;
150 150
151 bool have_initialized_origin_loop_; 151 bool have_initialized_origin_loop_;
152 bool has_config_; 152 bool has_config_;
153 bool poll_task_outstanding_; 153 bool poll_task_outstanding_;
154 bool poll_task_queued_; 154 bool poll_task_queued_;
155 }; 155 };
156 156
157 PollingProxyConfigService::PollingProxyConfigService( 157 PollingProxyConfigService::PollingProxyConfigService(
158 base::TimeDelta poll_interval, 158 base::TimeDelta poll_interval,
(...skipping 19 matching lines...) Expand all
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
OLDNEW
« no previous file with comments | « net/ocsp/nss_ocsp.cc ('k') | net/proxy/sync_host_resolver_bridge.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698