| 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 "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
| 9 #include "base/time.h" | 9 #include "base/time.h" |
| 10 #include "chromeos/dbus/dbus_method_call_status.h" | 10 #include "chromeos/dbus/dbus_method_call_status.h" |
| 11 #include "chromeos/dbus/shill_property_changed_observer.h" | 11 #include "chromeos/dbus/shill_property_changed_observer.h" |
| 12 #include "chromeos/network/network_handler.h" |
| 12 #include "chromeos/network/network_util.h" | 13 #include "chromeos/network/network_util.h" |
| 13 | 14 |
| 14 namespace base { | 15 namespace base { |
| 15 class DictionaryValue; | 16 class DictionaryValue; |
| 16 } | 17 } |
| 17 | 18 |
| 18 namespace chromeos { | 19 namespace chromeos { |
| 19 | 20 |
| 20 // This class provices Shill Wifi Access Point data. It currently relies on | 21 // This class provices Shill Wifi Access Point data. It currently relies on |
| 21 // polling because that is the usage model in content::WifiDataProvider. This | 22 // polling because that is the usage model in content::WifiDataProvider. This |
| 22 // class requests data asynchronously, returning the most recent available data. | 23 // class requests data asynchronously, returning the most recent available data. |
| 23 // A typical usage pattern, assuming a wifi device is enabled, is: | 24 // A typical usage pattern, assuming a wifi device is enabled, is: |
| 24 // Initialize(); // Makes an initial request | 25 // Initialize(); // Makes an initial request |
| 25 // GetWifiAccessPoints(); // returns true + inital data, requests update | 26 // GetWifiAccessPoints(); // returns true + inital data, requests update |
| 26 // (Delay some amount of time, ~10s) | 27 // (Delay some amount of time, ~10s) |
| 27 // GetWifiAccessPoints(); // returns true + updated data, requests update | 28 // GetWifiAccessPoints(); // returns true + updated data, requests update |
| 28 // (Delay some amount of time after data changed, ~10s) | 29 // (Delay some amount of time after data changed, ~10s) |
| 29 // GetWifiAccessPoints(); // returns true + same data, requests update | 30 // GetWifiAccessPoints(); // returns true + same data, requests update |
| 30 // (Delay some amount of time after data did not change, ~2 mins) | 31 // (Delay some amount of time after data did not change, ~2 mins) |
| 31 | 32 |
| 32 class CHROMEOS_EXPORT GeolocationHandler : public ShillPropertyChangedObserver { | 33 class CHROMEOS_EXPORT GeolocationHandler : public ShillPropertyChangedObserver { |
| 33 public: | 34 public: |
| 34 virtual ~GeolocationHandler(); | 35 virtual ~GeolocationHandler(); |
| 35 | 36 |
| 36 // Manage the global instance. Must be initialized before any calls to Get(). | |
| 37 static void Initialize(); | |
| 38 static void Shutdown(); | |
| 39 static GeolocationHandler* Get(); | |
| 40 | |
| 41 // This sends a request for wifi access point data. If data is already | 37 // This sends a request for wifi access point data. If data is already |
| 42 // available, returns |true|, fills |access_points| with the latest access | 38 // available, returns |true|, fills |access_points| with the latest access |
| 43 // point data, and sets |age_ms| to the time since the last update in MS. | 39 // point data, and sets |age_ms| to the time since the last update in MS. |
| 44 bool GetWifiAccessPoints(WifiAccessPointVector* access_points, int64* age_ms); | 40 bool GetWifiAccessPoints(WifiAccessPointVector* access_points, int64* age_ms); |
| 45 | 41 |
| 46 bool wifi_enabled() const { return wifi_enabled_; } | 42 bool wifi_enabled() const { return wifi_enabled_; } |
| 47 | 43 |
| 48 // ShillPropertyChangedObserver overrides | 44 // ShillPropertyChangedObserver overrides |
| 49 virtual void OnPropertyChanged(const std::string& key, | 45 virtual void OnPropertyChanged(const std::string& key, |
| 50 const base::Value& value) OVERRIDE; | 46 const base::Value& value) OVERRIDE; |
| 51 | 47 |
| 52 private: | 48 private: |
| 49 friend class NetworkHandler; |
| 53 friend class GeolocationHandlerTest; | 50 friend class GeolocationHandlerTest; |
| 54 GeolocationHandler(); | 51 GeolocationHandler(); |
| 52 |
| 55 void Init(); | 53 void Init(); |
| 56 | 54 |
| 57 // ShillManagerClient callback | 55 // ShillManagerClient callback |
| 58 void ManagerPropertiesCallback(DBusMethodCallStatus call_status, | 56 void ManagerPropertiesCallback(DBusMethodCallStatus call_status, |
| 59 const base::DictionaryValue& properties); | 57 const base::DictionaryValue& properties); |
| 60 | 58 |
| 61 // Called from OnPropertyChanged or ManagerPropertiesCallback. | 59 // Called from OnPropertyChanged or ManagerPropertiesCallback. |
| 62 void HandlePropertyChanged(const std::string& key, const base::Value& value); | 60 void HandlePropertyChanged(const std::string& key, const base::Value& value); |
| 63 | 61 |
| 64 // Asynchronously request wifi access points from Shill.Manager. | 62 // Asynchronously request wifi access points from Shill.Manager. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 77 | 75 |
| 78 // For Shill client callbacks | 76 // For Shill client callbacks |
| 79 base::WeakPtrFactory<GeolocationHandler> weak_ptr_factory_; | 77 base::WeakPtrFactory<GeolocationHandler> weak_ptr_factory_; |
| 80 | 78 |
| 81 DISALLOW_COPY_AND_ASSIGN(GeolocationHandler); | 79 DISALLOW_COPY_AND_ASSIGN(GeolocationHandler); |
| 82 }; | 80 }; |
| 83 | 81 |
| 84 } // namespace chromeos | 82 } // namespace chromeos |
| 85 | 83 |
| 86 #endif // CHROMEOS_NETWORK_GEOLOCATION_HANDLER_H_ | 84 #endif // CHROMEOS_NETWORK_GEOLOCATION_HANDLER_H_ |
| OLD | NEW |