OLD | NEW |
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/proxy_config_service_mac.h" | 5 #include "net/proxy/proxy_config_service_mac.h" |
6 | 6 |
7 #include <CoreFoundation/CoreFoundation.h> | 7 #include <CoreFoundation/CoreFoundation.h> |
8 #include <SystemConfiguration/SystemConfiguration.h> | 8 #include <SystemConfiguration/SystemConfiguration.h> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 SCDynamicStoreRef store) { | 191 SCDynamicStoreRef store) { |
192 proxy_config_service_->SetDynamicStoreNotificationKeys(store); | 192 proxy_config_service_->SetDynamicStoreNotificationKeys(store); |
193 } | 193 } |
194 | 194 |
195 void ProxyConfigServiceMac::Forwarder::OnNetworkConfigChange( | 195 void ProxyConfigServiceMac::Forwarder::OnNetworkConfigChange( |
196 CFArrayRef changed_keys) { | 196 CFArrayRef changed_keys) { |
197 proxy_config_service_->OnNetworkConfigChange(changed_keys); | 197 proxy_config_service_->OnNetworkConfigChange(changed_keys); |
198 } | 198 } |
199 | 199 |
200 ProxyConfigServiceMac::ProxyConfigServiceMac( | 200 ProxyConfigServiceMac::ProxyConfigServiceMac( |
201 const scoped_refptr<base::SingleThreadTaskRunner>& io_thread_task_runner) | 201 const scoped_refptr<base::SequencedTaskRunner>& io_thread_task_runner) |
202 : forwarder_(this), | 202 : forwarder_(this), |
203 has_fetched_config_(false), | 203 has_fetched_config_(false), |
204 helper_(new Helper(this)), | 204 helper_(new Helper(this)), |
205 io_thread_task_runner_(io_thread_task_runner) { | 205 io_thread_task_runner_(io_thread_task_runner) { |
206 DCHECK(io_thread_task_runner_.get()); | 206 DCHECK(io_thread_task_runner_.get()); |
207 config_watcher_.reset(new NetworkConfigWatcherMac(&forwarder_)); | 207 config_watcher_.reset(new NetworkConfigWatcherMac(&forwarder_)); |
208 } | 208 } |
209 | 209 |
210 ProxyConfigServiceMac::~ProxyConfigServiceMac() { | 210 ProxyConfigServiceMac::~ProxyConfigServiceMac() { |
211 DCHECK(io_thread_task_runner_->BelongsToCurrentThread()); | 211 DCHECK(io_thread_task_runner_->RunsTasksInCurrentSequence()); |
212 // Delete the config_watcher_ to ensure the notifier thread finishes before | 212 // Delete the config_watcher_ to ensure the notifier thread finishes before |
213 // this object is destroyed. | 213 // this object is destroyed. |
214 config_watcher_.reset(); | 214 config_watcher_.reset(); |
215 helper_->Orphan(); | 215 helper_->Orphan(); |
216 } | 216 } |
217 | 217 |
218 void ProxyConfigServiceMac::AddObserver(Observer* observer) { | 218 void ProxyConfigServiceMac::AddObserver(Observer* observer) { |
219 DCHECK(io_thread_task_runner_->BelongsToCurrentThread()); | 219 DCHECK(io_thread_task_runner_->RunsTasksInCurrentSequence()); |
220 observers_.AddObserver(observer); | 220 observers_.AddObserver(observer); |
221 } | 221 } |
222 | 222 |
223 void ProxyConfigServiceMac::RemoveObserver(Observer* observer) { | 223 void ProxyConfigServiceMac::RemoveObserver(Observer* observer) { |
224 DCHECK(io_thread_task_runner_->BelongsToCurrentThread()); | 224 DCHECK(io_thread_task_runner_->RunsTasksInCurrentSequence()); |
225 observers_.RemoveObserver(observer); | 225 observers_.RemoveObserver(observer); |
226 } | 226 } |
227 | 227 |
228 ProxyConfigService::ConfigAvailability | 228 ProxyConfigService::ConfigAvailability |
229 ProxyConfigServiceMac::GetLatestProxyConfig(ProxyConfig* config) { | 229 ProxyConfigServiceMac::GetLatestProxyConfig(ProxyConfig* config) { |
230 DCHECK(io_thread_task_runner_->BelongsToCurrentThread()); | 230 DCHECK(io_thread_task_runner_->RunsTasksInCurrentSequence()); |
231 | 231 |
232 // Lazy-initialize by fetching the proxy setting from this thread. | 232 // Lazy-initialize by fetching the proxy setting from this thread. |
233 if (!has_fetched_config_) { | 233 if (!has_fetched_config_) { |
234 GetCurrentProxyConfig(&last_config_fetched_); | 234 GetCurrentProxyConfig(&last_config_fetched_); |
235 has_fetched_config_ = true; | 235 has_fetched_config_ = true; |
236 } | 236 } |
237 | 237 |
238 *config = last_config_fetched_; | 238 *config = last_config_fetched_; |
239 return has_fetched_config_ ? CONFIG_VALID : CONFIG_PENDING; | 239 return has_fetched_config_ ? CONFIG_VALID : CONFIG_PENDING; |
240 } | 240 } |
(...skipping 22 matching lines...) Expand all Loading... |
263 GetCurrentProxyConfig(&new_config); | 263 GetCurrentProxyConfig(&new_config); |
264 | 264 |
265 // Call OnProxyConfigChanged() on the IO thread to notify our observers. | 265 // Call OnProxyConfigChanged() on the IO thread to notify our observers. |
266 io_thread_task_runner_->PostTask( | 266 io_thread_task_runner_->PostTask( |
267 FROM_HERE, | 267 FROM_HERE, |
268 base::Bind(&Helper::OnProxyConfigChanged, helper_.get(), new_config)); | 268 base::Bind(&Helper::OnProxyConfigChanged, helper_.get(), new_config)); |
269 } | 269 } |
270 | 270 |
271 void ProxyConfigServiceMac::OnProxyConfigChanged( | 271 void ProxyConfigServiceMac::OnProxyConfigChanged( |
272 const ProxyConfig& new_config) { | 272 const ProxyConfig& new_config) { |
273 DCHECK(io_thread_task_runner_->BelongsToCurrentThread()); | 273 DCHECK(io_thread_task_runner_->RunsTasksInCurrentSequence()); |
274 | 274 |
275 // Keep track of the last value we have seen. | 275 // Keep track of the last value we have seen. |
276 has_fetched_config_ = true; | 276 has_fetched_config_ = true; |
277 last_config_fetched_ = new_config; | 277 last_config_fetched_ = new_config; |
278 | 278 |
279 // Notify all the observers. | 279 // Notify all the observers. |
280 for (auto& observer : observers_) | 280 for (auto& observer : observers_) |
281 observer.OnProxyConfigChanged(new_config, CONFIG_VALID); | 281 observer.OnProxyConfigChanged(new_config, CONFIG_VALID); |
282 } | 282 } |
283 | 283 |
284 } // namespace net | 284 } // namespace net |
OLD | NEW |