Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 // This sends a request for geolocation (both wifi AP and cell tower) data. | |
| 56 // If cell data is already available, returns |true|, fills |cell_towers| | |
| 57 // with the latest cell tower data, and sets |age_ms| to the time | |
| 58 // since the last update in MS. | |
| 59 bool GetCellTowers(CellTowerVector* cell_towers, int64_t* age_ms); | |
|
Alexander Alekseev
2017/02/07 22:15:38
It looks like GetWifiAccessPoints()/GetCellTowers(
can Skylar cook
2017/02/07 22:29:59
GetWifiAccessPoints() is used in a few locations,
Alexander Alekseev
2017/02/08 22:10:32
WifiDataProviderChromeOs is a completely different
| |
| 60 | |
| 61 bool cellular_enabled() const { return cellular_enabled_; } | |
| 62 | |
| 46 bool wifi_enabled() const { return wifi_enabled_; } | 63 bool wifi_enabled() const { return wifi_enabled_; } |
| 47 | 64 |
| 48 // ShillPropertyChangedObserver overrides | 65 // ShillPropertyChangedObserver overrides |
| 49 void OnPropertyChanged(const std::string& key, | 66 void OnPropertyChanged(const std::string& key, |
| 50 const base::Value& value) override; | 67 const base::Value& value) override; |
| 51 | 68 |
| 52 private: | 69 private: |
| 53 friend class NetworkHandler; | 70 friend class NetworkHandler; |
| 54 friend class GeolocationHandlerTest; | 71 friend class GeolocationHandlerTest; |
| 55 friend class SimpleGeolocationWiFiTest; | 72 friend class SimpleGeolocationWirelessTest; |
| 56 | 73 |
| 57 GeolocationHandler(); | 74 GeolocationHandler(); |
| 58 | 75 |
| 59 void Init(); | 76 void Init(); |
| 60 | 77 |
| 61 // ShillManagerClient callback | 78 // ShillManagerClient callback |
| 62 void ManagerPropertiesCallback(DBusMethodCallStatus call_status, | 79 void ManagerPropertiesCallback(DBusMethodCallStatus call_status, |
| 63 const base::DictionaryValue& properties); | 80 const base::DictionaryValue& properties); |
| 64 | 81 |
| 65 // Called from OnPropertyChanged or ManagerPropertiesCallback. | 82 // Called from OnPropertyChanged or ManagerPropertiesCallback. |
| 66 void HandlePropertyChanged(const std::string& key, const base::Value& value); | 83 void HandlePropertyChanged(const std::string& key, const base::Value& value); |
| 67 | 84 |
| 68 // Asynchronously request wifi access points from Shill.Manager. | 85 // Asynchronously request geolocation objects (wifi access points and |
| 69 void RequestWifiAccessPoints(); | 86 // cell towers) from Shill.Manager. |
| 87 void RequestGeolocationObjects(); | |
| 70 | 88 |
| 71 // Callback for receiving Geolocation data. | 89 // Callback for receiving Geolocation data. |
| 72 void GeolocationCallback(DBusMethodCallStatus call_status, | 90 void GeolocationCallback(DBusMethodCallStatus call_status, |
| 73 const base::DictionaryValue& properties); | 91 const base::DictionaryValue& properties); |
| 74 | 92 |
| 75 // Wifi enabled state | 93 bool cellular_enabled_; |
| 76 bool wifi_enabled_; | 94 bool wifi_enabled_; |
| 77 | 95 |
| 96 void AddCellTowerFromDict(const base::DictionaryValue* entry); | |
| 97 void AddAccessPointFromDict(const base::DictionaryValue* entry); | |
| 98 | |
| 78 // Cached wifi access points and update time | 99 // Cached wifi access points and update time |
| 79 WifiAccessPointVector wifi_access_points_; | 100 WifiAccessPointVector wifi_access_points_; |
| 80 base::Time geolocation_received_time_; | 101 base::Time access_point_received_time_; |
| 102 | |
| 103 // Cached cell towers and update time | |
| 104 CellTowerVector cell_towers_; | |
| 105 base::Time cell_towers_received_time_; | |
| 81 | 106 |
| 82 // For Shill client callbacks | 107 // For Shill client callbacks |
| 83 base::WeakPtrFactory<GeolocationHandler> weak_ptr_factory_; | 108 base::WeakPtrFactory<GeolocationHandler> weak_ptr_factory_; |
| 84 | 109 |
| 85 DISALLOW_COPY_AND_ASSIGN(GeolocationHandler); | 110 DISALLOW_COPY_AND_ASSIGN(GeolocationHandler); |
| 86 }; | 111 }; |
| 87 | 112 |
| 88 } // namespace chromeos | 113 } // namespace chromeos |
| 89 | 114 |
| 90 #endif // CHROMEOS_NETWORK_GEOLOCATION_HANDLER_H_ | 115 #endif // CHROMEOS_NETWORK_GEOLOCATION_HANDLER_H_ |
| OLD | NEW |