summaryrefslogtreecommitdiffstats
path: root/chromeos/network/geolocation_handler.h
diff options
context:
space:
mode:
authorstevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-15 08:51:17 +0000
committerstevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-15 08:51:17 +0000
commit2632f5046d811f8780484cbaf983f3c9a97c9ea9 (patch)
treeaee09fbc24f1bb9524de64726638ddd3c8f826f3 /chromeos/network/geolocation_handler.h
parentd2397d877f3cd67b0010abecb451ae390cf789b6 (diff)
downloadchromium_src-2632f5046d811f8780484cbaf983f3c9a97c9ea9.zip
chromium_src-2632f5046d811f8780484cbaf983f3c9a97c9ea9.tar.gz
chromium_src-2632f5046d811f8780484cbaf983f3c9a97c9ea9.tar.bz2
Deprecate ShillNetworkClient and add GeolocationHandler
Shill deprecated Manager.Network which was being used to get wifi access point data. This eliminates the dead code and adds GeolocationHandler which currently queries Shill.Manager for geolocation data, and caches and returns the result. BUG=167987 For chrome/browser/geolocation: TBR=joth@chromium.org Review URL: https://chromiumcodereview.appspot.com/11887008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@176858 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos/network/geolocation_handler.h')
-rw-r--r--chromeos/network/geolocation_handler.h86
1 files changed, 86 insertions, 0 deletions
diff --git a/chromeos/network/geolocation_handler.h b/chromeos/network/geolocation_handler.h
new file mode 100644
index 0000000..46a31d7
--- /dev/null
+++ b/chromeos/network/geolocation_handler.h
@@ -0,0 +1,86 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROMEOS_NETWORK_GEOLOCATION_HANDLER_H_
+#define CHROMEOS_NETWORK_GEOLOCATION_HANDLER_H_
+
+#include "base/memory/weak_ptr.h"
+#include "base/time.h"
+#include "chromeos/dbus/dbus_method_call_status.h"
+#include "chromeos/dbus/shill_property_changed_observer.h"
+#include "chromeos/network/network_util.h"
+
+namespace base {
+class DictionaryValue;
+}
+
+namespace chromeos {
+
+// This class provices Shill Wifi Access Point data. It currently relies on
+// polling because that is the usage model in content::WifiDataProvider. This
+// class requests data asynchronously, returning the most recent available data.
+// A typical usage pattern, assuming a wifi device is enabeld, is:
+// Initialize(); // Makes an initial request
+// GetWifiAccessPoints(); // returns true + inital data, requests update
+// (Delay some amount of time, ~10s)
+// GetWifiAccessPoints(); // returns true + updated data, requests update
+// (Delay some amount of time after data changed, ~10s)
+// GetWifiAccessPoints(); // returns true + same data, requests update
+// (Delay some amount of time after data did not change, ~2 mins)
+
+class CHROMEOS_EXPORT GeolocationHandler : public ShillPropertyChangedObserver {
+ public:
+ ~GeolocationHandler();
+
+ // Manage the global instance. Must be initialized before any calls to Get().
+ static void Initialize();
+ static void Shutdown();
+ static GeolocationHandler* Get();
+
+ // This sends a request for wifi access point data. If data is already
+ // available, returns |true|, fills |access_points| with the latest access
+ // point data, and sets |age_ms| to the time since the last update in MS.
+ bool GetWifiAccessPoints(WifiAccessPointVector* access_points, int64* age_ms);
+
+ bool wifi_enabled() const { return wifi_enabled_; }
+
+ // ShillPropertyChangedObserver overrides
+ virtual void OnPropertyChanged(const std::string& key,
+ const base::Value& value) OVERRIDE;
+
+ private:
+ friend class GeolocationHandlerTest;
+ GeolocationHandler();
+ void Init();
+
+ // ShillManagerClient callback
+ void ManagerPropertiesCallback(DBusMethodCallStatus call_status,
+ const base::DictionaryValue& properties);
+
+ // Called from OnPropertyChanged or ManagerPropertiesCallback.
+ void HandlePropertyChanged(const std::string& key, const base::Value& value);
+
+ // Asynchronously request wifi access points from Shill.Manager.
+ void RequestWifiAccessPoints();
+
+ // Callback for receiving Geolocation data.
+ void GeolocationCallback(DBusMethodCallStatus call_status,
+ const base::DictionaryValue& properties);
+
+ // Wimax enabled state
+ bool wifi_enabled_;
+
+ // Cached wifi access points and update time
+ WifiAccessPointVector wifi_access_points_;
+ base::Time geolocation_received_time_;
+
+ // For Shill client callbacks
+ base::WeakPtrFactory<GeolocationHandler> weak_ptr_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(GeolocationHandler);
+};
+
+} // namespace chromeos
+
+#endif // CHROMEOS_NETWORK_GEOLOCATION_HANDLER_H_