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

Unified Diff: chrome/browser/chromeos/net/wake_on_wifi_connection_observer.cc

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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/net/wake_on_wifi_connection_observer.cc
diff --git a/chrome/browser/chromeos/net/wake_on_wifi_connection_observer.cc b/chrome/browser/chromeos/net/wake_on_wifi_connection_observer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..47c42da7fdcec3029bf0538c97b23227bf7bc882
--- /dev/null
+++ b/chrome/browser/chromeos/net/wake_on_wifi_connection_observer.cc
@@ -0,0 +1,91 @@
+// 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_connection_observer.h"
+
+
+#include "base/logging.h"
+#include "chrome/browser/chromeos/net/wake_on_wifi_manager.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/services/gcm/gcm_profile_service_factory.h"
+#include "chromeos/network/network_device_handler.h"
+#include "components/gcm_driver/gcm_driver.h"
+#include "components/gcm_driver/gcm_profile_service.h"
+
+namespace chromeos {
+
+WakeOnWifiConnectionObserver::WakeOnWifiConnectionObserver(
+ 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);
+}
+
+WakeOnWifiConnectionObserver::~WakeOnWifiConnectionObserver() {
+ if (!(ip_endpoint_ == net::IPEndPoint()))
+ OnDisconnected();
+
+ gcm::GCMProfileServiceFactory::GetForProfile(profile_)
+ ->driver()
+ ->RemoveConnectionObserver(this);
+}
+
+void WakeOnWifiConnectionObserver::HandleWifiDevicePropertiesReady() {
+ wifi_properties_received_ = true;
+
+ // IPEndPoint doesn't implement operator!=
+ if (ip_endpoint_ == net::IPEndPoint())
+ return;
+
+ AddWakeOnPacketConnection();
+}
+
+void WakeOnWifiConnectionObserver::OnConnected(
+ const net::IPEndPoint& ip_endpoint) {
+ ip_endpoint_ = ip_endpoint;
+
+ if (wifi_properties_received_)
+ AddWakeOnPacketConnection();
+}
+
+void WakeOnWifiConnectionObserver::OnDisconnected() {
+ if (ip_endpoint_ == net::IPEndPoint()) {
+ VLOG(1) << "Received GCMConnectionObserver::OnDisconnected without a "
+ << "valid IPEndPoint.";
+ return;
+ }
+
+ if (wifi_properties_received_)
+ RemoveWakeOnPacketConnection();
+
+ ip_endpoint_ = net::IPEndPoint();
+}
+
+void WakeOnWifiConnectionObserver::AddWakeOnPacketConnection() {
+ if (!WakeOnWifiManager::IsWakeOnPacketEnabled(feature_))
+ return;
+ network_device_handler_
+ ->AddWifiWakeOnPacketConnection(ip_endpoint_,
+ base::Bind(&base::DoNothing),
+ network_handler::ErrorCallback());
+}
+
+void WakeOnWifiConnectionObserver::RemoveWakeOnPacketConnection() {
+ if (!WakeOnWifiManager::IsWakeOnPacketEnabled(feature_))
+ return;
+ network_device_handler_
+ ->RemoveWifiWakeOnPacketConnection(ip_endpoint_,
+ base::Bind(&base::DoNothing),
+ network_handler::ErrorCallback());
+}
+
+} // namespace chromeos
« no previous file with comments | « chrome/browser/chromeos/net/wake_on_wifi_connection_observer.h ('k') | chrome/browser/chromeos/net/wake_on_wifi_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698