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

Side by Side Diff: chromeos/network/geolocation_handler.h

Issue 2624843003: Add support for cellular geolocation (Closed)
Patch Set: Remove GetCellTowers, fix indicator flag logic Created 3 years, 10 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 #ifndef CHROMEOS_NETWORK_GEOLOCATION_HANDLER_H_ 5 #ifndef CHROMEOS_NETWORK_GEOLOCATION_HANDLER_H_
6 #define CHROMEOS_NETWORK_GEOLOCATION_HANDLER_H_ 6 #define CHROMEOS_NETWORK_GEOLOCATION_HANDLER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
12 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "chromeos/dbus/dbus_method_call_status.h" 13 #include "chromeos/dbus/dbus_method_call_status.h"
14 #include "chromeos/dbus/shill_property_changed_observer.h" 14 #include "chromeos/dbus/shill_property_changed_observer.h"
15 #include "chromeos/network/network_handler.h" 15 #include "chromeos/network/network_handler.h"
16 #include "chromeos/network/network_util.h" 16 #include "chromeos/network/network_util.h"
17 17
18 namespace base { 18 namespace base {
19 class DictionaryValue; 19 class DictionaryValue;
20 } 20 }
21 21
22 namespace chromeos { 22 namespace chromeos {
23 23
24 // This class provices Shill Wifi Access Point data. It currently relies on 24 // This class provices Shill Wifi Access Point and Cell Tower data. It
25 // polling because that is the usage model in content::WifiDataProvider. This 25 // currently relies on polling because that is the usage model in
26 // class requests data asynchronously, returning the most recent available data. 26 // content::WifiDataProvider. This class requests data asynchronously,
27 // A typical usage pattern, assuming a wifi device is enabled, is: 27 // returning the most recent available data. A typical usage pattern,
28 // assuming a wifi device is enabled, is:
28 // Initialize(); // Makes an initial request 29 // Initialize(); // Makes an initial request
29 // GetWifiAccessPoints(); // returns true + inital data, requests update 30 // GetWifiAccessPoints(); // returns true + inital data, requests update
30 // (Delay some amount of time, ~10s) 31 // (Delay some amount of time, ~10s)
31 // GetWifiAccessPoints(); // returns true + updated data, requests update 32 // GetWifiAccessPoints(); // returns true + updated data, requests update
32 // (Delay some amount of time after data changed, ~10s) 33 // (Delay some amount of time after data changed, ~10s)
33 // GetWifiAccessPoints(); // returns true + same data, requests update 34 // GetWifiAccessPoints(); // returns true + same data, requests update
34 // (Delay some amount of time after data did not change, ~2 mins) 35 // (Delay some amount of time after data did not change, ~2 mins)
35 36
36 class CHROMEOS_EXPORT GeolocationHandler : public ShillPropertyChangedObserver { 37 class CHROMEOS_EXPORT GeolocationHandler : public ShillPropertyChangedObserver {
37 public: 38 public:
38 ~GeolocationHandler() override; 39 ~GeolocationHandler() override;
39 40
40 // This sends a request for wifi access point data. If data is already 41 // This sends a request for geolocation (both wifi AP and cell tower) data.
41 // available, returns |true|, fills |access_points| with the latest access 42 // If AP data is already available, fills |access_points| with the latest
42 // point data, and sets |age_ms| to the time since the last update in MS. 43 // access point data, and similarly for cell tower data and |cell_towers|.
44 // Returns |true| if either type of data is already available upon call.
45 bool GetNetworkInformation(WifiAccessPointVector* access_points,
46 CellTowerVector* cell_towers);
47
48 // This sends a request for geolocation (both wifi AP and cell tower) data.
49 // If wifi data is already available, returns |true|, fills |access_points|
50 // with the latest access point data, and sets |age_ms| to the time
51 // since the last update in MS.
43 bool GetWifiAccessPoints(WifiAccessPointVector* access_points, 52 bool GetWifiAccessPoints(WifiAccessPointVector* access_points,
44 int64_t* age_ms); 53 int64_t* age_ms);
45 54
55 bool cellular_enabled() const { return cellular_enabled_; }
stevenjb 2017/02/07 23:54:29 Is this used now?
can Skylar cook 2017/02/08 21:15:49 Done.
56
46 bool wifi_enabled() const { return wifi_enabled_; } 57 bool wifi_enabled() const { return wifi_enabled_; }
47 58
48 // ShillPropertyChangedObserver overrides 59 // ShillPropertyChangedObserver overrides
49 void OnPropertyChanged(const std::string& key, 60 void OnPropertyChanged(const std::string& key,
50 const base::Value& value) override; 61 const base::Value& value) override;
51 62
52 private: 63 private:
53 friend class NetworkHandler; 64 friend class NetworkHandler;
54 friend class GeolocationHandlerTest; 65 friend class GeolocationHandlerTest;
55 friend class SimpleGeolocationWiFiTest; 66 friend class SimpleGeolocationWirelessTest;
56 67
57 GeolocationHandler(); 68 GeolocationHandler();
58 69
59 void Init(); 70 void Init();
60 71
61 // ShillManagerClient callback 72 // ShillManagerClient callback
62 void ManagerPropertiesCallback(DBusMethodCallStatus call_status, 73 void ManagerPropertiesCallback(DBusMethodCallStatus call_status,
63 const base::DictionaryValue& properties); 74 const base::DictionaryValue& properties);
64 75
65 // Called from OnPropertyChanged or ManagerPropertiesCallback. 76 // Called from OnPropertyChanged or ManagerPropertiesCallback.
66 void HandlePropertyChanged(const std::string& key, const base::Value& value); 77 void HandlePropertyChanged(const std::string& key, const base::Value& value);
67 78
68 // Asynchronously request wifi access points from Shill.Manager. 79 // Asynchronously request geolocation objects (wifi access points and
69 void RequestWifiAccessPoints(); 80 // cell towers) from Shill.Manager.
81 void RequestGeolocationObjects();
70 82
71 // Callback for receiving Geolocation data. 83 // Callback for receiving Geolocation data.
72 void GeolocationCallback(DBusMethodCallStatus call_status, 84 void GeolocationCallback(DBusMethodCallStatus call_status,
73 const base::DictionaryValue& properties); 85 const base::DictionaryValue& properties);
74 86
75 // Wifi enabled state 87 bool cellular_enabled_;
76 bool wifi_enabled_; 88 bool wifi_enabled_;
77 89
90 void AddCellTowerFromDict(const base::DictionaryValue* entry);
91 void AddAccessPointFromDict(const base::DictionaryValue* entry);
92
78 // Cached wifi access points and update time 93 // Cached wifi access points and update time
79 WifiAccessPointVector wifi_access_points_; 94 WifiAccessPointVector wifi_access_points_;
80 base::Time geolocation_received_time_; 95 base::Time access_point_received_time_;
96
97 // Cached cell towers and update time
98 CellTowerVector cell_towers_;
99 base::Time cell_towers_received_time_;
81 100
82 // For Shill client callbacks 101 // For Shill client callbacks
83 base::WeakPtrFactory<GeolocationHandler> weak_ptr_factory_; 102 base::WeakPtrFactory<GeolocationHandler> weak_ptr_factory_;
84 103
85 DISALLOW_COPY_AND_ASSIGN(GeolocationHandler); 104 DISALLOW_COPY_AND_ASSIGN(GeolocationHandler);
86 }; 105 };
87 106
88 } // namespace chromeos 107 } // namespace chromeos
89 108
90 #endif // CHROMEOS_NETWORK_GEOLOCATION_HANDLER_H_ 109 #endif // CHROMEOS_NETWORK_GEOLOCATION_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698