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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/net/wake_on_wifi_connection_observer.h"
6
7
8 #include "base/logging.h"
9 #include "chrome/browser/chromeos/net/wake_on_wifi_manager.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h"
12 #include "chromeos/network/network_device_handler.h"
13 #include "components/gcm_driver/gcm_driver.h"
14 #include "components/gcm_driver/gcm_profile_service.h"
15
16 namespace chromeos {
17
18 WakeOnWifiConnectionObserver::WakeOnWifiConnectionObserver(
19 Profile* profile,
20 bool wifi_properties_received,
21 WakeOnWifiManager::WakeOnWifiFeature feature,
22 NetworkDeviceHandler* network_device_handler)
23 : profile_(profile),
24 ip_endpoint_(net::IPEndPoint()),
25 wifi_properties_received_(wifi_properties_received),
26 feature_(feature),
27 network_device_handler_(network_device_handler) {
28 gcm::GCMProfileServiceFactory::GetForProfile(profile_)
29 ->driver()
30 ->AddConnectionObserver(this);
31 }
32
33 WakeOnWifiConnectionObserver::~WakeOnWifiConnectionObserver() {
34 if (!(ip_endpoint_ == net::IPEndPoint()))
35 OnDisconnected();
36
37 gcm::GCMProfileServiceFactory::GetForProfile(profile_)
38 ->driver()
39 ->RemoveConnectionObserver(this);
40 }
41
42 void WakeOnWifiConnectionObserver::HandleWifiDevicePropertiesReady() {
43 wifi_properties_received_ = true;
44
45 // IPEndPoint doesn't implement operator!=
46 if (ip_endpoint_ == net::IPEndPoint())
47 return;
48
49 AddWakeOnPacketConnection();
50 }
51
52 void WakeOnWifiConnectionObserver::OnConnected(
53 const net::IPEndPoint& ip_endpoint) {
54 ip_endpoint_ = ip_endpoint;
55
56 if (wifi_properties_received_)
57 AddWakeOnPacketConnection();
58 }
59
60 void WakeOnWifiConnectionObserver::OnDisconnected() {
61 if (ip_endpoint_ == net::IPEndPoint()) {
62 VLOG(1) << "Received GCMConnectionObserver::OnDisconnected without a "
63 << "valid IPEndPoint.";
64 return;
65 }
66
67 if (wifi_properties_received_)
68 RemoveWakeOnPacketConnection();
69
70 ip_endpoint_ = net::IPEndPoint();
71 }
72
73 void WakeOnWifiConnectionObserver::AddWakeOnPacketConnection() {
74 if (!WakeOnWifiManager::IsWakeOnPacketEnabled(feature_))
75 return;
76 network_device_handler_
77 ->AddWifiWakeOnPacketConnection(ip_endpoint_,
78 base::Bind(&base::DoNothing),
79 network_handler::ErrorCallback());
80 }
81
82 void WakeOnWifiConnectionObserver::RemoveWakeOnPacketConnection() {
83 if (!WakeOnWifiManager::IsWakeOnPacketEnabled(feature_))
84 return;
85 network_device_handler_
86 ->RemoveWifiWakeOnPacketConnection(ip_endpoint_,
87 base::Bind(&base::DoNothing),
88 network_handler::ErrorCallback());
89 }
90
91 } // namespace chromeos
OLDNEW
« 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