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

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

Issue 3153031: Gateway Location Provider (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Land patch Created 10 years, 4 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
« no previous file with comments | « no previous file | chrome/browser/geolocation/empty_device_data_provider.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 // 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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 // Test how many have changed. 169 // Test how many have changed.
170 return max_ap_count > num_common + difference_threadhold; 170 return max_ap_count > num_common + difference_threadhold;
171 } 171 }
172 172
173 // Store access points as a set, sorted by MAC address. This allows quick 173 // Store access points as a set, sorted by MAC address. This allows quick
174 // comparison of sets for detecting changes and for caching. 174 // comparison of sets for detecting changes and for caching.
175 typedef std::set<AccessPointData, AccessPointDataLess> AccessPointDataSet; 175 typedef std::set<AccessPointData, AccessPointDataLess> AccessPointDataSet;
176 AccessPointDataSet access_point_data; 176 AccessPointDataSet access_point_data;
177 }; 177 };
178 178
179 // Gateway data relating to a single router.
180 struct RouterData {
181 RouterData() {}
182 // MAC address, formatted as per MacAddressAsString16.
183 string16 mac_address;
184 };
185
186 // This is to allow RouterData to be used in std::set. We order
187 // lexicographically by MAC address.
188 struct RouterDataLess : public std::less<RouterData> {
189 bool operator()(const RouterData& data1,
190 const RouterData& data2) const {
191 return data1.mac_address < data2.mac_address;
192 }
193 };
194
195 // All gateway data for routers.
196 struct GatewayData {
197 // Determines whether a new set of gateway data differs significantly
198 // from this.
199 bool DiffersSignificantly(const GatewayData& other) const {
200 // Any change is significant.
201 if (this->router_data.size() != other.router_data.size())
202 return true;
203 RouterDataSet::const_iterator iter1 = router_data.begin();
204 RouterDataSet::const_iterator iter2 = other.router_data.begin();
205 while (iter1 != router_data.end()) {
206 if (iter1->mac_address != iter2->mac_address) {
207 // There is a difference between the sets of routers.
208 return true;
209 }
210 ++iter1;
211 ++iter2;
212 }
213 return false;
214 }
215
216 // Store routers as a set, sorted by MAC address. This allows quick
217 // comparison of sets for detecting changes and for caching.
218 typedef std::set<RouterData, RouterDataLess> RouterDataSet;
219 RouterDataSet router_data;
220 };
221
179 template<typename DataType> 222 template<typename DataType>
180 class DeviceDataProvider; 223 class DeviceDataProvider;
181 224
182 // This class just exists to work-around MSVC2005 not being able to have a 225 // This class just exists to work-around MSVC2005 not being able to have a
183 // template class implement RefCountedThreadSafe 226 // template class implement RefCountedThreadSafe
184 class DeviceDataProviderImplBaseHack 227 class DeviceDataProviderImplBaseHack
185 : public base::RefCountedThreadSafe<DeviceDataProviderImplBaseHack> { 228 : public base::RefCountedThreadSafe<DeviceDataProviderImplBaseHack> {
186 protected: 229 protected:
187 friend class base::RefCountedThreadSafe<DeviceDataProviderImplBaseHack>; 230 friend class base::RefCountedThreadSafe<DeviceDataProviderImplBaseHack>;
188 virtual ~DeviceDataProviderImplBaseHack() {} 231 virtual ~DeviceDataProviderImplBaseHack() {}
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 307
265 // Reference to the client's message loop, all callbacks and access to 308 // Reference to the client's message loop, all callbacks and access to
266 // the listeners_ member should happen in this context. 309 // the listeners_ member should happen in this context.
267 MessageLoop* client_loop_; 310 MessageLoop* client_loop_;
268 311
269 ListenersSet listeners_; 312 ListenersSet listeners_;
270 313
271 DISALLOW_COPY_AND_ASSIGN(DeviceDataProviderImplBase); 314 DISALLOW_COPY_AND_ASSIGN(DeviceDataProviderImplBase);
272 }; 315 };
273 316
317 typedef DeviceDataProviderImplBase<GatewayData> GatewayDataProviderImplBase;
274 typedef DeviceDataProviderImplBase<RadioData> RadioDataProviderImplBase; 318 typedef DeviceDataProviderImplBase<RadioData> RadioDataProviderImplBase;
275 typedef DeviceDataProviderImplBase<WifiData> WifiDataProviderImplBase; 319 typedef DeviceDataProviderImplBase<WifiData> WifiDataProviderImplBase;
276 320
277 // A device data provider 321 // A device data provider
278 // 322 //
279 // We use a singleton instance of this class which is shared by multiple network 323 // We use a singleton instance of this class which is shared by multiple network
280 // location providers. These location providers access the instance through the 324 // location providers. These location providers access the instance through the
281 // Register and Unregister methods. 325 // Register and Unregister methods.
282 template<typename DataType> 326 template<typename DataType>
283 class DeviceDataProvider : public NonThreadSafe { 327 class DeviceDataProvider : public NonThreadSafe {
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 444
401 // static 445 // static
402 template<typename DataType> 446 template<typename DataType>
403 DeviceDataProvider<DataType>* DeviceDataProvider<DataType>::instance_ = NULL; 447 DeviceDataProvider<DataType>* DeviceDataProvider<DataType>::instance_ = NULL;
404 448
405 // static 449 // static
406 template<typename DataType> 450 template<typename DataType>
407 typename DeviceDataProvider<DataType>::ImplFactoryFunction 451 typename DeviceDataProvider<DataType>::ImplFactoryFunction
408 DeviceDataProvider<DataType>::factory_function_ = DefaultFactoryFunction; 452 DeviceDataProvider<DataType>::factory_function_ = DefaultFactoryFunction;
409 453
454 typedef DeviceDataProvider<GatewayData> GatewayDataProvider;
410 typedef DeviceDataProvider<RadioData> RadioDataProvider; 455 typedef DeviceDataProvider<RadioData> RadioDataProvider;
411 typedef DeviceDataProvider<WifiData> WifiDataProvider; 456 typedef DeviceDataProvider<WifiData> WifiDataProvider;
412 457
413 #endif // CHROME_BROWSER_GEOLOCATION_DEVICE_DATA_PROVIDER_H_ 458 #endif // CHROME_BROWSER_GEOLOCATION_DEVICE_DATA_PROVIDER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/geolocation/empty_device_data_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698