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

Side by Side Diff: components/arc/net/arc_net_host_impl.cc

Issue 1798293002: ARC: Implement SetWifiEnabledState API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Formatting changes in comments. Created 4 years, 9 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
« no previous file with comments | « components/arc/net/arc_net_host_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #include "components/arc/net/arc_net_host_impl.h" 5 #include "components/arc/net/arc_net_host_impl.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/posix/eintr_wrapper.h" 12 #include "base/posix/eintr_wrapper.h"
13 #include "base/thread_task_runner_handle.h" 13 #include "base/thread_task_runner_handle.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "chromeos/network/network_handler.h" 15 #include "chromeos/network/network_handler.h"
16 #include "chromeos/network/network_state_handler.h" 16 #include "chromeos/network/network_state_handler.h"
17 #include "chromeos/network/network_type_pattern.h"
17 #include "chromeos/network/network_util.h" 18 #include "chromeos/network/network_util.h"
18 #include "chromeos/network/onc/onc_utils.h" 19 #include "chromeos/network/onc/onc_utils.h"
19 #include "components/arc/arc_bridge_service.h" 20 #include "components/arc/arc_bridge_service.h"
20 21
21 namespace { 22 namespace {
22 23
23 const int kGetNetworksListLimit = 100; 24 const int kGetNetworksListLimit = 100;
24 25
25 } // namespace 26 } // namespace
26 27
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 networks.push_back(std::move(wc)); 139 networks.push_back(std::move(wc));
139 } 140 }
140 data->networks = std::move(networks); 141 data->networks = std::move(networks);
141 callback.Run(std::move(data)); 142 callback.Run(std::move(data));
142 } 143 }
143 144
144 void ArcNetHostImpl::GetWifiEnabledState( 145 void ArcNetHostImpl::GetWifiEnabledState(
145 const GetWifiEnabledStateCallback& callback) { 146 const GetWifiEnabledStateCallback& callback) {
146 bool is_enabled = GetStateHandler()->IsTechnologyEnabled( 147 bool is_enabled = GetStateHandler()->IsTechnologyEnabled(
147 chromeos::NetworkTypePattern::WiFi()); 148 chromeos::NetworkTypePattern::WiFi());
149 callback.Run(is_enabled);
150 }
148 151
149 callback.Run(is_enabled); 152 void ArcNetHostImpl::SetWifiEnabledState(
153 bool is_enabled,
154 const SetWifiEnabledStateCallback& callback) {
155 DCHECK(thread_checker_.CalledOnValidThread());
156 chromeos::NetworkStateHandler::TechnologyState state =
157 GetStateHandler()->GetTechnologyState(
158 chromeos::NetworkTypePattern::WiFi());
159 // WiFi can't be enabled or disabled in these states.
160 if ((state == chromeos::NetworkStateHandler::TECHNOLOGY_PROHIBITED) ||
161 (state == chromeos::NetworkStateHandler::TECHNOLOGY_UNINITIALIZED) ||
162 (state == chromeos::NetworkStateHandler::TECHNOLOGY_UNAVAILABLE)) {
163 VLOG(1) << "SetWifiEnabledState failed due to WiFi state: " << state;
164 callback.Run(false);
165 } else {
166 GetStateHandler()->SetTechnologyEnabled(
167 chromeos::NetworkTypePattern::WiFi(), is_enabled,
168 chromeos::network_handler::ErrorCallback());
169 callback.Run(true);
170 }
150 } 171 }
151 172
152 void ArcNetHostImpl::StartScan() { 173 void ArcNetHostImpl::StartScan() {
153 GetStateHandler()->RequestScan(); 174 GetStateHandler()->RequestScan();
154 } 175 }
155 176
156 void ArcNetHostImpl::ScanCompleted(const chromeos::DeviceState* /*unused*/) { 177 void ArcNetHostImpl::ScanCompleted(const chromeos::DeviceState* /*unused*/) {
157 if (arc_bridge_service()->net_version() < 1) { 178 if (arc_bridge_service()->net_version() < 1) {
158 VLOG(1) << "ArcBridgeService does not support ScanCompleted."; 179 VLOG(1) << "ArcBridgeService does not support ScanCompleted.";
159 return; 180 return;
160 } 181 }
161 182
162 arc_bridge_service()->net_instance()->ScanCompleted(); 183 arc_bridge_service()->net_instance()->ScanCompleted();
163 } 184 }
164 185
165 void ArcNetHostImpl::OnShuttingDown() { 186 void ArcNetHostImpl::OnShuttingDown() {
166 GetStateHandler()->RemoveObserver(this, FROM_HERE); 187 GetStateHandler()->RemoveObserver(this, FROM_HERE);
167 } 188 }
168 189
169 } // namespace arc 190 } // namespace arc
OLDNEW
« no previous file with comments | « components/arc/net/arc_net_host_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698