summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorabhishekbh <abhishekbh@google.com>2016-03-16 16:21:59 -0700
committerCommit bot <commit-bot@chromium.org>2016-03-16 23:26:26 +0000
commit9f654ac6a5d00c94ad1e612e3785fffd8e4df7c9 (patch)
treeb6f2d398e8278400005bc0e79824730ebf2cac65
parented6800f22cb908b03fa72d876296a87e1e747b48 (diff)
downloadchromium_src-9f654ac6a5d00c94ad1e612e3785fffd8e4df7c9.zip
chromium_src-9f654ac6a5d00c94ad1e612e3785fffd8e4df7c9.tar.gz
chromium_src-9f654ac6a5d00c94ad1e612e3785fffd8e4df7c9.tar.bz2
ARC: Implement SetWifiEnabledState API.
This change implements the SetWifiEnabledState API for the Host. BUG=594723 BUG=b/27107139 Review URL: https://codereview.chromium.org/1798293002 Cr-Commit-Position: refs/heads/master@{#381583}
-rw-r--r--components/arc/common/net.mojom6
-rw-r--r--components/arc/net/arc_net_host_impl.cc23
-rw-r--r--components/arc/net/arc_net_host_impl.h5
3 files changed, 33 insertions, 1 deletions
diff --git a/components/arc/common/net.mojom b/components/arc/common/net.mojom
index 67c3abe..912fdac 100644
--- a/components/arc/common/net.mojom
+++ b/components/arc/common/net.mojom
@@ -47,6 +47,12 @@ interface NetHost {
// Sends a request to get configured or visible WiFi networks based on the
// request type.
[MinVersion=2] GetNetworks@3(GetNetworksRequestType type) => (NetworkData data);
+
+ // Sends a request to enable or disable WiFi. The |result| is true when the
+ // the state has been successfully set or WiFi is already in the desired
+ // state. It is false if WiFi manipulation is prohibited due to a policy or
+ // its current state.
+ [MinVersion=3] SetWifiEnabledState@4(bool is_enabled) => (bool result);
};
interface NetInstance {
diff --git a/components/arc/net/arc_net_host_impl.cc b/components/arc/net/arc_net_host_impl.cc
index 929b64e..afaec21 100644
--- a/components/arc/net/arc_net_host_impl.cc
+++ b/components/arc/net/arc_net_host_impl.cc
@@ -14,6 +14,7 @@
#include "base/time/time.h"
#include "chromeos/network/network_handler.h"
#include "chromeos/network/network_state_handler.h"
+#include "chromeos/network/network_type_pattern.h"
#include "chromeos/network/network_util.h"
#include "chromeos/network/onc/onc_utils.h"
#include "components/arc/arc_bridge_service.h"
@@ -145,10 +146,30 @@ void ArcNetHostImpl::GetWifiEnabledState(
const GetWifiEnabledStateCallback& callback) {
bool is_enabled = GetStateHandler()->IsTechnologyEnabled(
chromeos::NetworkTypePattern::WiFi());
-
callback.Run(is_enabled);
}
+void ArcNetHostImpl::SetWifiEnabledState(
+ bool is_enabled,
+ const SetWifiEnabledStateCallback& callback) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ chromeos::NetworkStateHandler::TechnologyState state =
+ GetStateHandler()->GetTechnologyState(
+ chromeos::NetworkTypePattern::WiFi());
+ // WiFi can't be enabled or disabled in these states.
+ if ((state == chromeos::NetworkStateHandler::TECHNOLOGY_PROHIBITED) ||
+ (state == chromeos::NetworkStateHandler::TECHNOLOGY_UNINITIALIZED) ||
+ (state == chromeos::NetworkStateHandler::TECHNOLOGY_UNAVAILABLE)) {
+ VLOG(1) << "SetWifiEnabledState failed due to WiFi state: " << state;
+ callback.Run(false);
+ } else {
+ GetStateHandler()->SetTechnologyEnabled(
+ chromeos::NetworkTypePattern::WiFi(), is_enabled,
+ chromeos::network_handler::ErrorCallback());
+ callback.Run(true);
+ }
+}
+
void ArcNetHostImpl::StartScan() {
GetStateHandler()->RequestScan();
}
diff --git a/components/arc/net/arc_net_host_impl.h b/components/arc/net/arc_net_host_impl.h
index ae7bb1b..f4c15f8 100644
--- a/components/arc/net/arc_net_host_impl.h
+++ b/components/arc/net/arc_net_host_impl.h
@@ -46,6 +46,11 @@ class ArcNetHostImpl : public ArcService,
void GetWifiEnabledState(
const GetWifiEnabledStateCallback& callback) override;
+ // Called when a SetWifiEnabledState call is sent from ARC.
+ void SetWifiEnabledState(
+ bool is_enabled,
+ const SetWifiEnabledStateCallback& callback) override;
+
// Called when a StartScan call is sent from ARC.
void StartScan() override;