Use Persistent::Reset.
[chromium-blink-merge.git] / chromeos / network / geolocation_handler.h
blob9c3e533931ed34702a5eee367e8bc517e943c8df
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
3 // found in the LICENSE file.
5 #ifndef CHROMEOS_NETWORK_GEOLOCATION_HANDLER_H_
6 #define CHROMEOS_NETWORK_GEOLOCATION_HANDLER_H_
8 #include "base/memory/weak_ptr.h"
9 #include "base/time.h"
10 #include "chromeos/dbus/dbus_method_call_status.h"
11 #include "chromeos/dbus/shill_property_changed_observer.h"
12 #include "chromeos/network/network_util.h"
14 namespace base {
15 class DictionaryValue;
18 namespace chromeos {
20 // 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 // class requests data asynchronously, returning the most recent available data.
23 // A typical usage pattern, assuming a wifi device is enabled, is:
24 // Initialize(); // Makes an initial request
25 // GetWifiAccessPoints(); // returns true + inital data, requests update
26 // (Delay some amount of time, ~10s)
27 // GetWifiAccessPoints(); // returns true + updated data, requests update
28 // (Delay some amount of time after data changed, ~10s)
29 // GetWifiAccessPoints(); // returns true + same data, requests update
30 // (Delay some amount of time after data did not change, ~2 mins)
32 class CHROMEOS_EXPORT GeolocationHandler : public ShillPropertyChangedObserver {
33 public:
34 virtual ~GeolocationHandler();
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();
41 // This sends a request for wifi access point data. If data is already
42 // 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.
44 bool GetWifiAccessPoints(WifiAccessPointVector* access_points, int64* age_ms);
46 bool wifi_enabled() const { return wifi_enabled_; }
48 // ShillPropertyChangedObserver overrides
49 virtual void OnPropertyChanged(const std::string& key,
50 const base::Value& value) OVERRIDE;
52 private:
53 friend class GeolocationHandlerTest;
54 GeolocationHandler();
55 void Init();
57 // ShillManagerClient callback
58 void ManagerPropertiesCallback(DBusMethodCallStatus call_status,
59 const base::DictionaryValue& properties);
61 // Called from OnPropertyChanged or ManagerPropertiesCallback.
62 void HandlePropertyChanged(const std::string& key, const base::Value& value);
64 // Asynchronously request wifi access points from Shill.Manager.
65 void RequestWifiAccessPoints();
67 // Callback for receiving Geolocation data.
68 void GeolocationCallback(DBusMethodCallStatus call_status,
69 const base::DictionaryValue& properties);
71 // Wifi enabled state
72 bool wifi_enabled_;
74 // Cached wifi access points and update time
75 WifiAccessPointVector wifi_access_points_;
76 base::Time geolocation_received_time_;
78 // For Shill client callbacks
79 base::WeakPtrFactory<GeolocationHandler> weak_ptr_factory_;
81 DISALLOW_COPY_AND_ASSIGN(GeolocationHandler);
84 } // namespace chromeos
86 #endif // CHROMEOS_NETWORK_GEOLOCATION_HANDLER_H_