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 wifi data is already available, returns |true|, fills |access_points| |
| 42 // point data, and sets |age_ms| to the time since the last update in MS. | 43 // with the latest access point data, and sets |age_ms| to the time |
| 44 // since the last update in MS. | |
| 43 bool GetWifiAccessPoints(WifiAccessPointVector* access_points, | 45 bool GetWifiAccessPoints(WifiAccessPointVector* access_points, |
| 44 int64_t* age_ms); | 46 int64_t* age_ms); |
| 45 | 47 |
| 46 bool wifi_enabled() const { return wifi_enabled_; } | 48 bool wifi_enabled() const { return wifi_enabled_; } |
| 47 | 49 |
| 50 // This sends a request for geolocation (both wifi AP and cell tower) data. | |
| 51 // If cell data is already available, returns |true|, fills |cell_towers| | |
| 52 // with the latest cell tower data, and sets |age_ms| to the time | |
| 53 // since the last update in MS. | |
| 54 bool GetCellTowers(CellTowerVector* cell_towers, int64_t* age_ms); | |
| 55 | |
| 56 bool cellular_enabled() const { return cellular_enabled_; } | |
| 57 | |
| 48 // ShillPropertyChangedObserver overrides | 58 // ShillPropertyChangedObserver overrides |
| 49 void OnPropertyChanged(const std::string& key, | 59 void OnPropertyChanged(const std::string& key, |
| 50 const base::Value& value) override; | 60 const base::Value& value) override; |
| 51 | 61 |
| 52 private: | 62 private: |
| 53 friend class NetworkHandler; | 63 friend class NetworkHandler; |
| 54 friend class GeolocationHandlerTest; | 64 friend class GeolocationHandlerTest; |
| 55 friend class SimpleGeolocationWiFiTest; | 65 friend class SimpleGeolocationWirelessTest; |
| 56 | 66 |
| 57 GeolocationHandler(); | 67 GeolocationHandler(); |
| 58 | 68 |
| 59 void Init(); | 69 void Init(); |
| 60 | 70 |
| 61 // ShillManagerClient callback | 71 // ShillManagerClient callback |
| 62 void ManagerPropertiesCallback(DBusMethodCallStatus call_status, | 72 void ManagerPropertiesCallback(DBusMethodCallStatus call_status, |
| 63 const base::DictionaryValue& properties); | 73 const base::DictionaryValue& properties); |
| 64 | 74 |
| 65 // Called from OnPropertyChanged or ManagerPropertiesCallback. | 75 // Called from OnPropertyChanged or ManagerPropertiesCallback. |
| 66 void HandlePropertyChanged(const std::string& key, const base::Value& value); | 76 void HandlePropertyChanged(const std::string& key, const base::Value& value); |
| 67 | 77 |
| 68 // Asynchronously request wifi access points from Shill.Manager. | 78 // Asynchronously request geolocation objects (wifi access points and |
| 69 void RequestWifiAccessPoints(); | 79 // cell towers) from Shill.Manager. |
| 80 void RequestGeolocationObjects(); | |
| 70 | 81 |
| 71 // Callback for receiving Geolocation data. | 82 // Callback for receiving Geolocation data. |
| 72 void GeolocationCallback(DBusMethodCallStatus call_status, | 83 void GeolocationCallback(DBusMethodCallStatus call_status, |
| 73 const base::DictionaryValue& properties); | 84 const base::DictionaryValue& properties); |
| 74 | 85 |
| 86 // Cellular enabled state | |
|
stevenjb
2017/02/03 02:12:03
nit: These comment's aren't helpful and this are n
can Skylar cook
2017/02/03 21:47:07
Done.
| |
| 87 bool cellular_enabled_; | |
| 75 // Wifi enabled state | 88 // Wifi enabled state |
| 76 bool wifi_enabled_; | 89 bool wifi_enabled_; |
| 77 | 90 |
| 78 // Cached wifi access points and update time | 91 // Cached wifi access points and update time |
| 79 WifiAccessPointVector wifi_access_points_; | 92 WifiAccessPointVector wifi_access_points_; |
| 80 base::Time geolocation_received_time_; | 93 base::Time access_point_received_time_; |
| 94 | |
| 95 // Cached cell towers and update time | |
| 96 CellTowerVector cell_towers_; | |
| 97 base::Time cell_towers_received_time_; | |
| 81 | 98 |
| 82 // For Shill client callbacks | 99 // For Shill client callbacks |
| 83 base::WeakPtrFactory<GeolocationHandler> weak_ptr_factory_; | 100 base::WeakPtrFactory<GeolocationHandler> weak_ptr_factory_; |
| 84 | 101 |
| 85 DISALLOW_COPY_AND_ASSIGN(GeolocationHandler); | 102 DISALLOW_COPY_AND_ASSIGN(GeolocationHandler); |
| 86 }; | 103 }; |
| 87 | 104 |
| 88 } // namespace chromeos | 105 } // namespace chromeos |
| 89 | 106 |
| 90 #endif // CHROMEOS_NETWORK_GEOLOCATION_HANDLER_H_ | 107 #endif // CHROMEOS_NETWORK_GEOLOCATION_HANDLER_H_ |
| OLD | NEW |