Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 CHROME_BROWSER_CHROMEOS_NET_WAKE_ON_WIFI_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_NET_WAKE_ON_WIFI_MANAGER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_NET_WAKE_ON_WIFI_MANAGER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_NET_WAKE_ON_WIFI_MANAGER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/containers/scoped_ptr_hash_map.h" | 10 #include "base/gtest_prod_util.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "chrome/browser/chromeos/power/extension_event_observer.h" | 13 #include "chrome/browser/chromeos/power/extension_event_observer.h" |
| 14 #include "chromeos/network/network_state_handler_observer.h" | 14 #include "chromeos/network/network_state_handler_observer.h" |
| 15 #include "content/public/browser/notification_observer.h" | 15 #include "content/public/browser/notification_observer.h" |
| 16 #include "content/public/browser/notification_registrar.h" | 16 #include "content/public/browser/notification_registrar.h" |
| 17 #include "net/base/ip_endpoint.h" | |
|
stevenjb
2016/04/20 20:16:28
No longer needed
malaykeshav
2016/04/20 23:14:56
Done
| |
| 17 | 18 |
| 18 class Profile; | 19 class Profile; |
| 19 | 20 |
| 20 namespace base { | 21 namespace base { |
| 21 class DictionaryValue; | 22 class DictionaryValue; |
| 22 } | 23 } |
| 23 | 24 |
| 24 namespace chromeos { | 25 namespace chromeos { |
| 25 | 26 |
| 27 class ConnectionObserverTest; | |
| 28 class NetworkDeviceHandler; | |
|
stevenjb
2016/04/20 20:16:28
Both of these should be forward declared in wake_o
malaykeshav
2016/04/20 23:14:55
Done
| |
| 29 class WakeOnWifiConnectionObserver; | |
| 30 | |
| 26 // This class is responsible for managing the various wake-on-wifi related bits | 31 // This class is responsible for managing the various wake-on-wifi related bits |
| 27 // of functionality in chrome. It is responsible for communicating the user's | 32 // of functionality in chrome. It is responsible for communicating the user's |
| 28 // preferences to shill as well as listening for connections to the Google GCM | 33 // preferences to shill as well as listening for connections to the Google GCM |
| 29 // servers and sending that connection information down to shill. This class is | 34 // servers and sending that connection information down to shill. This class is |
| 30 // owned by ChromeBrowserMainPartsChromeos. This class is also NOT thread-safe | 35 // owned by ChromeBrowserMainPartsChromeos. This class is also NOT thread-safe |
| 31 // and should only be called on the UI thread. | 36 // and should only be called on the UI thread. |
| 32 class WakeOnWifiManager : public content::NotificationObserver, | 37 class WakeOnWifiManager : public content::NotificationObserver, |
| 33 public NetworkStateHandlerObserver { | 38 public NetworkStateHandlerObserver { |
| 34 public: | 39 public: |
| 35 enum WakeOnWifiFeature { | 40 enum WakeOnWifiFeature { |
| 36 WAKE_ON_WIFI_NONE = 0x00, | 41 WAKE_ON_WIFI_NONE = 0x00, |
| 37 WAKE_ON_WIFI_PACKET = 0x01, | 42 WAKE_ON_WIFI_PACKET = 0x01, |
| 38 WAKE_ON_WIFI_DARKCONNECT = 0x02, | 43 WAKE_ON_WIFI_DARKCONNECT = 0x02, |
| 39 WAKE_ON_WIFI_PACKET_AND_DARKCONNECT = 0x03, | 44 WAKE_ON_WIFI_PACKET_AND_DARKCONNECT = 0x03, |
| 40 NOT_SUPPORTED = 0x04, | 45 NOT_SUPPORTED = 0x04, |
| 41 INVALID = 0x08, | 46 INVALID = 0x08, |
| 42 }; | 47 }; |
| 43 | 48 |
| 44 static WakeOnWifiManager* Get(); | 49 static WakeOnWifiManager* Get(); |
| 50 static bool IsWakeOnPacketEnabled(WakeOnWifiFeature feature); | |
| 45 | 51 |
| 46 WakeOnWifiManager(); | 52 WakeOnWifiManager(); |
| 47 ~WakeOnWifiManager() override; | 53 ~WakeOnWifiManager() override; |
| 48 | 54 |
| 49 // Should be called whenever the primary user changes their preference for the | 55 // Should be called whenever the primary user changes their preference for the |
| 50 // wake-on-wifi features that should be enabled. | 56 // wake-on-wifi features that should be enabled. |
| 51 void OnPreferenceChanged(WakeOnWifiFeature feature); | 57 void OnPreferenceChanged(WakeOnWifiFeature feature); |
| 52 | 58 |
| 53 // Returns true if wake-on-wifi features are supported. Returns false if we | 59 // Returns true if wake-on-wifi features are supported. Returns false if we |
| 54 // have not yet determined whether wake-on-wifi features are supported. | 60 // have not yet determined whether wake-on-wifi features are supported. |
| 55 bool WakeOnWifiSupported(); | 61 bool WakeOnWifiSupported(); |
| 56 | 62 |
| 57 // content::NotificationObserver override. | 63 // content::NotificationObserver override. |
| 58 void Observe(int type, | 64 void Observe(int type, |
| 59 const content::NotificationSource& source, | 65 const content::NotificationSource& source, |
| 60 const content::NotificationDetails& details) override; | 66 const content::NotificationDetails& details) override; |
| 61 | 67 |
| 62 // NetworkStateHandlerObserver overrides. | 68 // NetworkStateHandlerObserver overrides. |
| 63 void DeviceListChanged() override; | 69 void DeviceListChanged() override; |
| 64 void DevicePropertiesUpdated(const DeviceState* device) override; | 70 void DevicePropertiesUpdated(const DeviceState* device) override; |
| 65 | 71 |
| 66 private: | 72 private: |
| 73 FRIEND_TEST_ALL_PREFIXES(WakeOnWifiObserverTest, TestWakeOnWifiPacketAdd); | |
| 74 FRIEND_TEST_ALL_PREFIXES(WakeOnWifiObserverTest, TestWakeOnWifiPacketRemove); | |
| 75 FRIEND_TEST_ALL_PREFIXES(WakeOnWifiObserverTest, TestWakeOnWifiNoneAdd); | |
| 76 FRIEND_TEST_ALL_PREFIXES(WakeOnWifiObserverTest, TestWakeOnWifiNoneRemove); | |
| 77 | |
| 67 // Sends the user's preference to shill, updates the timer used by the GCM | 78 // Sends the user's preference to shill, updates the timer used by the GCM |
| 68 // client to send heartbeats, and tells |extension_event_observer_| to block | 79 // client to send heartbeats, and tells |extension_event_observer_| to block |
| 69 // (or not block) suspends based on the value of |current_feature_|. | 80 // (or not block) suspends based on the value of |current_feature_|. |
| 70 void HandleWakeOnWifiFeatureUpdated(); | 81 void HandleWakeOnWifiFeatureUpdated(); |
| 71 | 82 |
| 72 // Requests all the properties for the wifi device from shill. | 83 // Requests all the properties for the wifi device from shill. |
| 73 void GetWifiDeviceProperties(); | 84 void GetWifiDeviceProperties(); |
| 74 | 85 |
| 75 // Callback for getting the Wi-Fi device properties. | 86 // Callback for getting the Wi-Fi device properties. |
| 76 void GetDevicePropertiesCallback(const std::string& device_path, | 87 void GetDevicePropertiesCallback(const std::string& device_path, |
| 77 const base::DictionaryValue& properties); | 88 const base::DictionaryValue& properties); |
| 78 | 89 |
| 79 // Called when a Profile is added or destroyed. | 90 // Called when a Profile is added or destroyed. |
| 80 void OnProfileAdded(Profile* profile); | 91 void OnProfileAdded(Profile* profile); |
| 81 void OnProfileDestroyed(Profile* profile); | 92 void OnProfileDestroyed(Profile* profile); |
| 82 | 93 |
| 83 WakeOnWifiFeature current_feature_; | 94 WakeOnWifiFeature current_feature_; |
| 84 | 95 |
| 85 // Set to true once we have received the properties for the wifi device from | 96 // Set to true once we have received the properties for the wifi device from |
| 86 // shill. | 97 // shill. |
| 87 bool wifi_properties_received_; | 98 bool wifi_properties_received_; |
| 88 | 99 |
| 89 class WakeOnPacketConnectionObserver; | 100 std::map<Profile*, |
| 90 base::ScopedPtrHashMap<Profile*, | 101 std::unique_ptr<WakeOnWifiConnectionObserver>> connection_observers_; |
| 91 std::unique_ptr<WakeOnPacketConnectionObserver>> | |
| 92 connection_observers_; | |
| 93 | 102 |
| 94 std::unique_ptr<ExtensionEventObserver> extension_event_observer_; | 103 std::unique_ptr<ExtensionEventObserver> extension_event_observer_; |
| 95 | 104 |
| 96 content::NotificationRegistrar registrar_; | 105 content::NotificationRegistrar registrar_; |
| 97 | 106 |
| 98 base::WeakPtrFactory<WakeOnWifiManager> weak_ptr_factory_; | 107 base::WeakPtrFactory<WakeOnWifiManager> weak_ptr_factory_; |
| 99 | 108 |
| 100 DISALLOW_COPY_AND_ASSIGN(WakeOnWifiManager); | 109 DISALLOW_COPY_AND_ASSIGN(WakeOnWifiManager); |
| 101 }; | 110 }; |
| 102 | 111 |
| 103 } // namespace chromeos | 112 } // namespace chromeos |
| 104 | 113 |
| 105 #endif // CHROME_BROWSER_CHROMEOS_NET_WAKE_ON_WIFI_MANAGER_H_ | 114 #endif // CHROME_BROWSER_CHROMEOS_NET_WAKE_ON_WIFI_MANAGER_H_ |
| OLD | NEW |