diff options
29 files changed, 617 insertions, 231 deletions
diff --git a/chrome/browser/chromeos/chrome_browser_main_chromeos.cc b/chrome/browser/chromeos/chrome_browser_main_chromeos.cc index 8758015..a5df15a 100644 --- a/chrome/browser/chromeos/chrome_browser_main_chromeos.cc +++ b/chrome/browser/chromeos/chrome_browser_main_chromeos.cc @@ -54,6 +54,7 @@ #include "chrome/browser/chromeos/login/wizard_controller.h" #include "chrome/browser/chromeos/memory/oom_priority_manager.h" #include "chrome/browser/chromeos/net/network_portal_detector_impl.h" +#include "chrome/browser/chromeos/net/wake_on_wifi_manager.h" #include "chrome/browser/chromeos/options/cert_library.h" #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_factory.h" #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" @@ -366,6 +367,8 @@ void ChromeBrowserMainPartsChromeos::PreMainMessageLoopRun() { DeviceOAuth2TokenServiceFactory::Initialize(); + wake_on_wifi_manager_.reset(new WakeOnWifiManager()); + ChromeBrowserMainPartsLinux::PreMainMessageLoopRun(); } @@ -724,6 +727,7 @@ void ChromeBrowserMainPartsChromeos::PostMainMessageLoopRun() { power_prefs_.reset(); renderer_freezer_.reset(); light_bar_.reset(); + wake_on_wifi_manager_.reset(); // Let the ScreenLocker unregister itself from SessionManagerClient before // DBusThreadManager is shut down. diff --git a/chrome/browser/chromeos/chrome_browser_main_chromeos.h b/chrome/browser/chromeos/chrome_browser_main_chromeos.h index 828bd5b..ff833a1 100644 --- a/chrome/browser/chromeos/chrome_browser_main_chromeos.h +++ b/chrome/browser/chromeos/chrome_browser_main_chromeos.h @@ -34,6 +34,7 @@ class PowerPrefs; class RendererFreezer; class SessionManagerObserver; class SwapMetrics; +class WakeOnWifiManager; namespace default_app_order { class ExternalLoader; @@ -75,6 +76,7 @@ class ChromeBrowserMainPartsChromeos : public ChromeBrowserMainPartsLinux { scoped_ptr<DataPromoNotification> data_promo_notification_; scoped_ptr<RendererFreezer> renderer_freezer_; scoped_ptr<LightBar> light_bar_; + scoped_ptr<WakeOnWifiManager> wake_on_wifi_manager_; scoped_ptr<internal::DBusServices> dbus_services_; diff --git a/chrome/browser/chromeos/net/wake_on_wifi_manager.cc b/chrome/browser/chromeos/net/wake_on_wifi_manager.cc new file mode 100644 index 0000000..d163378 --- /dev/null +++ b/chrome/browser/chromeos/net/wake_on_wifi_manager.cc @@ -0,0 +1,213 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/chromeos/net/wake_on_wifi_manager.h" + +#include <string> + +#include "base/bind.h" +#include "base/command_line.h" +#include "base/containers/scoped_ptr_hash_map.h" +#include "base/logging.h" +#include "base/macros.h" +#include "base/memory/scoped_ptr.h" +#include "base/sys_info.h" +#include "chrome/browser/chrome_notification_types.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/services/gcm/gcm_profile_service.h" +#include "chrome/browser/services/gcm/gcm_profile_service_factory.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" +#include "components/gcm_driver/gcm_connection_observer.h" +#include "components/gcm_driver/gcm_driver.h" +#include "content/public/browser/browser_thread.h" +#include "content/public/browser/notification_service.h" +#include "content/public/browser/notification_source.h" +#include "net/base/ip_endpoint.h" +#include "third_party/cros_system_api/dbus/service_constants.h" + +namespace chromeos { + +namespace { + +const char kWakeOnNone[] = "none"; +const char kWakeOnPacket[] = "packet"; +const char kWakeOnSsid[] = "ssid"; +const char kWakeOnPacketAndSsid[] = "packet_and_ssid"; + +std::string WakeOnWifiFeatureToString( + WakeOnWifiManager::WakeOnWifiFeature feature) { + switch (feature) { + case WakeOnWifiManager::WAKE_ON_NONE: + return kWakeOnNone; + case WakeOnWifiManager::WAKE_ON_PACKET: + return kWakeOnPacket; + case WakeOnWifiManager::WAKE_ON_SSID: + return kWakeOnSsid; + case WakeOnWifiManager::WAKE_ON_PACKET_AND_SSID: + return kWakeOnPacketAndSsid; + } + + NOTREACHED() << "Unknown wake on wifi feature: " << feature; + return std::string(); +} + +// Weak pointer. This class is owned by ChromeBrowserMainPartsChromeos. +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: + explicit WakeOnPacketConnectionObserver(Profile* profile) + : profile_(profile), + ip_endpoint_(net::IPEndPoint()) { + gcm::GCMProfileServiceFactory::GetForProfile(profile_) + ->driver() + ->AddConnectionObserver(this); + } + + ~WakeOnPacketConnectionObserver() override { + if (!(ip_endpoint_ == net::IPEndPoint())) + OnDisconnected(); + + gcm::GCMProfileServiceFactory::GetForProfile(profile_) + ->driver() + ->RemoveConnectionObserver(this); + } + + // gcm::GCMConnectionObserver overrides. + + void OnConnected(const net::IPEndPoint& ip_endpoint) override { + ip_endpoint_ = ip_endpoint; + + NetworkHandler::Get() + ->network_device_handler() + ->AddWifiWakeOnPacketConnection( + ip_endpoint_, + base::Bind(&base::DoNothing), + network_handler::ErrorCallback()); + } + + void OnDisconnected() override { + if (ip_endpoint_ == net::IPEndPoint()) { + LOG(WARNING) << "Received GCMConnectionObserver::OnDisconnected without " + << "a valid IPEndPoint."; + return; + } + + NetworkHandler::Get() + ->network_device_handler() + ->RemoveWifiWakeOnPacketConnection( + ip_endpoint_, + base::Bind(&base::DoNothing), + network_handler::ErrorCallback()); + + ip_endpoint_ = net::IPEndPoint(); + } + + private: + Profile* profile_; + net::IPEndPoint ip_endpoint_; + + DISALLOW_COPY_AND_ASSIGN(WakeOnPacketConnectionObserver); +}; + +// static +WakeOnWifiManager* WakeOnWifiManager::Get() { + DCHECK(g_wake_on_wifi_manager); + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + return g_wake_on_wifi_manager; +} + +WakeOnWifiManager::WakeOnWifiManager() { + // This class must be constructed before any users are logged in, i.e., before + // any profiles are created or added to the ProfileManager. Additionally, + // IsUserLoggedIn always returns true when we are not running on a Chrome OS + // device so this check should only run on real devices. + CHECK(!base::SysInfo::IsRunningOnChromeOS() || + !LoginState::Get()->IsUserLoggedIn()); + DCHECK(!g_wake_on_wifi_manager); + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + + g_wake_on_wifi_manager = this; + + registrar_.Add(this, + chrome::NOTIFICATION_PROFILE_ADDED, + content::NotificationService::AllBrowserContextsAndSources()); + registrar_.Add(this, + chrome::NOTIFICATION_PROFILE_DESTROYED, + content::NotificationService::AllBrowserContextsAndSources()); + + NetworkHandler::Get() + ->network_device_handler() + ->RemoveAllWifiWakeOnPacketConnections( + base::Bind(&base::DoNothing), + network_handler::ErrorCallback()); +} + +WakeOnWifiManager::~WakeOnWifiManager() { + DCHECK(g_wake_on_wifi_manager); + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + g_wake_on_wifi_manager = NULL; +} + +void WakeOnWifiManager::OnPreferenceChanged( + WakeOnWifiManager::WakeOnWifiFeature feature) { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + const DeviceState* device = + NetworkHandler::Get()->network_state_handler()->GetDeviceStateByType( + NetworkTypePattern::WiFi()); + if (!device) + return; + + std::string feature_string(WakeOnWifiFeatureToString(feature)); + DCHECK(!feature_string.empty()); + + NetworkHandler::Get()->network_device_handler()->SetDeviceProperty( + device->path(), + shill::kWakeOnWiFiFeaturesEnabledProperty, + base::StringValue(feature_string), + base::Bind(&base::DoNothing), + network_handler::ErrorCallback()); +} + +void WakeOnWifiManager::Observe(int type, + const content::NotificationSource& source, + const content::NotificationDetails& details) { + switch (type) { + case chrome::NOTIFICATION_PROFILE_ADDED: { + OnProfileAdded(content::Source<Profile>(source).ptr()); + break; + } + case chrome::NOTIFICATION_PROFILE_DESTROYED: { + OnProfileDestroyed(content::Source<Profile>(source).ptr()); + break; + } + default: + NOTREACHED(); + } +} + +void WakeOnWifiManager::OnProfileAdded(Profile* profile) { + // add will do nothing if |profile| already exists in |connection_observers_|. + connection_observers_.add( + profile, + make_scoped_ptr( + new WakeOnWifiManager::WakeOnPacketConnectionObserver(profile))); +} + +void WakeOnWifiManager::OnProfileDestroyed(Profile* profile) { + connection_observers_.erase(profile); +} + +} // namespace chromeos diff --git a/chrome/browser/chromeos/net/wake_on_wifi_manager.h b/chrome/browser/chromeos/net/wake_on_wifi_manager.h new file mode 100644 index 0000000..bdbe236 --- /dev/null +++ b/chrome/browser/chromeos/net/wake_on_wifi_manager.h @@ -0,0 +1,61 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_CHROMEOS_NET_WAKE_ON_WIFI_MANAGER_H_ +#define CHROME_BROWSER_CHROMEOS_NET_WAKE_ON_WIFI_MANAGER_H_ + +#include "base/containers/scoped_ptr_hash_map.h" +#include "base/macros.h" +#include "content/public/browser/notification_observer.h" +#include "content/public/browser/notification_registrar.h" + +class Profile; + +namespace chromeos { + +// This class is responsible for managing the various wake-on-wifi related bits +// of functionality in chrome. It is responsible for communicating the user's +// preferences to shill as well as listening for connections to the Google GCM +// servers and sending that connection information down to shill. This class is +// owned by ChromeBrowserMainPartsChromeos. This class is also NOT thread-safe +// and should only be called on the UI thread. +class WakeOnWifiManager : public content::NotificationObserver { + public: + enum WakeOnWifiFeature { + WAKE_ON_NONE = 0, + WAKE_ON_PACKET = 1, + WAKE_ON_SSID = 2, + WAKE_ON_PACKET_AND_SSID = 3, + }; + + static WakeOnWifiManager* Get(); + + WakeOnWifiManager(); + ~WakeOnWifiManager() override; + + // Should be called whenever the primary user changes their preference for the + // wake-on-wifi features that should be enabled. + void OnPreferenceChanged(WakeOnWifiFeature feature); + + // content::NotificationObserver override. + void Observe(int type, + const content::NotificationSource& source, + const content::NotificationDetails& details) override; + + private: + void OnProfileAdded(Profile* profile); + void OnProfileDestroyed(Profile* profile); + + class WakeOnPacketConnectionObserver; + base::ScopedPtrHashMap<Profile*, WakeOnPacketConnectionObserver> + connection_observers_; + + content::NotificationRegistrar registrar_; + + DISALLOW_COPY_AND_ASSIGN(WakeOnWifiManager); +}; + +} // namespace chromeos + +#endif // CHROME_BROWSER_CHROMEOS_NET_WAKE_ON_WIFI_MANAGER_H_ diff --git a/chrome/browser/chromeos/preferences.cc b/chrome/browser/chromeos/preferences.cc index c95ddba..8d88971 100644 --- a/chrome/browser/chromeos/preferences.cc +++ b/chrome/browser/chromeos/preferences.cc @@ -24,6 +24,7 @@ #include "chrome/browser/chromeos/drive/file_system_util.h" #include "chrome/browser/chromeos/input_method/input_method_util.h" #include "chrome/browser/chromeos/login/session/user_session_manager.h" +#include "chrome/browser/chromeos/net/wake_on_wifi_manager.h" #include "chrome/browser/chromeos/profiles/profile_helper.h" #include "chrome/browser/chromeos/system/input_device_settings.h" #include "chrome/browser/download/download_prefs.h" @@ -274,6 +275,16 @@ void Preferences::RegisterProfilePrefs( language_prefs::kXkbAutoRepeatIntervalInMs, user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); + // We don't sync wake-on-wifi related prefs because they are device specific. + // TODO(chirantan): Default this to on when we are ready to launch. + registry->RegisterIntegerPref( + prefs::kWakeOnWiFiEnabled, + base::CommandLine::ForCurrentProcess()->HasSwitch( + switches::kWakeOnPackets) + ? WakeOnWifiManager::WAKE_ON_PACKET_AND_SSID + : WakeOnWifiManager::WAKE_ON_NONE, + user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); + // Mobile plan notifications default to on. registry->RegisterBooleanPref( prefs::kShowPlanNotifications, @@ -348,6 +359,8 @@ void Preferences::InitUserPrefs(PrefServiceSyncable* prefs) { prefs::kLanguageXkbAutoRepeatDelay, prefs, callback); xkb_auto_repeat_interval_pref_.Init( prefs::kLanguageXkbAutoRepeatInterval, prefs, callback); + + wake_on_wifi_enabled_.Init(prefs::kWakeOnWiFiEnabled, prefs, callback); } void Preferences::Init(Profile* profile, const user_manager::User* user) { @@ -553,6 +566,13 @@ void Preferences::ApplyPreferences(ApplyReason reason, UpdateAutoRepeatRate(); } + if (user_is_primary_ && (reason != REASON_PREF_CHANGED || + pref_name == prefs::kWakeOnWiFiEnabled)) { + WakeOnWifiManager::Get()->OnPreferenceChanged( + static_cast<WakeOnWifiManager::WakeOnWifiFeature>( + wake_on_wifi_enabled_.GetValue())); + } + if (reason == REASON_INITIALIZATION) SetInputMethodList(); diff --git a/chrome/browser/chromeos/preferences.h b/chrome/browser/chromeos/preferences.h index ab6fd3c..7ed406d 100644 --- a/chrome/browser/chromeos/preferences.h +++ b/chrome/browser/chromeos/preferences.h @@ -140,6 +140,8 @@ class Preferences : public PrefServiceSyncableObserver, IntegerPrefMember xkb_auto_repeat_delay_pref_; IntegerPrefMember xkb_auto_repeat_interval_pref_; + IntegerPrefMember wake_on_wifi_enabled_; + // User owning these preferences. const user_manager::User* user_; diff --git a/chrome/browser/services/gcm/chromeos_gcm_connection_observer.cc b/chrome/browser/services/gcm/chromeos_gcm_connection_observer.cc deleted file mode 100644 index 99a1873..0000000 --- a/chrome/browser/services/gcm/chromeos_gcm_connection_observer.cc +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (c) 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/services/gcm/chromeos_gcm_connection_observer.h" - -#include "base/callback.h" -#include "base/logging.h" -#include "chromeos/dbus/dbus_thread_manager.h" -#include "chromeos/dbus/shill_manager_client.h" - -namespace gcm { - -ChromeOSGCMConnectionObserver::ChromeOSGCMConnectionObserver() { -} - -ChromeOSGCMConnectionObserver::~ChromeOSGCMConnectionObserver() { -} - -// static -void ChromeOSGCMConnectionObserver::ErrorCallback( - const std::string& error_name, - const std::string& error) { - LOG(ERROR) << "GCM D-Bus method error " << error_name << ": " << error; -} - -void ChromeOSGCMConnectionObserver::OnConnected( - const net::IPEndPoint& ip_endpoint) { - ip_endpoint_ = ip_endpoint; - chromeos::DBusThreadManager::Get()-> - GetShillManagerClient()-> - AddWakeOnPacketConnection( - ip_endpoint, - base::Bind(&base::DoNothing), - base::Bind(&ChromeOSGCMConnectionObserver::ErrorCallback)); -} - -void ChromeOSGCMConnectionObserver::OnDisconnected() { - chromeos::DBusThreadManager::Get()-> - GetShillManagerClient()-> - RemoveWakeOnPacketConnection( - ip_endpoint_, - base::Bind(&base::DoNothing), - base::Bind(&ChromeOSGCMConnectionObserver::ErrorCallback)); -} - -} // namespace gcm diff --git a/chrome/browser/services/gcm/chromeos_gcm_connection_observer.h b/chrome/browser/services/gcm/chromeos_gcm_connection_observer.h deleted file mode 100644 index d444bb1..0000000 --- a/chrome/browser/services/gcm/chromeos_gcm_connection_observer.h +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_SERVICES_GCM_CHROMEOS_GCM_CONNECTION_OBSERVER_H_ -#define CHROME_BROWSER_SERVICES_GCM_CHROMEOS_GCM_CONNECTION_OBSERVER_H_ - -#include "base/compiler_specific.h" -#include "components/gcm_driver/gcm_connection_observer.h" -#include "net/base/ip_endpoint.h" - -namespace gcm { - -class ChromeOSGCMConnectionObserver : public GCMConnectionObserver { - public: - ChromeOSGCMConnectionObserver(); - virtual ~ChromeOSGCMConnectionObserver(); - // gcm::GCMConnectionObserver implementation: - virtual void OnConnected(const net::IPEndPoint& ip_endpoint) override; - virtual void OnDisconnected() override; - - static void ErrorCallback( - const std::string& error_name, - const std::string& error); - - private: - net::IPEndPoint ip_endpoint_; - - DISALLOW_COPY_AND_ASSIGN(ChromeOSGCMConnectionObserver); -}; - -} // namespace gcm - -#endif // CHROME_BROWSER_SERVICES_GCM_CHROMEOS_GCM_CONNECTION_OBSERVER_H_ diff --git a/chrome/browser/services/gcm/gcm_profile_service.cc b/chrome/browser/services/gcm/gcm_profile_service.cc index 018cbe6..0b898ab 100644 --- a/chrome/browser/services/gcm/gcm_profile_service.cc +++ b/chrome/browser/services/gcm/gcm_profile_service.cc @@ -17,9 +17,6 @@ #include "components/gcm_driver/gcm_driver_android.h" #else #include "base/bind.h" -#if defined(OS_CHROMEOS) -#include "chrome/browser/services/gcm/chromeos_gcm_connection_observer.h" -#endif #include "base/files/file_path.h" #include "base/memory/weak_ptr.h" #include "chrome/browser/services/gcm/gcm_account_tracker.h" @@ -166,11 +163,6 @@ GCMProfileService::GCMProfileService( profile_->GetPath().Append(chrome::kGCMStoreDirname), profile_->GetRequestContext()); -#if defined(OS_CHROMEOS) - chromeos_connection_observer_.reset(new gcm::ChromeOSGCMConnectionObserver); - driver_->AddConnectionObserver(chromeos_connection_observer_.get()); -#endif - identity_observer_.reset(new IdentityObserver(profile, driver_.get())); } #endif // defined(OS_ANDROID) @@ -188,10 +180,6 @@ void GCMProfileService::Shutdown() { identity_observer_.reset(); #endif // !defined(OS_ANDROID) if (driver_) { -#if defined(OS_CHROMEOS) - driver_->RemoveConnectionObserver(chromeos_connection_observer_.get()); - chromeos_connection_observer_.reset(); -#endif driver_->Shutdown(); driver_.reset(); } diff --git a/chrome/browser/services/gcm/gcm_profile_service.h b/chrome/browser/services/gcm/gcm_profile_service.h index f6a80d9..436cb68 100644 --- a/chrome/browser/services/gcm/gcm_profile_service.h +++ b/chrome/browser/services/gcm/gcm_profile_service.h @@ -80,9 +80,6 @@ class GCMProfileService : public KeyedService { class IdentityObserver; scoped_ptr<IdentityObserver> identity_observer_; #endif -#if defined(OS_CHROMEOS) - scoped_ptr<GCMConnectionObserver> chromeos_connection_observer_; -#endif DISALLOW_COPY_AND_ASSIGN(GCMProfileService); }; diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 3230ca0..80e5d19 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -2710,8 +2710,6 @@ # support ChromeOS with enable_plugins==0. 'browser/renderer_host/pepper/pepper_platform_verification_message_filter.cc', 'browser/renderer_host/pepper/pepper_platform_verification_message_filter.h', - 'browser/services/gcm/chromeos_gcm_connection_observer.cc', - 'browser/services/gcm/chromeos_gcm_connection_observer.h', ], # Used everywhere but ChromeOS. 'chrome_browser_non_chromeos_sources': [ diff --git a/chrome/chrome_browser_chromeos.gypi b/chrome/chrome_browser_chromeos.gypi index c1484cc..8227c28 100644 --- a/chrome/chrome_browser_chromeos.gypi +++ b/chrome/chrome_browser_chromeos.gypi @@ -660,6 +660,8 @@ 'browser/chromeos/net/onc_utils.h', 'browser/chromeos/net/proxy_config_handler.cc', 'browser/chromeos/net/proxy_config_handler.h', + 'browser/chromeos/net/wake_on_wifi_manager.cc', + 'browser/chromeos/net/wake_on_wifi_manager.h', 'browser/chromeos/offline/offline_load_page.cc', 'browser/chromeos/offline/offline_load_page.h', 'browser/chromeos/options/cert_library.cc', diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc index 78fd32d..e4feac3 100644 --- a/chrome/common/pref_names.cc +++ b/chrome/common/pref_names.cc @@ -835,6 +835,10 @@ const char kFileSystemProviderMounted[] = "file_system_provider.mounted"; // A boolean pref set to true if the virtual keyboard should be enabled. const char kTouchVirtualKeyboardEnabled[] = "ui.touch_virtual_keyboard_enabled"; +// An integer pref that controls the wake on wifi features that should be +// enabled. +const char kWakeOnWiFiEnabled[] = "settings.internet.wake_on_wifi"; + #endif // defined(OS_CHROMEOS) // The disabled messages in IPC logging. diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h index 775bc45..15ede99 100644 --- a/chrome/common/pref_names.h +++ b/chrome/common/pref_names.h @@ -268,6 +268,7 @@ extern const char kTimeOnOobe[]; extern const char kCurrentWallpaperAppName[]; extern const char kFileSystemProviderMounted[]; extern const char kTouchVirtualKeyboardEnabled[]; +extern const char kWakeOnWiFiEnabled[]; #endif // defined(OS_CHROMEOS) extern const char kIpcDisabledMessages[]; extern const char kShowHomeButton[]; diff --git a/chromeos/dbus/fake_shill_device_client.cc b/chromeos/dbus/fake_shill_device_client.cc index 623487b..8a631ad 100644 --- a/chromeos/dbus/fake_shill_device_client.cc +++ b/chromeos/dbus/fake_shill_device_client.cc @@ -16,6 +16,7 @@ #include "dbus/object_path.h" #include "dbus/object_proxy.h" #include "dbus/values_util.h" +#include "net/base/ip_endpoint.h" #include "third_party/cros_system_api/dbus/service_constants.h" namespace chromeos { @@ -31,7 +32,7 @@ void ErrorFunction(const std::string& device_path, << ": " << error_name << " : " << error_message; } -void PostDeviceNotFoundError( +void PostNotFoundError( const ShillDeviceClient::ErrorCallback& error_callback) { std::string error_message("Failed"); base::MessageLoop::current()->PostTask( @@ -91,7 +92,7 @@ void FakeShillDeviceClient::SetProperty(const dbus::ObjectPath& device_path, base::DictionaryValue* device_properties = NULL; if (!stub_devices_.GetDictionaryWithoutPathExpansion(device_path.value(), &device_properties)) { - PostDeviceNotFoundError(error_callback); + PostNotFoundError(error_callback); return; } device_properties->SetWithoutPathExpansion(name, value.DeepCopy()); @@ -141,7 +142,7 @@ void FakeShillDeviceClient::RequirePin(const dbus::ObjectPath& device_path, base::DictionaryValue* device_properties = NULL; if (!stub_devices_.GetDictionaryWithoutPathExpansion(device_path.value(), &device_properties)) { - PostDeviceNotFoundError(error_callback); + PostNotFoundError(error_callback); return; } base::DictionaryValue* simlock_dict = NULL; @@ -174,7 +175,7 @@ void FakeShillDeviceClient::EnterPin(const dbus::ObjectPath& device_path, return; } if (!stub_devices_.HasKey(device_path.value())) { - PostDeviceNotFoundError(error_callback); + PostNotFoundError(error_callback); return; } base::MessageLoop::current()->PostTask(FROM_HERE, callback); @@ -187,7 +188,7 @@ void FakeShillDeviceClient::UnblockPin(const dbus::ObjectPath& device_path, const ErrorCallback& error_callback) { VLOG(1) << "UnblockPin: " << device_path.value(); if (!stub_devices_.HasKey(device_path.value())) { - PostDeviceNotFoundError(error_callback); + PostNotFoundError(error_callback); return; } base::MessageLoop::current()->PostTask(FROM_HERE, callback); @@ -200,7 +201,7 @@ void FakeShillDeviceClient::ChangePin(const dbus::ObjectPath& device_path, const ErrorCallback& error_callback) { VLOG(1) << "ChangePin: " << device_path.value(); if (!stub_devices_.HasKey(device_path.value())) { - PostDeviceNotFoundError(error_callback); + PostNotFoundError(error_callback); return; } base::MessageLoop::current()->PostTask(FROM_HERE, callback); @@ -211,7 +212,7 @@ void FakeShillDeviceClient::Register(const dbus::ObjectPath& device_path, const base::Closure& callback, const ErrorCallback& error_callback) { if (!stub_devices_.HasKey(device_path.value())) { - PostDeviceNotFoundError(error_callback); + PostNotFoundError(error_callback); return; } base::MessageLoop::current()->PostTask(FROM_HERE, callback); @@ -222,7 +223,7 @@ void FakeShillDeviceClient::SetCarrier(const dbus::ObjectPath& device_path, const base::Closure& callback, const ErrorCallback& error_callback) { if (!stub_devices_.HasKey(device_path.value())) { - PostDeviceNotFoundError(error_callback); + PostNotFoundError(error_callback); return; } base::MessageLoop::current()->PostTask(FROM_HERE, callback); @@ -232,7 +233,7 @@ void FakeShillDeviceClient::Reset(const dbus::ObjectPath& device_path, const base::Closure& callback, const ErrorCallback& error_callback) { if (!stub_devices_.HasKey(device_path.value())) { - PostDeviceNotFoundError(error_callback); + PostNotFoundError(error_callback); return; } base::MessageLoop::current()->PostTask(FROM_HERE, callback); @@ -245,7 +246,7 @@ void FakeShillDeviceClient::PerformTDLSOperation( const StringCallback& callback, const ErrorCallback& error_callback) { if (!stub_devices_.HasKey(device_path.value())) { - PostDeviceNotFoundError(error_callback); + PostNotFoundError(error_callback); return; } if (tdls_busy_count_) { @@ -264,6 +265,60 @@ void FakeShillDeviceClient::PerformTDLSOperation( base::Bind(callback, result)); } +void FakeShillDeviceClient::AddWakeOnPacketConnection( + const dbus::ObjectPath& device_path, + const net::IPEndPoint& ip_endpoint, + const base::Closure& callback, + const ErrorCallback& error_callback) { + if (!stub_devices_.HasKey(device_path.value())) { + PostNotFoundError(error_callback); + return; + } + + wake_on_packet_connections_[device_path].insert(ip_endpoint); + + base::MessageLoop::current()->PostTask(FROM_HERE, callback); +} + +void FakeShillDeviceClient::RemoveWakeOnPacketConnection( + const dbus::ObjectPath& device_path, + const net::IPEndPoint& ip_endpoint, + const base::Closure& callback, + const ErrorCallback& error_callback) { + const auto device_iter = wake_on_packet_connections_.find(device_path); + if (!stub_devices_.HasKey(device_path.value()) || + device_iter == wake_on_packet_connections_.end()) { + PostNotFoundError(error_callback); + return; + } + + const auto endpoint_iter = device_iter->second.find(ip_endpoint); + if (endpoint_iter == device_iter->second.end()) { + PostNotFoundError(error_callback); + return; + } + + device_iter->second.erase(endpoint_iter); + + base::MessageLoop::current()->PostTask(FROM_HERE, callback); +} + +void FakeShillDeviceClient::RemoveAllWakeOnPacketConnections( + const dbus::ObjectPath& device_path, + const base::Closure& callback, + const ErrorCallback& error_callback) { + const auto iter = wake_on_packet_connections_.find(device_path); + if (!stub_devices_.HasKey(device_path.value()) || + iter == wake_on_packet_connections_.end()) { + PostNotFoundError(error_callback); + return; + } + + wake_on_packet_connections_.erase(iter); + + base::MessageLoop::current()->PostTask(FROM_HERE, callback); +} + ShillDeviceClient::TestInterface* FakeShillDeviceClient::GetTestInterface() { return this; } diff --git a/chromeos/dbus/fake_shill_device_client.h b/chromeos/dbus/fake_shill_device_client.h index a4a0fd3..6d97e12 100644 --- a/chromeos/dbus/fake_shill_device_client.h +++ b/chromeos/dbus/fake_shill_device_client.h @@ -5,6 +5,8 @@ #ifndef CHROMEOS_DBUS_FAKE_SHILL_DEVICE_CLIENT_H_ #define CHROMEOS_DBUS_FAKE_SHILL_DEVICE_CLIENT_H_ +#include <map> +#include <set> #include <string> #include "base/basictypes.h" @@ -82,6 +84,20 @@ class CHROMEOS_EXPORT FakeShillDeviceClient const std::string& peer, const StringCallback& callback, const ErrorCallback& error_callback) override; + void AddWakeOnPacketConnection( + const dbus::ObjectPath& device_path, + const net::IPEndPoint& ip_endpoint, + const base::Closure& callback, + const ErrorCallback& error_callback) override; + void RemoveWakeOnPacketConnection( + const dbus::ObjectPath& device_path, + const net::IPEndPoint& ip_endpoint, + const base::Closure& callback, + const ErrorCallback& error_callback) override; + void RemoveAllWakeOnPacketConnections( + const dbus::ObjectPath& device_path, + const base::Closure& callback, + const ErrorCallback& error_callback) override; virtual ShillDeviceClient::TestInterface* GetTestInterface() override; @@ -121,6 +137,10 @@ class CHROMEOS_EXPORT FakeShillDeviceClient int tdls_busy_count_; // Number of times to return InProgress for TDLS. + // Wake on packet connections for each device. + std::map<dbus::ObjectPath, std::set<net::IPEndPoint> > + wake_on_packet_connections_; + // Note: This should remain the last member so it'll be destroyed and // invalidate its weak pointers before any other members are destroyed. base::WeakPtrFactory<FakeShillDeviceClient> weak_ptr_factory_; diff --git a/chromeos/dbus/fake_shill_manager_client.cc b/chromeos/dbus/fake_shill_manager_client.cc index 8e22da3..2ef8327 100644 --- a/chromeos/dbus/fake_shill_manager_client.cc +++ b/chromeos/dbus/fake_shill_manager_client.cc @@ -355,23 +355,6 @@ void FakeShillManagerClient::ConnectToBestServices( dbus::ObjectPath(best_service_), callback, error_callback); } -void FakeShillManagerClient::AddWakeOnPacketConnection( - const net::IPEndPoint& ip_endpoint, - const base::Closure& callback, - const ErrorCallback& error_callback) { -} - -void FakeShillManagerClient::RemoveWakeOnPacketConnection( - const net::IPEndPoint& ip_endpoint, - const base::Closure& callback, - const ErrorCallback& error_callback) { -} - -void FakeShillManagerClient::RemoveAllWakeOnPacketConnections( - const base::Closure& callback, - const ErrorCallback& error_callback) { -} - ShillManagerClient::TestInterface* FakeShillManagerClient::GetTestInterface() { return this; } diff --git a/chromeos/dbus/fake_shill_manager_client.h b/chromeos/dbus/fake_shill_manager_client.h index 5a0591e..ac4a9d1 100644 --- a/chromeos/dbus/fake_shill_manager_client.h +++ b/chromeos/dbus/fake_shill_manager_client.h @@ -81,17 +81,6 @@ class CHROMEOS_EXPORT FakeShillManagerClient virtual void ConnectToBestServices( const base::Closure& callback, const ErrorCallback& error_callback) override; - virtual void AddWakeOnPacketConnection( - const net::IPEndPoint& ip_connection, - const base::Closure& callback, - const ErrorCallback& error_callback) override; - virtual void RemoveWakeOnPacketConnection( - const net::IPEndPoint& ip_endpoint, - const base::Closure& callback, - const ErrorCallback& error_callback) override; - virtual void RemoveAllWakeOnPacketConnections( - const base::Closure& callback, - const ErrorCallback& error_callback) override; virtual ShillManagerClient::TestInterface* GetTestInterface() override; diff --git a/chromeos/dbus/mock_shill_manager_client.h b/chromeos/dbus/mock_shill_manager_client.h index 63c8c9c4..7fa16ee 100644 --- a/chromeos/dbus/mock_shill_manager_client.h +++ b/chromeos/dbus/mock_shill_manager_client.h @@ -67,17 +67,6 @@ class MockShillManagerClient : public ShillManagerClient { MOCK_METHOD2(ConnectToBestServices, void(const base::Closure& callback, const ErrorCallback& error_callback)); - MOCK_METHOD3(AddWakeOnPacketConnection, - void(const net::IPEndPoint& ip_connection, - const base::Closure& callback, - const ErrorCallback& error_callback)); - MOCK_METHOD3(RemoveWakeOnPacketConnection, - void(const net::IPEndPoint& ip_connection, - const base::Closure& callback, - const ErrorCallback& error_callback)); - MOCK_METHOD2(RemoveAllWakeOnPacketConnections, - void(const base::Closure& callback, - const ErrorCallback& error_callback)); MOCK_METHOD0(GetTestInterface, TestInterface*()); }; diff --git a/chromeos/dbus/shill_device_client.cc b/chromeos/dbus/shill_device_client.cc index 1a523ff..5685b6096 100644 --- a/chromeos/dbus/shill_device_client.cc +++ b/chromeos/dbus/shill_device_client.cc @@ -14,6 +14,7 @@ #include "dbus/object_path.h" #include "dbus/object_proxy.h" #include "dbus/values_util.h" +#include "net/base/ip_endpoint.h" #include "third_party/cros_system_api/dbus/service_constants.h" namespace chromeos { @@ -23,7 +24,7 @@ namespace { // The ShillDeviceClient implementation. class ShillDeviceClientImpl : public ShillDeviceClient { public: - explicit ShillDeviceClientImpl() + ShillDeviceClientImpl() : bus_(NULL) { } @@ -206,6 +207,54 @@ class ShillDeviceClientImpl : public ShillDeviceClient { &method_call, callback, error_callback); } + void AddWakeOnPacketConnection( + const dbus::ObjectPath& device_path, + const net::IPEndPoint& ip_endpoint, + const base::Closure& callback, + const ErrorCallback& error_callback) override { + if (ip_endpoint.address().empty()) { + LOG(ERROR) << "AddWakeOnPacketConnection: null address"; + return; + } + dbus::MethodCall method_call(shill::kFlimflamDeviceInterface, + shill::kAddWakeOnPacketConnectionFunction); + dbus::MessageWriter writer(&method_call); + writer.AppendString(ip_endpoint.ToStringWithoutPort()); + GetHelper(device_path)->CallVoidMethodWithErrorCallback(&method_call, + callback, + error_callback); + } + + void RemoveWakeOnPacketConnection( + const dbus::ObjectPath& device_path, + const net::IPEndPoint& ip_endpoint, + const base::Closure& callback, + const ErrorCallback& error_callback) override { + if (ip_endpoint.address().empty()) { + LOG(ERROR) << "RemoveWakeOnPacketConnection: null address"; + return; + } + dbus::MethodCall method_call(shill::kFlimflamDeviceInterface, + shill::kRemoveWakeOnPacketConnectionFunction); + dbus::MessageWriter writer(&method_call); + writer.AppendString(ip_endpoint.ToStringWithoutPort()); + GetHelper(device_path)->CallVoidMethodWithErrorCallback(&method_call, + callback, + error_callback); + } + + void RemoveAllWakeOnPacketConnections( + const dbus::ObjectPath& device_path, + const base::Closure& callback, + const ErrorCallback& error_callback) override { + dbus::MethodCall method_call( + shill::kFlimflamDeviceInterface, + shill::kRemoveAllWakeOnPacketConnectionsFunction); + GetHelper(device_path)->CallVoidMethodWithErrorCallback(&method_call, + callback, + error_callback); + } + virtual TestInterface* GetTestInterface() override { return NULL; } diff --git a/chromeos/dbus/shill_device_client.h b/chromeos/dbus/shill_device_client.h index dd668c6..2e0a376 100644 --- a/chromeos/dbus/shill_device_client.h +++ b/chromeos/dbus/shill_device_client.h @@ -26,6 +26,12 @@ class ObjectPath; } // namespace dbus +namespace net { + +class IPEndPoint; + +} // namespace net + namespace chromeos { class ShillPropertyChangedObserver; @@ -163,6 +169,29 @@ class CHROMEOS_EXPORT ShillDeviceClient : public DBusClient { const StringCallback& callback, const ErrorCallback& error_callback) = 0; + // Adds |ip_endpoint| to the list of tcp connections that the device should + // monitor to wake the system from suspend. + virtual void AddWakeOnPacketConnection( + const dbus::ObjectPath& device_path, + const net::IPEndPoint& ip_endpoint, + const base::Closure& callback, + const ErrorCallback& error_callback) = 0; + + // Removes |ip_endpoint| from the list of tcp connections that the device + // should monitor to wake the system from suspend. + virtual void RemoveWakeOnPacketConnection( + const dbus::ObjectPath& device_path, + const net::IPEndPoint& ip_endpoint, + const base::Closure& callback, + const ErrorCallback& error_callback) = 0; + + // Clears the list of tcp connections that the device should monitor to wake + // the system from suspend. + virtual void RemoveAllWakeOnPacketConnections( + const dbus::ObjectPath& device_path, + const base::Closure& callback, + const ErrorCallback& error_callback) = 0; + // Returns an interface for testing (stub only), or returns NULL. virtual TestInterface* GetTestInterface() = 0; diff --git a/chromeos/dbus/shill_manager_client.cc b/chromeos/dbus/shill_manager_client.cc index 52b2ef1..f1ea6710 100644 --- a/chromeos/dbus/shill_manager_client.cc +++ b/chromeos/dbus/shill_manager_client.cc @@ -211,51 +211,6 @@ class ShillManagerClientImpl : public ShillManagerClient { error_callback); } - virtual void AddWakeOnPacketConnection( - const net::IPEndPoint& ip_endpoint, - const base::Closure& callback, - const ErrorCallback& error_callback) override { - if (ip_endpoint.address().empty()) { - LOG(ERROR) << "AddWakeOnPacketConnection: null address"; - return; - } - dbus::MethodCall method_call(shill::kFlimflamManagerInterface, - shill::kAddWakeOnPacketConnectionFunction); - dbus::MessageWriter writer(&method_call); - writer.AppendString(net::IPAddressToString(ip_endpoint.address())); - helper_->CallVoidMethodWithErrorCallback(&method_call, - callback, - error_callback); - } - - virtual void RemoveWakeOnPacketConnection( - const net::IPEndPoint& ip_endpoint, - const base::Closure& callback, - const ErrorCallback& error_callback) override { - if (ip_endpoint.address().empty()) { - LOG(ERROR) << "RemoveWakeOnPacketConnection: null address"; - return; - } - dbus::MethodCall method_call(shill::kFlimflamManagerInterface, - shill::kRemoveWakeOnPacketConnectionFunction); - dbus::MessageWriter writer(&method_call); - writer.AppendString(net::IPAddressToString(ip_endpoint.address())); - helper_->CallVoidMethodWithErrorCallback(&method_call, - callback, - error_callback); - } - - virtual void RemoveAllWakeOnPacketConnections( - const base::Closure& callback, - const ErrorCallback& error_callback) override { - dbus::MethodCall method_call( - shill::kFlimflamManagerInterface, - shill::kRemoveAllWakeOnPacketConnectionsFunction); - helper_->CallVoidMethodWithErrorCallback(&method_call, - callback, - error_callback); - } - virtual TestInterface* GetTestInterface() override { return NULL; } diff --git a/chromeos/dbus/shill_manager_client.h b/chromeos/dbus/shill_manager_client.h index 8bc7251..e8b3177 100644 --- a/chromeos/dbus/shill_manager_client.h +++ b/chromeos/dbus/shill_manager_client.h @@ -224,24 +224,6 @@ class CHROMEOS_EXPORT ShillManagerClient : public DBusClient { virtual void ConnectToBestServices(const base::Closure& callback, const ErrorCallback& error_callback) = 0; - // Requests that shill program the NIC so that packets incoming on - // |ip_connection| wake up the CPU. - virtual void AddWakeOnPacketConnection( - const net::IPEndPoint& ip_endpoint, - const base::Closure& callback, - const ErrorCallback& error_callback) = 0; - - // Removes a request to wake up on packets coming on |ip_connection|. - virtual void RemoveWakeOnPacketConnection( - const net::IPEndPoint& ip_endpoint, - const base::Closure& callback, - const ErrorCallback& error_callback) = 0; - - // Clears all requests to wake up on packets. - virtual void RemoveAllWakeOnPacketConnections( - const base::Closure& callback, - const ErrorCallback& error_callback) = 0; - // Returns an interface for testing (stub only), or returns NULL. virtual TestInterface* GetTestInterface() = 0; diff --git a/chromeos/network/fake_network_device_handler.cc b/chromeos/network/fake_network_device_handler.cc index bd6df3c..536ea9f 100644 --- a/chromeos/network/fake_network_device_handler.cc +++ b/chromeos/network/fake_network_device_handler.cc @@ -84,4 +84,18 @@ void FakeNetworkDeviceHandler::GetWifiTDLSStatus( const network_handler::StringResultCallback& callback, const network_handler::ErrorCallback& error_callback) {} +void FakeNetworkDeviceHandler::AddWifiWakeOnPacketConnection( + const net::IPEndPoint& ip_endpoint, + const base::Closure& callback, + const network_handler::ErrorCallback& error_callback) {} + +void FakeNetworkDeviceHandler::RemoveWifiWakeOnPacketConnection( + const net::IPEndPoint& ip_endpoint, + const base::Closure& callback, + const network_handler::ErrorCallback& error_callback) {} + +void FakeNetworkDeviceHandler::RemoveAllWifiWakeOnPacketConnections( + const base::Closure& callback, + const network_handler::ErrorCallback& error_callback) {} + } // namespace chromeos diff --git a/chromeos/network/fake_network_device_handler.h b/chromeos/network/fake_network_device_handler.h index 556a104..d009b16 100644 --- a/chromeos/network/fake_network_device_handler.h +++ b/chromeos/network/fake_network_device_handler.h @@ -94,6 +94,20 @@ class CHROMEOS_EXPORT FakeNetworkDeviceHandler : public NetworkDeviceHandler { const network_handler::StringResultCallback& callback, const network_handler::ErrorCallback& error_callback) override; + void AddWifiWakeOnPacketConnection( + const net::IPEndPoint& ip_endpoint, + const base::Closure& callback, + const network_handler::ErrorCallback& error_callback) override; + + void RemoveWifiWakeOnPacketConnection( + const net::IPEndPoint& ip_endpoint, + const base::Closure& callback, + const network_handler::ErrorCallback& error_callback) override; + + void RemoveAllWifiWakeOnPacketConnections( + const base::Closure& callback, + const network_handler::ErrorCallback& error_callback) override; + private: DISALLOW_COPY_AND_ASSIGN(FakeNetworkDeviceHandler); }; diff --git a/chromeos/network/network_device_handler.h b/chromeos/network/network_device_handler.h index c1333a3..d682eb9 100644 --- a/chromeos/network/network_device_handler.h +++ b/chromeos/network/network_device_handler.h @@ -15,6 +15,10 @@ namespace base { class Value; } +namespace net { +class IPEndPoint; +} + namespace chromeos { // The NetworkDeviceHandler class allows making device specific requests on a @@ -209,6 +213,26 @@ class CHROMEOS_EXPORT NetworkDeviceHandler { const network_handler::StringResultCallback& callback, const network_handler::ErrorCallback& error_callback) = 0; + // Adds |ip_endpoint| to the list of tcp connections that the wifi device + // should monitor to wake the system from suspend. + virtual void AddWifiWakeOnPacketConnection( + const net::IPEndPoint& ip_endpoint, + const base::Closure& callback, + const network_handler::ErrorCallback& error_callback) = 0; + + // Removes |ip_endpoint| from the list of tcp connections that the wifi device + // should monitor to wake the system from suspend. + virtual void RemoveWifiWakeOnPacketConnection( + const net::IPEndPoint& ip_endpoint, + const base::Closure& callback, + const network_handler::ErrorCallback& error_callback) = 0; + + // Clears the list of tcp connections that the wifi device should monitor to + // wake the system from suspend. + virtual void RemoveAllWifiWakeOnPacketConnections( + const base::Closure& callback, + const network_handler::ErrorCallback& error_callback) = 0; + private: DISALLOW_COPY_AND_ASSIGN(NetworkDeviceHandler); }; diff --git a/chromeos/network/network_device_handler_impl.cc b/chromeos/network/network_device_handler_impl.cc index f7f2855..fb66d90 100644 --- a/chromeos/network/network_device_handler_impl.cc +++ b/chromeos/network/network_device_handler_impl.cc @@ -399,16 +399,10 @@ void NetworkDeviceHandlerImpl::SetWifiTDLSEnabled( bool enabled, const network_handler::StringResultCallback& callback, const network_handler::ErrorCallback& error_callback) { - const DeviceState* device_state = - network_state_handler_->GetDeviceStateByType(NetworkTypePattern::WiFi()); - if (!device_state) { - if (error_callback.is_null()) - return; - scoped_ptr<base::DictionaryValue> error_data(new base::DictionaryValue); - error_data->SetString(network_handler::kErrorName, kErrorDeviceMissing); - error_callback.Run(kErrorDeviceMissing, error_data.Pass()); + const DeviceState* device_state = GetWifiDeviceState(error_callback); + if (!device_state) return; - } + TDLSOperationParams params; params.operation = enabled ? shill::kTDLSSetupOperation : shill::kTDLSTeardownOperation; @@ -421,16 +415,10 @@ void NetworkDeviceHandlerImpl::GetWifiTDLSStatus( const std::string& ip_or_mac_address, const network_handler::StringResultCallback& callback, const network_handler::ErrorCallback& error_callback) { - const DeviceState* device_state = - network_state_handler_->GetDeviceStateByType(NetworkTypePattern::WiFi()); - if (!device_state) { - if (error_callback.is_null()) - return; - scoped_ptr<base::DictionaryValue> error_data(new base::DictionaryValue); - error_data->SetString(network_handler::kErrorName, kErrorDeviceMissing); - error_callback.Run(kErrorDeviceMissing, error_data.Pass()); + const DeviceState* device_state = GetWifiDeviceState(error_callback); + if (!device_state) return; - } + TDLSOperationParams params; params.operation = shill::kTDLSStatusOperation; params.ip_or_mac_address = ip_or_mac_address; @@ -438,6 +426,57 @@ void NetworkDeviceHandlerImpl::GetWifiTDLSStatus( device_state->path(), params, callback, error_callback); } +void NetworkDeviceHandlerImpl::AddWifiWakeOnPacketConnection( + const net::IPEndPoint& ip_endpoint, + const base::Closure& callback, + const network_handler::ErrorCallback& error_callback) { + const DeviceState* device_state = GetWifiDeviceState(error_callback); + if (!device_state) + return; + + DBusThreadManager::Get()->GetShillDeviceClient()->AddWakeOnPacketConnection( + dbus::ObjectPath(device_state->path()), + ip_endpoint, + callback, + base::Bind(&HandleShillCallFailure, + device_state->path(), + error_callback)); +} + +void NetworkDeviceHandlerImpl::RemoveWifiWakeOnPacketConnection( + const net::IPEndPoint& ip_endpoint, + const base::Closure& callback, + const network_handler::ErrorCallback& error_callback) { + const DeviceState* device_state = GetWifiDeviceState(error_callback); + if (!device_state) + return; + + DBusThreadManager::Get() + ->GetShillDeviceClient() + ->RemoveWakeOnPacketConnection(dbus::ObjectPath(device_state->path()), + ip_endpoint, + callback, + base::Bind(&HandleShillCallFailure, + device_state->path(), + error_callback)); +} + +void NetworkDeviceHandlerImpl::RemoveAllWifiWakeOnPacketConnections( + const base::Closure& callback, + const network_handler::ErrorCallback& error_callback) { + const DeviceState* device_state = GetWifiDeviceState(error_callback); + if (!device_state) + return; + + DBusThreadManager::Get() + ->GetShillDeviceClient() + ->RemoveAllWakeOnPacketConnections(dbus::ObjectPath(device_state->path()), + callback, + base::Bind(&HandleShillCallFailure, + device_state->path(), + error_callback)); +} + void NetworkDeviceHandlerImpl::DeviceListChanged() { ApplyCellularAllowRoamingToShill(); } @@ -484,4 +523,20 @@ void NetworkDeviceHandlerImpl::ApplyCellularAllowRoamingToShill() { } } +const DeviceState* NetworkDeviceHandlerImpl::GetWifiDeviceState( + const network_handler::ErrorCallback& error_callback) { + const DeviceState* device_state = + network_state_handler_->GetDeviceStateByType(NetworkTypePattern::WiFi()); + if (!device_state) { + if (error_callback.is_null()) + return NULL; + scoped_ptr<base::DictionaryValue> error_data(new base::DictionaryValue); + error_data->SetString(network_handler::kErrorName, kErrorDeviceMissing); + error_callback.Run(kErrorDeviceMissing, error_data.Pass()); + return NULL; + } + + return device_state; +} + } // namespace chromeos diff --git a/chromeos/network/network_device_handler_impl.h b/chromeos/network/network_device_handler_impl.h index fb10f3c..11216bd 100644 --- a/chromeos/network/network_device_handler_impl.h +++ b/chromeos/network/network_device_handler_impl.h @@ -102,6 +102,20 @@ class CHROMEOS_EXPORT NetworkDeviceHandlerImpl const network_handler::StringResultCallback& callback, const network_handler::ErrorCallback& error_callback) override; + void AddWifiWakeOnPacketConnection( + const net::IPEndPoint& ip_endpoint, + const base::Closure& callback, + const network_handler::ErrorCallback& error_callback) override; + + void RemoveWifiWakeOnPacketConnection( + const net::IPEndPoint& ip_endpoint, + const base::Closure& callback, + const network_handler::ErrorCallback& error_callback) override; + + void RemoveAllWifiWakeOnPacketConnections( + const base::Closure& callback, + const network_handler::ErrorCallback& error_callback) override; + // NetworkStateHandlerObserver overrides virtual void DeviceListChanged() override; @@ -117,6 +131,10 @@ class CHROMEOS_EXPORT NetworkDeviceHandlerImpl // cellular devices of Shill. void ApplyCellularAllowRoamingToShill(); + // Get the DeviceState for the wifi device, if any. + const DeviceState* GetWifiDeviceState( + const network_handler::ErrorCallback& error_callback); + NetworkStateHandler* network_state_handler_; bool cellular_allow_roaming_; diff --git a/components/gcm_driver/gcm_driver_desktop.h b/components/gcm_driver/gcm_driver_desktop.h index 3f72c26..407d91a 100644 --- a/components/gcm_driver/gcm_driver_desktop.h +++ b/components/gcm_driver/gcm_driver_desktop.h @@ -150,8 +150,7 @@ class GCMDriverDesktop : public GCMDriver { bool connected_; // List of observers to notify when connection state changes. - // Makes sure list is empty on destruction. - ObserverList<GCMConnectionObserver, true> connection_observer_list_; + ObserverList<GCMConnectionObserver, false> connection_observer_list_; // Account mapper. Only works when user is signed in. scoped_ptr<GCMAccountMapper> account_mapper_; |