Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Side by Side Diff: chrome/browser/chromeos/net/wake_on_wifi_manager.h

Issue 1891633002: Remove unnecessary calls to AddWakeOnPaketConnection and RemoveWakeOnPacketConnection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 17
18 class Profile; 18 class Profile;
19 19
20 namespace base { 20 namespace base {
21 class DictionaryValue; 21 class DictionaryValue;
22 } 22 }
23 23
24 namespace chromeos { 24 namespace chromeos {
25 25
26 class WakeOnWifiConnectionObserver;
27
26 // This class is responsible for managing the various wake-on-wifi related bits 28 // 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 29 // 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 30 // 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 31 // servers and sending that connection information down to shill. This class is
30 // owned by ChromeBrowserMainPartsChromeos. This class is also NOT thread-safe 32 // owned by ChromeBrowserMainPartsChromeos. This class is also NOT thread-safe
31 // and should only be called on the UI thread. 33 // and should only be called on the UI thread.
32 class WakeOnWifiManager : public content::NotificationObserver, 34 class WakeOnWifiManager : public content::NotificationObserver,
33 public NetworkStateHandlerObserver { 35 public NetworkStateHandlerObserver {
34 public: 36 public:
35 enum WakeOnWifiFeature { 37 enum WakeOnWifiFeature {
36 WAKE_ON_WIFI_NONE = 0x00, 38 WAKE_ON_WIFI_NONE = 0x00,
37 WAKE_ON_WIFI_PACKET = 0x01, 39 WAKE_ON_WIFI_PACKET = 0x01,
38 WAKE_ON_WIFI_DARKCONNECT = 0x02, 40 WAKE_ON_WIFI_DARKCONNECT = 0x02,
39 WAKE_ON_WIFI_PACKET_AND_DARKCONNECT = 0x03, 41 WAKE_ON_WIFI_PACKET_AND_DARKCONNECT = 0x03,
40 NOT_SUPPORTED = 0x04, 42 NOT_SUPPORTED = 0x04,
41 INVALID = 0x08, 43 INVALID = 0x08,
42 }; 44 };
43 45
44 static WakeOnWifiManager* Get(); 46 static WakeOnWifiManager* Get();
47 static bool IsWakeOnPacketEnabled(WakeOnWifiFeature feature);
45 48
46 WakeOnWifiManager(); 49 WakeOnWifiManager();
47 ~WakeOnWifiManager() override; 50 ~WakeOnWifiManager() override;
48 51
49 // Should be called whenever the primary user changes their preference for the 52 // Should be called whenever the primary user changes their preference for the
50 // wake-on-wifi features that should be enabled. 53 // wake-on-wifi features that should be enabled.
51 void OnPreferenceChanged(WakeOnWifiFeature feature); 54 void OnPreferenceChanged(WakeOnWifiFeature feature);
52 55
53 // Returns true if wake-on-wifi features are supported. Returns false if we 56 // 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. 57 // have not yet determined whether wake-on-wifi features are supported.
55 bool WakeOnWifiSupported(); 58 bool WakeOnWifiSupported();
56 59
57 // content::NotificationObserver override. 60 // content::NotificationObserver override.
58 void Observe(int type, 61 void Observe(int type,
59 const content::NotificationSource& source, 62 const content::NotificationSource& source,
60 const content::NotificationDetails& details) override; 63 const content::NotificationDetails& details) override;
61 64
62 // NetworkStateHandlerObserver overrides. 65 // NetworkStateHandlerObserver overrides.
63 void DeviceListChanged() override; 66 void DeviceListChanged() override;
64 void DevicePropertiesUpdated(const DeviceState* device) override; 67 void DevicePropertiesUpdated(const DeviceState* device) override;
65 68
66 private: 69 private:
70 FRIEND_TEST_ALL_PREFIXES(WakeOnWifiObserverTest, TestWakeOnWifiPacketAdd);
71 FRIEND_TEST_ALL_PREFIXES(WakeOnWifiObserverTest, TestWakeOnWifiPacketRemove);
72 FRIEND_TEST_ALL_PREFIXES(WakeOnWifiObserverTest, TestWakeOnWifiNoneAdd);
73 FRIEND_TEST_ALL_PREFIXES(WakeOnWifiObserverTest, TestWakeOnWifiNoneRemove);
74
67 // Sends the user's preference to shill, updates the timer used by the GCM 75 // 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 76 // client to send heartbeats, and tells |extension_event_observer_| to block
69 // (or not block) suspends based on the value of |current_feature_|. 77 // (or not block) suspends based on the value of |current_feature_|.
70 void HandleWakeOnWifiFeatureUpdated(); 78 void HandleWakeOnWifiFeatureUpdated();
71 79
72 // Requests all the properties for the wifi device from shill. 80 // Requests all the properties for the wifi device from shill.
73 void GetWifiDeviceProperties(); 81 void GetWifiDeviceProperties();
74 82
75 // Callback for getting the Wi-Fi device properties. 83 // Callback for getting the Wi-Fi device properties.
76 void GetDevicePropertiesCallback(const std::string& device_path, 84 void GetDevicePropertiesCallback(const std::string& device_path,
77 const base::DictionaryValue& properties); 85 const base::DictionaryValue& properties);
78 86
79 // Called when a Profile is added or destroyed. 87 // Called when a Profile is added or destroyed.
80 void OnProfileAdded(Profile* profile); 88 void OnProfileAdded(Profile* profile);
81 void OnProfileDestroyed(Profile* profile); 89 void OnProfileDestroyed(Profile* profile);
82 90
83 WakeOnWifiFeature current_feature_; 91 WakeOnWifiFeature current_feature_;
84 92
85 // Set to true once we have received the properties for the wifi device from 93 // Set to true once we have received the properties for the wifi device from
86 // shill. 94 // shill.
87 bool wifi_properties_received_; 95 bool wifi_properties_received_;
88 96
89 class WakeOnPacketConnectionObserver; 97 std::map<Profile*,
90 base::ScopedPtrHashMap<Profile*, 98 std::unique_ptr<WakeOnWifiConnectionObserver>> connection_observers_;
91 std::unique_ptr<WakeOnPacketConnectionObserver>>
92 connection_observers_;
93 99
94 std::unique_ptr<ExtensionEventObserver> extension_event_observer_; 100 std::unique_ptr<ExtensionEventObserver> extension_event_observer_;
95 101
96 content::NotificationRegistrar registrar_; 102 content::NotificationRegistrar registrar_;
97 103
98 base::WeakPtrFactory<WakeOnWifiManager> weak_ptr_factory_; 104 base::WeakPtrFactory<WakeOnWifiManager> weak_ptr_factory_;
99 105
100 DISALLOW_COPY_AND_ASSIGN(WakeOnWifiManager); 106 DISALLOW_COPY_AND_ASSIGN(WakeOnWifiManager);
101 }; 107 };
102 108
103 } // namespace chromeos 109 } // namespace chromeos
104 110
105 #endif // CHROME_BROWSER_CHROMEOS_NET_WAKE_ON_WIFI_MANAGER_H_ 111 #endif // CHROME_BROWSER_CHROMEOS_NET_WAKE_ON_WIFI_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/net/wake_on_wifi_connection_observer.cc ('k') | chrome/browser/chromeos/net/wake_on_wifi_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698