Support SizeClassIdiom on iOS7.
[chromium-blink-merge.git] / chrome / browser / chromeos / net / wake_on_wifi_manager.h
blob86f217573fec3f8d2d9745c70d738df936c7dee2
1 // Copyright 2014 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 CHROME_BROWSER_CHROMEOS_NET_WAKE_ON_WIFI_MANAGER_H_
6 #define CHROME_BROWSER_CHROMEOS_NET_WAKE_ON_WIFI_MANAGER_H_
8 #include "base/containers/scoped_ptr_hash_map.h"
9 #include "base/macros.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "chrome/browser/chromeos/power/extension_event_observer.h"
13 #include "chromeos/network/network_state_handler_observer.h"
14 #include "content/public/browser/notification_observer.h"
15 #include "content/public/browser/notification_registrar.h"
17 class Profile;
19 namespace base {
20 class DictionaryValue;
23 namespace chromeos {
25 // This class is responsible for managing the various wake-on-wifi related bits
26 // of functionality in chrome. It is responsible for communicating the user's
27 // preferences to shill as well as listening for connections to the Google GCM
28 // servers and sending that connection information down to shill. This class is
29 // owned by ChromeBrowserMainPartsChromeos. This class is also NOT thread-safe
30 // and should only be called on the UI thread.
31 class WakeOnWifiManager : public content::NotificationObserver,
32 public NetworkStateHandlerObserver {
33 public:
34 enum WakeOnWifiFeature {
35 WAKE_ON_NONE = 0x00,
36 WAKE_ON_PACKET = 0x01,
37 WAKE_ON_SSID = 0x02,
38 WAKE_ON_PACKET_AND_SSID = 0x03,
39 NOT_SUPPORTED = 0x04,
40 INVALID = 0x08,
43 static WakeOnWifiManager* Get();
45 WakeOnWifiManager();
46 ~WakeOnWifiManager() override;
48 // Should be called whenever the primary user changes their preference for the
49 // wake-on-wifi features that should be enabled.
50 void OnPreferenceChanged(WakeOnWifiFeature feature);
52 // Returns true if wake-on-wifi features are supported. Returns false if we
53 // have not yet determined whether wake-on-wifi features are supported.
54 bool WakeOnWifiSupported();
56 // content::NotificationObserver override.
57 void Observe(int type,
58 const content::NotificationSource& source,
59 const content::NotificationDetails& details) override;
61 // NetworkStateHandlerObserver overrides.
62 void DeviceListChanged() override;
63 void DevicePropertiesUpdated(const DeviceState* device) override;
65 private:
66 // Sends the user's preference to shill, updates the timer used by the GCM
67 // client to send heartbeats, and tells |extension_event_observer_| to block
68 // (or not block) suspends based on the value of |current_feature_|.
69 void HandleWakeOnWifiFeatureUpdated();
71 // Requests all the properties for the wifi device from shill.
72 void GetWifiDeviceProperties();
74 // Callback for getting the Wi-Fi device properties.
75 void GetDevicePropertiesCallback(const std::string& device_path,
76 const base::DictionaryValue& properties);
78 // Called when a Profile is added or destroyed.
79 void OnProfileAdded(Profile* profile);
80 void OnProfileDestroyed(Profile* profile);
82 WakeOnWifiFeature current_feature_;
84 // Set to true once we have received the properties for the wifi device from
85 // shill.
86 bool wifi_properties_received_;
88 class WakeOnPacketConnectionObserver;
89 base::ScopedPtrHashMap<Profile*, scoped_ptr<WakeOnPacketConnectionObserver>>
90 connection_observers_;
92 scoped_ptr<ExtensionEventObserver> extension_event_observer_;
94 content::NotificationRegistrar registrar_;
96 base::WeakPtrFactory<WakeOnWifiManager> weak_ptr_factory_;
98 DISALLOW_COPY_AND_ASSIGN(WakeOnWifiManager);
101 } // namespace chromeos
103 #endif // CHROME_BROWSER_CHROMEOS_NET_WAKE_ON_WIFI_MANAGER_H_