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

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

Issue 10534120: Remove RadioData from geolocation (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: fix content_unittests Created 8 years, 6 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 | content/browser/geolocation/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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 //
11 // This file providers DeviceDataProvider, which provides static methods to 11 // This file providers DeviceDataProvider, which provides static methods to
12 // access the singleton instance. The singleton instance uses a private 12 // access the singleton instance. The singleton instance uses a private
13 // implementation to abstract across platforms and also to allow mock providers 13 // implementation to abstract across platforms and also to allow mock providers
14 // to be used for testing. 14 // to be used for testing.
15 // 15 //
16 // This file also provides DeviceDataProviderImplBase, a base class which 16 // This file also provides DeviceDataProviderImplBase, a base class which
17 // provides commom functionality for the private implementations. 17 // provides commom functionality for the private implementations.
18 // 18 //
19 // This file also declares the data structures used to represent cell radio data 19 // This file also declares the data structures used to represent cell radio data
20 // and wifi data. 20 // and wifi data.
21 21
22 #ifndef CONTENT_BROWSER_GEOLOCATION_DEVICE_DATA_PROVIDER_H_ 22 #ifndef CONTENT_BROWSER_GEOLOCATION_DEVICE_DATA_PROVIDER_H_
23 #define CONTENT_BROWSER_GEOLOCATION_DEVICE_DATA_PROVIDER_H_ 23 #define CONTENT_BROWSER_GEOLOCATION_DEVICE_DATA_PROVIDER_H_
24 #pragma once 24 #pragma once
25 25
26 #include <algorithm>
27 #include <set> 26 #include <set>
28 #include <vector>
29 27
30 #include "base/basictypes.h" 28 #include "base/basictypes.h"
31 #include "base/bind.h" 29 #include "base/bind.h"
32 #include "base/memory/ref_counted.h" 30 #include "base/memory/ref_counted.h"
33 #include "base/message_loop.h" 31 #include "base/message_loop.h"
34 #include "base/string16.h" 32 #include "base/string16.h"
35 #include "base/string_util.h" 33 #include "base/string_util.h"
36 #include "base/threading/non_thread_safe.h" 34 #include "base/threading/non_thread_safe.h"
37 #include "content/common/content_export.h" 35 #include "content/common/content_export.h"
38 36
39 // The following data structures are used to store cell radio data and wifi
40 // data. See the Geolocation API design document at
41 // http://code.google.com/p/google-gears/wiki/LocationAPI for a more complete
42 // description.
43 //
44 // For all integer fields, we use kint32min to represent unknown values.
45
46 // Cell radio data relating to a single cell tower.
47 struct CellData {
48 CellData();
49 bool Matches(const CellData &other) const {
50 // Ignore radio_signal_strength when matching.
51 return cell_id == other.cell_id &&
52 location_area_code == other.location_area_code &&
53 mobile_network_code == other.mobile_network_code &&
54 mobile_country_code == other.mobile_country_code &&
55 timing_advance == other.timing_advance;
56 }
57
58 int cell_id; // Unique identifier of the cell
59 int location_area_code; // For current location area
60 int mobile_network_code; // For current cell
61 int mobile_country_code; // For current cell
62 int radio_signal_strength; // Measured in dBm.
63 int timing_advance; // Timing advance representing the distance from
64 // the cell tower. Each unit is roughly 550
65 // meters.
66 };
67
68 enum RadioType {
69 RADIO_TYPE_UNKNOWN,
70 RADIO_TYPE_GSM,
71 RADIO_TYPE_CDMA,
72 RADIO_TYPE_WCDMA,
73 };
74
75 // All data for the cell radio.
76 // TODO(joth): Remove RadioData and all usage of it; http://crbug.com/103713
77 struct CONTENT_EXPORT RadioData {
78 RadioData();
79 ~RadioData();
80
81 bool Matches(const RadioData &other) const;
82
83 // Determines whether a new set of radio data differs significantly from this.
84 bool DiffersSignificantly(const RadioData &other) const {
85 // This is required by MockDeviceDataProviderImpl.
86 // TODO(steveblock): Implement properly.
87 return !Matches(other);
88 }
89
90 string16 device_id;
91 std::vector<CellData> cell_data;
92 int home_mobile_network_code; // For the device's home network.
93 int home_mobile_country_code; // For the device's home network.
94 RadioType radio_type; // Mobile radio type.
95 string16 carrier; // Carrier name.
96 };
97
98 // Wifi data relating to a single access point. 37 // Wifi data relating to a single access point.
99 struct CONTENT_EXPORT AccessPointData { 38 struct CONTENT_EXPORT AccessPointData {
100 AccessPointData(); 39 AccessPointData();
101 ~AccessPointData(); 40 ~AccessPointData();
102 41
103 // MAC address, formatted as per MacAddressAsString16. 42 // MAC address, formatted as per MacAddressAsString16.
104 string16 mac_address; 43 string16 mac_address;
105 int radio_signal_strength; // Measured in dBm 44 int radio_signal_strength; // Measured in dBm
106 int channel; 45 int channel;
107 int signal_to_noise; // Ratio in dB 46 int signal_to_noise; // Ratio in dB
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 163
225 // Reference to the client's message loop, all callbacks and access to 164 // Reference to the client's message loop, all callbacks and access to
226 // the listeners_ member should happen in this context. 165 // the listeners_ member should happen in this context.
227 MessageLoop* client_loop_; 166 MessageLoop* client_loop_;
228 167
229 ListenersSet listeners_; 168 ListenersSet listeners_;
230 169
231 DISALLOW_COPY_AND_ASSIGN(DeviceDataProviderImplBase); 170 DISALLOW_COPY_AND_ASSIGN(DeviceDataProviderImplBase);
232 }; 171 };
233 172
234 typedef DeviceDataProviderImplBase<RadioData> RadioDataProviderImplBase;
235 typedef DeviceDataProviderImplBase<WifiData> WifiDataProviderImplBase; 173 typedef DeviceDataProviderImplBase<WifiData> WifiDataProviderImplBase;
236 174
237 // A device data provider 175 // A device data provider
238 // 176 //
239 // We use a singleton instance of this class which is shared by multiple network 177 // We use a singleton instance of this class which is shared by multiple network
240 // location providers. These location providers access the instance through the 178 // location providers. These location providers access the instance through the
241 // Register and Unregister methods. 179 // Register and Unregister methods.
242 template<typename DataType> 180 template<typename DataType>
243 class DeviceDataProvider : public base::NonThreadSafe { 181 class DeviceDataProvider : public base::NonThreadSafe {
244 public: 182 public:
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 294
357 // The factory function used to create the singleton instance. 295 // The factory function used to create the singleton instance.
358 CONTENT_EXPORT static ImplFactoryFunction factory_function_; 296 CONTENT_EXPORT static ImplFactoryFunction factory_function_;
359 297
360 // The internal implementation. 298 // The internal implementation.
361 scoped_refptr<DeviceDataProviderImplBase<DataType> > impl_; 299 scoped_refptr<DeviceDataProviderImplBase<DataType> > impl_;
362 300
363 DISALLOW_COPY_AND_ASSIGN(DeviceDataProvider); 301 DISALLOW_COPY_AND_ASSIGN(DeviceDataProvider);
364 }; 302 };
365 303
366 typedef DeviceDataProvider<RadioData> RadioDataProvider;
367 typedef DeviceDataProvider<WifiData> WifiDataProvider; 304 typedef DeviceDataProvider<WifiData> WifiDataProvider;
368 305
369 #endif // CONTENT_BROWSER_GEOLOCATION_DEVICE_DATA_PROVIDER_H_ 306 #endif // CONTENT_BROWSER_GEOLOCATION_DEVICE_DATA_PROVIDER_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/geolocation/device_data_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698