Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chromeos / network / geolocation_handler.h
blob15b291e074ae54b3a1f58c2ceb88078041417d1b
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/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_handler.h"
13 #include "chromeos/network/network_util.h"
15 namespace base {
16 class DictionaryValue;
19 namespace chromeos {
21 // This class provices Shill Wifi Access Point data. It currently relies on
22 // polling because that is the usage model in content::WifiDataProvider. This
23 // class requests data asynchronously, returning the most recent available data.
24 // A typical usage pattern, assuming a wifi device is enabled, is:
25 // Initialize(); // Makes an initial request
26 // GetWifiAccessPoints(); // returns true + inital data, requests update
27 // (Delay some amount of time, ~10s)
28 // GetWifiAccessPoints(); // returns true + updated data, requests update
29 // (Delay some amount of time after data changed, ~10s)
30 // GetWifiAccessPoints(); // returns true + same data, requests update
31 // (Delay some amount of time after data did not change, ~2 mins)
33 class CHROMEOS_EXPORT GeolocationHandler : public ShillPropertyChangedObserver {
34 public:
35 ~GeolocationHandler() override;
37 // This sends a request for wifi access point data. If data is already
38 // available, returns |true|, fills |access_points| with the latest access
39 // point data, and sets |age_ms| to the time since the last update in MS.
40 bool GetWifiAccessPoints(WifiAccessPointVector* access_points, int64* age_ms);
42 bool wifi_enabled() const { return wifi_enabled_; }
44 // ShillPropertyChangedObserver overrides
45 void OnPropertyChanged(const std::string& key,
46 const base::Value& value) override;
48 private:
49 friend class NetworkHandler;
50 friend class GeolocationHandlerTest;
51 GeolocationHandler();
53 void Init();
55 // ShillManagerClient callback
56 void ManagerPropertiesCallback(DBusMethodCallStatus call_status,
57 const base::DictionaryValue& properties);
59 // Called from OnPropertyChanged or ManagerPropertiesCallback.
60 void HandlePropertyChanged(const std::string& key, const base::Value& value);
62 // Asynchronously request wifi access points from Shill.Manager.
63 void RequestWifiAccessPoints();
65 // Callback for receiving Geolocation data.
66 void GeolocationCallback(DBusMethodCallStatus call_status,
67 const base::DictionaryValue& properties);
69 // Wifi enabled state
70 bool wifi_enabled_;
72 // Cached wifi access points and update time
73 WifiAccessPointVector wifi_access_points_;
74 base::Time geolocation_received_time_;
76 // For Shill client callbacks
77 base::WeakPtrFactory<GeolocationHandler> weak_ptr_factory_;
79 DISALLOW_COPY_AND_ASSIGN(GeolocationHandler);
82 } // namespace chromeos
84 #endif // CHROMEOS_NETWORK_GEOLOCATION_HANDLER_H_