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/polling_proxy_config_service.h" | 5 #include "net/proxy/polling_proxy_config_service.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 PollOnWorkerThread(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_loop_proxy_) { | 108 if (origin_loop_proxy_.get()) { |
109 origin_loop_proxy_->PostTask( | 109 origin_loop_proxy_->PostTask( |
110 FROM_HERE, | 110 FROM_HERE, base::Bind(&Core::GetConfigCompleted, this, config)); |
111 base::Bind(&Core::GetConfigCompleted, this, config)); | |
112 } | 111 } |
113 } | 112 } |
114 | 113 |
115 // Called after the worker thread has finished retrieving a configuration. | 114 // Called after the worker thread has finished retrieving a configuration. |
116 void GetConfigCompleted(const ProxyConfig& config) { | 115 void GetConfigCompleted(const ProxyConfig& config) { |
117 DCHECK(poll_task_outstanding_); | 116 DCHECK(poll_task_outstanding_); |
118 poll_task_outstanding_ = false; | 117 poll_task_outstanding_ = false; |
119 | 118 |
120 if (!origin_loop_proxy_) | 119 if (!origin_loop_proxy_.get()) |
121 return; // Was orphaned (parent has already been destroyed). | 120 return; // Was orphaned (parent has already been destroyed). |
122 | 121 |
123 DCHECK(origin_loop_proxy_->BelongsToCurrentThread()); | 122 DCHECK(origin_loop_proxy_->BelongsToCurrentThread()); |
124 | 123 |
125 if (!has_config_ || !last_config_.Equals(config)) { | 124 if (!has_config_ || !last_config_.Equals(config)) { |
126 // If the configuration has changed, notify the observers. | 125 // If the configuration has changed, notify the observers. |
127 has_config_ = true; | 126 has_config_ = true; |
128 last_config_ = config; | 127 last_config_ = config; |
129 FOR_EACH_OBSERVER(Observer, observers_, | 128 FOR_EACH_OBSERVER(Observer, observers_, |
130 OnProxyConfigChanged(config, | 129 OnProxyConfigChanged(config, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 | 185 |
187 PollingProxyConfigService::~PollingProxyConfigService() { | 186 PollingProxyConfigService::~PollingProxyConfigService() { |
188 core_->Orphan(); | 187 core_->Orphan(); |
189 } | 188 } |
190 | 189 |
191 void PollingProxyConfigService::CheckForChangesNow() { | 190 void PollingProxyConfigService::CheckForChangesNow() { |
192 core_->CheckForChangesNow(); | 191 core_->CheckForChangesNow(); |
193 } | 192 } |
194 | 193 |
195 } // namespace net | 194 } // namespace net |
OLD | NEW |