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 // A device data provider provides data from the device that is used by a | 5 // A device data provider provides data from the device that is used by a |
6 // NetworkLocationProvider to obtain a position fix. This data may be either | 6 // NetworkLocationProvider to obtain a position fix. This data may be either |
7 // cell radio data or wifi data. For a given type of data, we use a singleton | 7 // cell radio data or wifi data. For a given type of data, we use a singleton |
8 // instance of the device data provider, which is used by multiple | 8 // instance of the device data provider, which is used by multiple |
9 // NetworkLocationProvider objects. | 9 // NetworkLocationProvider objects. |
10 // | 10 // |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
173 | 173 |
174 // See class DeviceDataProvider for the public client API. | 174 // See class DeviceDataProvider for the public client API. |
175 // DeviceDataProvider uses containment to hide platform-specific implementation | 175 // DeviceDataProvider uses containment to hide platform-specific implementation |
176 // details from common code. This class provides common functionality for these | 176 // details from common code. This class provides common functionality for these |
177 // contained implementation classes. This is a modified pimpl pattern: this | 177 // contained implementation classes. This is a modified pimpl pattern: this |
178 // class needs to be in the public header due to use of templating. | 178 // class needs to be in the public header due to use of templating. |
179 template<typename DataType> | 179 template<typename DataType> |
180 class DeviceDataProviderImplBase : public DeviceDataProviderImplBaseHack { | 180 class DeviceDataProviderImplBase : public DeviceDataProviderImplBaseHack { |
181 public: | 181 public: |
182 DeviceDataProviderImplBase() | 182 DeviceDataProviderImplBase() |
183 : container_(NULL), client_loop_(MessageLoop::current()) { | 183 : client_loop_(MessageLoop::current()), container_(NULL) { |
184 DCHECK(client_loop_); | 184 DCHECK(client_loop_); |
185 } | 185 } |
186 | 186 |
187 virtual bool StartDataProvider() = 0; | 187 virtual bool StartDataProvider() = 0; |
188 virtual void StopDataProvider() = 0; | 188 virtual void StopDataProvider() = 0; |
189 virtual bool GetData(DataType* data) = 0; | 189 virtual bool GetData(DataType* data) = 0; |
190 | 190 |
191 // Sets the container of this class, which is of type DeviceDataProvider. | 191 // Sets the container of this class, which is of type DeviceDataProvider. |
192 // This is required to pass as a parameter when making the callback to | 192 // This is required to pass as a parameter when making the callback to |
193 // listeners. | 193 // listeners. |
(...skipping 29 matching lines...) Expand all Loading... | |
223 // Always make the nitofy callback via a posted task, se we can unwind | 223 // Always make the nitofy callback via a posted task, se we can unwind |
224 // callstack here and make callback without causing client re-entrancy. | 224 // callstack here and make callback without causing client re-entrancy. |
225 client_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, | 225 client_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, |
226 &DeviceDataProviderImplBase<DataType>::NotifyListenersInClientLoop)); | 226 &DeviceDataProviderImplBase<DataType>::NotifyListenersInClientLoop)); |
227 } | 227 } |
228 | 228 |
229 bool CalledOnClientThread() const { | 229 bool CalledOnClientThread() const { |
230 return MessageLoop::current() == this->client_loop_; | 230 return MessageLoop::current() == this->client_loop_; |
231 } | 231 } |
232 | 232 |
233 // Reference to the client's message loop, all callbacks and access to | |
234 // the listeners_ member should happen in this context. | |
235 MessageLoop* client_loop_; | |
stevenjb
2011/03/16 17:46:56
We shouldn't expose this publicly if we only need
John Knottenbelt
2011/03/16 18:20:14
Done.
| |
236 | |
233 private: | 237 private: |
234 void NotifyListenersInClientLoop() { | 238 void NotifyListenersInClientLoop() { |
235 DCHECK(CalledOnClientThread()); | 239 DCHECK(CalledOnClientThread()); |
236 // It's possible that all the listeners (and the container) went away | 240 // It's possible that all the listeners (and the container) went away |
237 // whilst this task was pending. This is fine; the loop will be a no-op. | 241 // whilst this task was pending. This is fine; the loop will be a no-op. |
238 typename ListenersSet::const_iterator iter = listeners_.begin(); | 242 typename ListenersSet::const_iterator iter = listeners_.begin(); |
239 while (iter != listeners_.end()) { | 243 while (iter != listeners_.end()) { |
240 ListenerInterface* listener = *iter; | 244 ListenerInterface* listener = *iter; |
241 ++iter; // Advance iter before callback, in case listener unregisters. | 245 ++iter; // Advance iter before callback, in case listener unregisters. |
242 listener->DeviceDataUpdateAvailable(container_); | 246 listener->DeviceDataUpdateAvailable(container_); |
243 } | 247 } |
244 } | 248 } |
245 | 249 |
246 DeviceDataProvider<DataType>* container_; | 250 DeviceDataProvider<DataType>* container_; |
247 | 251 |
248 // Reference to the client's message loop, all callbacks and access to | |
249 // the listeners_ member should happen in this context. | |
250 MessageLoop* client_loop_; | |
251 | |
252 ListenersSet listeners_; | 252 ListenersSet listeners_; |
253 | 253 |
254 DISALLOW_COPY_AND_ASSIGN(DeviceDataProviderImplBase); | 254 DISALLOW_COPY_AND_ASSIGN(DeviceDataProviderImplBase); |
255 }; | 255 }; |
256 | 256 |
257 typedef DeviceDataProviderImplBase<GatewayData> GatewayDataProviderImplBase; | 257 typedef DeviceDataProviderImplBase<GatewayData> GatewayDataProviderImplBase; |
258 typedef DeviceDataProviderImplBase<RadioData> RadioDataProviderImplBase; | 258 typedef DeviceDataProviderImplBase<RadioData> RadioDataProviderImplBase; |
259 typedef DeviceDataProviderImplBase<WifiData> WifiDataProviderImplBase; | 259 typedef DeviceDataProviderImplBase<WifiData> WifiDataProviderImplBase; |
260 | 260 |
261 // A device data provider | 261 // A device data provider |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
393 // static | 393 // static |
394 template<typename DataType> | 394 template<typename DataType> |
395 typename DeviceDataProvider<DataType>::ImplFactoryFunction | 395 typename DeviceDataProvider<DataType>::ImplFactoryFunction |
396 DeviceDataProvider<DataType>::factory_function_ = DefaultFactoryFunction; | 396 DeviceDataProvider<DataType>::factory_function_ = DefaultFactoryFunction; |
397 | 397 |
398 typedef DeviceDataProvider<GatewayData> GatewayDataProvider; | 398 typedef DeviceDataProvider<GatewayData> GatewayDataProvider; |
399 typedef DeviceDataProvider<RadioData> RadioDataProvider; | 399 typedef DeviceDataProvider<RadioData> RadioDataProvider; |
400 typedef DeviceDataProvider<WifiData> WifiDataProvider; | 400 typedef DeviceDataProvider<WifiData> WifiDataProvider; |
401 | 401 |
402 #endif // CONTENT_BROWSER_GEOLOCATION_DEVICE_DATA_PROVIDER_H_ | 402 #endif // CONTENT_BROWSER_GEOLOCATION_DEVICE_DATA_PROVIDER_H_ |
OLD | NEW |