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_device_handler.h" | |
|
stevenjb
2016/04/19 23:46:15
Forward declare instead
malaykeshav
2016/04/20 19:48:42
Done
| |
| 14 #include "chromeos/network/network_state_handler_observer.h" | 15 #include "chromeos/network/network_state_handler_observer.h" |
| 16 #include "components/gcm_driver/gcm_connection_observer.h" | |
| 15 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
| 16 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
| 19 #include "net/base/ip_endpoint.h" | |
| 17 | 20 |
| 18 class Profile; | 21 class Profile; |
| 19 | 22 |
| 20 namespace base { | 23 namespace base { |
| 21 class DictionaryValue; | 24 class DictionaryValue; |
| 22 } | 25 } |
| 23 | 26 |
| 24 namespace chromeos { | 27 namespace chromeos { |
| 25 | 28 |
| 29 class ConnectionObserverTest; | |
| 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 { |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 57 // content::NotificationObserver override. | 62 // content::NotificationObserver override. |
| 58 void Observe(int type, | 63 void Observe(int type, |
| 59 const content::NotificationSource& source, | 64 const content::NotificationSource& source, |
| 60 const content::NotificationDetails& details) override; | 65 const content::NotificationDetails& details) override; |
| 61 | 66 |
| 62 // NetworkStateHandlerObserver overrides. | 67 // NetworkStateHandlerObserver overrides. |
| 63 void DeviceListChanged() override; | 68 void DeviceListChanged() override; |
| 64 void DevicePropertiesUpdated(const DeviceState* device) override; | 69 void DevicePropertiesUpdated(const DeviceState* device) override; |
| 65 | 70 |
| 66 private: | 71 private: |
| 72 FRIEND_TEST_ALL_PREFIXES(WakeOnWifiObserverTest, TestWakeOnWifiPacketAdd); | |
| 73 FRIEND_TEST_ALL_PREFIXES(WakeOnWifiObserverTest, TestWakeOnWifiPacketRemove); | |
| 74 FRIEND_TEST_ALL_PREFIXES(WakeOnWifiObserverTest, TestWakeOnWifiNoneAdd); | |
| 75 FRIEND_TEST_ALL_PREFIXES(WakeOnWifiObserverTest, TestWakeOnWifiNoneRemove); | |
| 76 | |
| 67 // Sends the user's preference to shill, updates the timer used by the GCM | 77 // 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 | 78 // client to send heartbeats, and tells |extension_event_observer_| to block |
| 69 // (or not block) suspends based on the value of |current_feature_|. | 79 // (or not block) suspends based on the value of |current_feature_|. |
| 70 void HandleWakeOnWifiFeatureUpdated(); | 80 void HandleWakeOnWifiFeatureUpdated(); |
| 71 | 81 |
| 72 // Requests all the properties for the wifi device from shill. | 82 // Requests all the properties for the wifi device from shill. |
| 73 void GetWifiDeviceProperties(); | 83 void GetWifiDeviceProperties(); |
| 74 | 84 |
| 75 // Callback for getting the Wi-Fi device properties. | 85 // Callback for getting the Wi-Fi device properties. |
| 76 void GetDevicePropertiesCallback(const std::string& device_path, | 86 void GetDevicePropertiesCallback(const std::string& device_path, |
| 77 const base::DictionaryValue& properties); | 87 const base::DictionaryValue& properties); |
| 78 | 88 |
| 79 // Called when a Profile is added or destroyed. | 89 // Called when a Profile is added or destroyed. |
| 80 void OnProfileAdded(Profile* profile); | 90 void OnProfileAdded(Profile* profile); |
| 81 void OnProfileDestroyed(Profile* profile); | 91 void OnProfileDestroyed(Profile* profile); |
| 82 | 92 |
| 83 WakeOnWifiFeature current_feature_; | 93 WakeOnWifiFeature current_feature_; |
| 84 | 94 |
| 85 // Set to true once we have received the properties for the wifi device from | 95 // Set to true once we have received the properties for the wifi device from |
| 86 // shill. | 96 // shill. |
| 87 bool wifi_properties_received_; | 97 bool wifi_properties_received_; |
| 88 | 98 |
| 89 class WakeOnPacketConnectionObserver; | 99 // Simple class that listens for a connection to the GCM server and passes the |
| 90 base::ScopedPtrHashMap<Profile*, | 100 // connection information down to shill. Each profile gets its own instance |
| 91 std::unique_ptr<WakeOnPacketConnectionObserver>> | 101 // of this class. |
| 92 connection_observers_; | 102 class ConnectionObserver : public gcm::GCMConnectionObserver { |
| 103 public: | |
| 104 ConnectionObserver(Profile* profile, | |
| 105 bool wifi_properties_received, | |
| 106 WakeOnWifiManager::WakeOnWifiFeature feature, | |
| 107 NetworkDeviceHandler* network_device_handler); | |
| 108 ~ConnectionObserver() override; | |
| 109 | |
| 110 void HandleWifiDevicePropertiesReady(); | |
| 111 | |
| 112 // gcm::GCMConnectionObserver overrides: | |
| 113 void OnConnected(const net::IPEndPoint& ip_endpoint) override; | |
| 114 void OnDisconnected() override; | |
| 115 | |
| 116 void set_feature(const WakeOnWifiFeature feature) { feature_ = feature; } | |
| 117 | |
| 118 private: | |
| 119 FRIEND_TEST_ALL_PREFIXES(WakeOnWifiObserverTest, TestWakeOnWifiPacketAdd); | |
| 120 FRIEND_TEST_ALL_PREFIXES(WakeOnWifiObserverTest, | |
| 121 TestWakeOnWifiPacketRemove); | |
| 122 FRIEND_TEST_ALL_PREFIXES(WakeOnWifiObserverTest, TestWakeOnWifiNoneAdd); | |
| 123 FRIEND_TEST_ALL_PREFIXES(WakeOnWifiObserverTest, TestWakeOnWifiNoneRemove); | |
| 124 | |
| 125 void AddWakeOnPacketConnection(); | |
| 126 void RemoveWakeOnPacketConnection(); | |
| 127 | |
| 128 Profile* profile_; | |
| 129 net::IPEndPoint ip_endpoint_; | |
| 130 bool wifi_properties_received_; | |
| 131 WakeOnWifiManager::WakeOnWifiFeature feature_; | |
| 132 NetworkDeviceHandler* network_device_handler_; | |
| 133 | |
| 134 DISALLOW_COPY_AND_ASSIGN(ConnectionObserver); | |
| 135 }; | |
|
stevenjb
2016/04/19 23:46:15
Since we need to expose this in the header for tes
malaykeshav
2016/04/20 19:48:42
Done
| |
| 136 | |
| 137 std::map<Profile*, std::unique_ptr<ConnectionObserver>> connection_observers_; | |
| 93 | 138 |
| 94 std::unique_ptr<ExtensionEventObserver> extension_event_observer_; | 139 std::unique_ptr<ExtensionEventObserver> extension_event_observer_; |
| 95 | 140 |
| 96 content::NotificationRegistrar registrar_; | 141 content::NotificationRegistrar registrar_; |
| 97 | 142 |
| 98 base::WeakPtrFactory<WakeOnWifiManager> weak_ptr_factory_; | 143 base::WeakPtrFactory<WakeOnWifiManager> weak_ptr_factory_; |
| 99 | 144 |
| 100 DISALLOW_COPY_AND_ASSIGN(WakeOnWifiManager); | 145 DISALLOW_COPY_AND_ASSIGN(WakeOnWifiManager); |
| 101 }; | 146 }; |
| 102 | 147 |
| 103 } // namespace chromeos | 148 } // namespace chromeos |
| 104 | 149 |
| 105 #endif // CHROME_BROWSER_CHROMEOS_NET_WAKE_ON_WIFI_MANAGER_H_ | 150 #endif // CHROME_BROWSER_CHROMEOS_NET_WAKE_ON_WIFI_MANAGER_H_ |
| OLD | NEW |