| Index: chrome/browser/chromeos/net/wake_on_wifi_manager.cc
|
| diff --git a/chrome/browser/chromeos/net/wake_on_wifi_manager.cc b/chrome/browser/chromeos/net/wake_on_wifi_manager.cc
|
| index 98db612dcdec85f0ad943689dcb51ece89f8950f..cf9aedebdec14ebbc0fba6821d3fa091856c4c2d 100644
|
| --- a/chrome/browser/chromeos/net/wake_on_wifi_manager.cc
|
| +++ b/chrome/browser/chromeos/net/wake_on_wifi_manager.cc
|
| @@ -8,7 +8,6 @@
|
| #include <string>
|
|
|
| #include "base/bind.h"
|
| -#include "base/containers/scoped_ptr_hash_map.h"
|
| #include "base/logging.h"
|
| #include "base/macros.h"
|
| #include "base/memory/ptr_util.h"
|
| @@ -20,7 +19,6 @@
|
| #include "chromeos/chromeos_switches.h"
|
| #include "chromeos/login/login_state.h"
|
| #include "chromeos/network/device_state.h"
|
| -#include "chromeos/network/network_device_handler.h"
|
| #include "chromeos/network/network_handler.h"
|
| #include "chromeos/network/network_state_handler.h"
|
| #include "chromeos/network/network_type_pattern.h"
|
| @@ -73,86 +71,78 @@ WakeOnWifiManager* g_wake_on_wifi_manager = NULL;
|
|
|
| } // namespace
|
|
|
| -// Simple class that listens for a connection to the GCM server and passes the
|
| -// connection information down to shill. Each profile gets its own instance of
|
| -// this class.
|
| -class WakeOnWifiManager::WakeOnPacketConnectionObserver
|
| - : public gcm::GCMConnectionObserver {
|
| - public:
|
| - WakeOnPacketConnectionObserver(Profile* profile,
|
| - bool wifi_properties_received)
|
| - : profile_(profile),
|
| - ip_endpoint_(net::IPEndPoint()),
|
| - wifi_properties_received_(wifi_properties_received) {
|
| - gcm::GCMProfileServiceFactory::GetForProfile(profile_)
|
| - ->driver()
|
| - ->AddConnectionObserver(this);
|
| - }
|
| -
|
| - ~WakeOnPacketConnectionObserver() override {
|
| - if (!(ip_endpoint_ == net::IPEndPoint()))
|
| - OnDisconnected();
|
| -
|
| - gcm::GCMProfileServiceFactory::GetForProfile(profile_)
|
| - ->driver()
|
| - ->RemoveConnectionObserver(this);
|
| - }
|
| -
|
| - void HandleWifiDevicePropertiesReady() {
|
| - wifi_properties_received_ = true;
|
| +WakeOnWifiManager::ConnectionObserver::ConnectionObserver(
|
| + Profile* profile,
|
| + bool wifi_properties_received,
|
| + WakeOnWifiManager::WakeOnWifiFeature feature,
|
| + NetworkDeviceHandler* network_device_handler)
|
| + : profile_(profile),
|
| + ip_endpoint_(net::IPEndPoint()),
|
| + wifi_properties_received_(wifi_properties_received),
|
| + feature_(feature),
|
| + network_device_handler_(network_device_handler) {
|
| + gcm::GCMProfileServiceFactory::GetForProfile(profile_)
|
| + ->driver()
|
| + ->AddConnectionObserver(this);
|
| +}
|
|
|
| - // IPEndPoint doesn't implement operator!=
|
| - if (ip_endpoint_ == net::IPEndPoint())
|
| - return;
|
| +WakeOnWifiManager::ConnectionObserver::~ConnectionObserver() {
|
| + if (!(ip_endpoint_ == net::IPEndPoint()))
|
| + OnDisconnected();
|
|
|
| - AddWakeOnPacketConnection();
|
| - }
|
| + gcm::GCMProfileServiceFactory::GetForProfile(profile_)
|
| + ->driver()
|
| + ->RemoveConnectionObserver(this);
|
| +}
|
|
|
| - // gcm::GCMConnectionObserver overrides.
|
| +void WakeOnWifiManager::ConnectionObserver::HandleWifiDevicePropertiesReady() {
|
| + wifi_properties_received_ = true;
|
|
|
| - void OnConnected(const net::IPEndPoint& ip_endpoint) override {
|
| - ip_endpoint_ = ip_endpoint;
|
| + // IPEndPoint doesn't implement operator!=
|
| + if (ip_endpoint_ == net::IPEndPoint())
|
| + return;
|
|
|
| - if (wifi_properties_received_)
|
| - AddWakeOnPacketConnection();
|
| - }
|
| + AddWakeOnPacketConnection();
|
| +}
|
|
|
| - void OnDisconnected() override {
|
| - if (ip_endpoint_ == net::IPEndPoint()) {
|
| - VLOG(1) << "Received GCMConnectionObserver::OnDisconnected without a "
|
| - << "valid IPEndPoint.";
|
| - return;
|
| - }
|
| +void WakeOnWifiManager::ConnectionObserver::OnConnected(
|
| + const net::IPEndPoint& ip_endpoint) {
|
| + ip_endpoint_ = ip_endpoint;
|
|
|
| - if (wifi_properties_received_)
|
| - RemoveWakeOnPacketConnection();
|
| + if (wifi_properties_received_)
|
| + AddWakeOnPacketConnection();
|
| +}
|
|
|
| - ip_endpoint_ = net::IPEndPoint();
|
| +void WakeOnWifiManager::ConnectionObserver::OnDisconnected() {
|
| + if (ip_endpoint_ == net::IPEndPoint()) {
|
| + VLOG(1) << "Received GCMConnectionObserver::OnDisconnected without a "
|
| + << "valid IPEndPoint.";
|
| + return;
|
| }
|
|
|
| - private:
|
| - void AddWakeOnPacketConnection() {
|
| - NetworkHandler::Get()
|
| - ->network_device_handler()
|
| - ->AddWifiWakeOnPacketConnection(ip_endpoint_,
|
| - base::Bind(&base::DoNothing),
|
| - network_handler::ErrorCallback());
|
| - }
|
| + if (wifi_properties_received_)
|
| + RemoveWakeOnPacketConnection();
|
|
|
| - void RemoveWakeOnPacketConnection() {
|
| - NetworkHandler::Get()
|
| - ->network_device_handler()
|
| - ->RemoveWifiWakeOnPacketConnection(ip_endpoint_,
|
| - base::Bind(&base::DoNothing),
|
| - network_handler::ErrorCallback());
|
| - }
|
| + ip_endpoint_ = net::IPEndPoint();
|
| +}
|
|
|
| - Profile* profile_;
|
| - net::IPEndPoint ip_endpoint_;
|
| - bool wifi_properties_received_;
|
| +void WakeOnWifiManager::ConnectionObserver::AddWakeOnPacketConnection() {
|
| + if (!IsWakeOnPacketEnabled(WakeOnWifiManager::ConnectionObserver::feature_))
|
| + return;
|
| + network_device_handler_
|
| + ->AddWifiWakeOnPacketConnection(ip_endpoint_,
|
| + base::Bind(&base::DoNothing),
|
| + network_handler::ErrorCallback());
|
| +}
|
|
|
| - DISALLOW_COPY_AND_ASSIGN(WakeOnPacketConnectionObserver);
|
| -};
|
| +void WakeOnWifiManager::ConnectionObserver::RemoveWakeOnPacketConnection() {
|
| + if (!IsWakeOnPacketEnabled(WakeOnWifiManager::ConnectionObserver::feature_))
|
| + return;
|
| + network_device_handler_
|
| + ->RemoveWifiWakeOnPacketConnection(ip_endpoint_,
|
| + base::Bind(&base::DoNothing),
|
| + network_handler::ErrorCallback());
|
| +}
|
|
|
| // static
|
| WakeOnWifiManager* WakeOnWifiManager::Get() {
|
| @@ -211,6 +201,11 @@ void WakeOnWifiManager::OnPreferenceChanged(
|
|
|
| current_feature_ = feature;
|
|
|
| + // Update value of member variable feature for all connection observers.
|
| + for (const auto& kv_pair : connection_observers_) {
|
| + kv_pair.second->set_feature(current_feature_);
|
| + }
|
| +
|
| if (wifi_properties_received_)
|
| HandleWakeOnWifiFeatureUpdated();
|
| }
|
| @@ -325,25 +320,26 @@ void WakeOnWifiManager::GetDevicePropertiesCallback(
|
| network_handler::ErrorCallback());
|
|
|
| for (const auto& kv_pair : connection_observers_) {
|
| - WakeOnPacketConnectionObserver* observer = kv_pair.second;
|
| - observer->HandleWifiDevicePropertiesReady();
|
| + kv_pair.second->HandleWifiDevicePropertiesReady();
|
| }
|
| }
|
|
|
| void WakeOnWifiManager::OnProfileAdded(Profile* profile) {
|
| - // add will do nothing if |profile| already exists in |connection_observers_|.
|
| - auto result = connection_observers_.add(
|
| - profile,
|
| - base::WrapUnique(new WakeOnWifiManager::WakeOnPacketConnectionObserver(
|
| - profile, wifi_properties_received_)));
|
| -
|
| - if (result.second) {
|
| - // This is a profile we haven't seen before.
|
| - gcm::GCMProfileServiceFactory::GetForProfile(profile)
|
| - ->driver()
|
| - ->WakeFromSuspendForHeartbeat(
|
| - IsWakeOnPacketEnabled(current_feature_));
|
| - }
|
| + auto result = connection_observers_.find(profile);
|
| +
|
| + // Only add the profile if it is not already present.
|
| + if (result != connection_observers_.end())
|
| + return;
|
| +
|
| + connection_observers_[profile] =
|
| + base::WrapUnique(new WakeOnWifiManager::ConnectionObserver(
|
| + profile, wifi_properties_received_, current_feature_,
|
| + NetworkHandler::Get()->network_device_handler()));
|
| +
|
| + gcm::GCMProfileServiceFactory::GetForProfile(profile)
|
| + ->driver()
|
| + ->WakeFromSuspendForHeartbeat(
|
| + IsWakeOnPacketEnabled(current_feature_));
|
| }
|
|
|
| void WakeOnWifiManager::OnProfileDestroyed(Profile* profile) {
|
|
|