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

Side by Side Diff: content/browser/geolocation/device_data_provider.h

Issue 14335017: content: Use base::MessageLoop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 7 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
OLDNEW
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 // 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 85
86 // See class DeviceDataProvider for the public client API. 86 // See class DeviceDataProvider for the public client API.
87 // DeviceDataProvider uses containment to hide platform-specific implementation 87 // DeviceDataProvider uses containment to hide platform-specific implementation
88 // details from common code. This class provides common functionality for these 88 // details from common code. This class provides common functionality for these
89 // contained implementation classes. This is a modified pimpl pattern: this 89 // contained implementation classes. This is a modified pimpl pattern: this
90 // class needs to be in the public header due to use of templating. 90 // class needs to be in the public header due to use of templating.
91 template<typename DataType> 91 template<typename DataType>
92 class DeviceDataProviderImplBase : public DeviceDataProviderImplBaseHack { 92 class DeviceDataProviderImplBase : public DeviceDataProviderImplBaseHack {
93 public: 93 public:
94 DeviceDataProviderImplBase() 94 DeviceDataProviderImplBase()
95 : container_(NULL), client_loop_(MessageLoop::current()) { 95 : container_(NULL), client_loop_(base::MessageLoop::current()) {
96 DCHECK(client_loop_); 96 DCHECK(client_loop_);
97 } 97 }
98 98
99 virtual bool StartDataProvider() = 0; 99 virtual bool StartDataProvider() = 0;
100 virtual void StopDataProvider() = 0; 100 virtual void StopDataProvider() = 0;
101 virtual bool GetData(DataType* data) = 0; 101 virtual bool GetData(DataType* data) = 0;
102 102
103 // Sets the container of this class, which is of type DeviceDataProvider. 103 // Sets the container of this class, which is of type DeviceDataProvider.
104 // This is required to pass as a parameter when making the callback to 104 // This is required to pass as a parameter when making the callback to
105 // listeners. 105 // listeners.
(...skipping 25 matching lines...) Expand all
131 typedef std::set<ListenerInterface*> ListenersSet; 131 typedef std::set<ListenerInterface*> ListenersSet;
132 void NotifyListeners() { 132 void NotifyListeners() {
133 // Always make the notify callback via a posted task, so we can unwind 133 // Always make the notify callback via a posted task, so we can unwind
134 // callstack here and make callback without causing client re-entrancy. 134 // callstack here and make callback without causing client re-entrancy.
135 client_loop_->PostTask(FROM_HERE, base::Bind( 135 client_loop_->PostTask(FROM_HERE, base::Bind(
136 &DeviceDataProviderImplBase<DataType>::NotifyListenersInClientLoop, 136 &DeviceDataProviderImplBase<DataType>::NotifyListenersInClientLoop,
137 this)); 137 this));
138 } 138 }
139 139
140 bool CalledOnClientThread() const { 140 bool CalledOnClientThread() const {
141 return MessageLoop::current() == this->client_loop_; 141 return base::MessageLoop::current() == this->client_loop_;
142 } 142 }
143 143
144 MessageLoop* client_loop() const { 144 base::MessageLoop* client_loop() const { return client_loop_; }
145 return client_loop_;
146 }
147 145
148 private: 146 private:
149 void NotifyListenersInClientLoop() { 147 void NotifyListenersInClientLoop() {
150 DCHECK(CalledOnClientThread()); 148 DCHECK(CalledOnClientThread());
151 // It's possible that all the listeners (and the container) went away 149 // It's possible that all the listeners (and the container) went away
152 // whilst this task was pending. This is fine; the loop will be a no-op. 150 // whilst this task was pending. This is fine; the loop will be a no-op.
153 typename ListenersSet::const_iterator iter = listeners_.begin(); 151 typename ListenersSet::const_iterator iter = listeners_.begin();
154 while (iter != listeners_.end()) { 152 while (iter != listeners_.end()) {
155 ListenerInterface* listener = *iter; 153 ListenerInterface* listener = *iter;
156 ++iter; // Advance iter before callback, in case listener unregisters. 154 ++iter; // Advance iter before callback, in case listener unregisters.
157 listener->DeviceDataUpdateAvailable(container_); 155 listener->DeviceDataUpdateAvailable(container_);
158 } 156 }
159 } 157 }
160 158
161 DeviceDataProvider<DataType>* container_; 159 DeviceDataProvider<DataType>* container_;
162 160
163 // Reference to the client's message loop, all callbacks and access to 161 // Reference to the client's message loop, all callbacks and access to
164 // the listeners_ member should happen in this context. 162 // the listeners_ member should happen in this context.
165 MessageLoop* client_loop_; 163 base::MessageLoop* client_loop_;
166 164
167 ListenersSet listeners_; 165 ListenersSet listeners_;
168 166
169 DISALLOW_COPY_AND_ASSIGN(DeviceDataProviderImplBase); 167 DISALLOW_COPY_AND_ASSIGN(DeviceDataProviderImplBase);
170 }; 168 };
171 169
172 typedef DeviceDataProviderImplBase<WifiData> WifiDataProviderImplBase; 170 typedef DeviceDataProviderImplBase<WifiData> WifiDataProviderImplBase;
173 171
174 // A device data provider 172 // A device data provider
175 // 173 //
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 scoped_refptr<DeviceDataProviderImplBase<DataType> > impl_; 296 scoped_refptr<DeviceDataProviderImplBase<DataType> > impl_;
299 297
300 DISALLOW_COPY_AND_ASSIGN(DeviceDataProvider); 298 DISALLOW_COPY_AND_ASSIGN(DeviceDataProvider);
301 }; 299 };
302 300
303 typedef DeviceDataProvider<WifiData> WifiDataProvider; 301 typedef DeviceDataProvider<WifiData> WifiDataProvider;
304 302
305 } // namespace content 303 } // namespace content
306 304
307 #endif // CONTENT_BROWSER_GEOLOCATION_DEVICE_DATA_PROVIDER_H_ 305 #endif // CONTENT_BROWSER_GEOLOCATION_DEVICE_DATA_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698