Commit 6ad6767d authored by cernekee's avatar cernekee Committed by Commit bot

Implement OnGetNetworks for net.mojom

This allows ARC to request the list of visible wifi networks.

BUG=b:26369403
TEST=manual
Signed-off-by: default avatarAbhishek Bhardwaj <abhishekbh@chromium.org>
Signed-off-by: default avatarKevin Cernekee <cernekee@chromium.org>

Review URL: https://codereview.chromium.org/1572483002

Cr-Commit-Position: refs/heads/master@{#371421}
parent 66541ff2
......@@ -13,6 +13,7 @@
],
'dependencies': [
'arc_mojo_bindings',
'components.gyp:onc_component',
'../base/base.gyp:base',
'../chromeos/chromeos.gyp:chromeos',
'../chromeos/chromeos.gyp:power_manager_proto',
......@@ -43,6 +44,8 @@
'arc/ime/arc_ime_ipc_host_impl.h',
'arc/input/arc_input_bridge.cc',
'arc/input/arc_input_bridge.h',
'arc/net/arc_net_host_impl.cc',
'arc/net/arc_net_host_impl.h',
'arc/power/arc_power_bridge.cc',
'arc/power/arc_power_bridge.h',
],
......@@ -83,6 +86,7 @@
'arc/common/ime.mojom',
'arc/common/input.mojom',
'arc/common/intent_helper.mojom',
'arc/common/net.mojom',
'arc/common/notifications.mojom',
'arc/common/power.mojom',
'arc/common/process.mojom',
......
......@@ -25,6 +25,8 @@ static_library("arc") {
"ime/arc_ime_ipc_host_impl.h",
"input/arc_input_bridge.cc",
"input/arc_input_bridge.h",
"net/arc_net_host_impl.cc",
"net/arc_net_host_impl.h",
"power/arc_power_bridge.cc",
"power/arc_power_bridge.h",
]
......@@ -34,6 +36,7 @@ static_library("arc") {
"//base:prefs",
"//chromeos",
"//chromeos:power_manager_proto",
"//components/onc",
"//components/signin/core/account_id",
"//ipc:ipc",
"//ipc/mojo:mojo",
......@@ -60,6 +63,7 @@ mojom("arc_bindings") {
"common/ime.mojom",
"common/input.mojom",
"common/intent_helper.mojom",
"common/net.mojom",
"common/notifications.mojom",
"common/power.mojom",
"common/process.mojom",
......
......@@ -63,6 +63,8 @@ void ArcBridgeService::AddObserver(Observer* observer) {
observer->OnImeInstanceReady();
if (input_instance())
observer->OnInputInstanceReady();
if (net_instance())
observer->OnNetInstanceReady();
if (notifications_instance())
observer->OnNotificationsInstanceReady();
if (power_instance())
......@@ -223,6 +225,30 @@ void ArcBridgeService::CloseIntentHelperChannel() {
FOR_EACH_OBSERVER(Observer, observer_list(), OnIntentHelperInstanceClosed());
}
void ArcBridgeService::OnNetInstanceReady(NetInstancePtr net_ptr) {
DCHECK(CalledOnValidThread());
temporary_net_ptr_ = std::move(net_ptr);
temporary_net_ptr_.QueryVersion(base::Bind(
&ArcBridgeService::OnNetVersionReady, weak_factory_.GetWeakPtr()));
}
void ArcBridgeService::OnNetVersionReady(int32_t version) {
DCHECK(CalledOnValidThread());
net_ptr_ = std::move(temporary_net_ptr_);
net_ptr_.set_connection_error_handler(base::Bind(
&ArcBridgeService::CloseNetChannel, weak_factory_.GetWeakPtr()));
FOR_EACH_OBSERVER(Observer, observer_list(), OnNetInstanceReady());
}
void ArcBridgeService::CloseNetChannel() {
DCHECK(CalledOnValidThread());
if (!net_ptr_)
return;
net_ptr_.reset();
FOR_EACH_OBSERVER(Observer, observer_list(), OnNetInstanceClosed());
}
void ArcBridgeService::OnNotificationsInstanceReady(
NotificationsInstancePtr notifications_ptr) {
DCHECK(CalledOnValidThread());
......@@ -331,6 +357,7 @@ void ArcBridgeService::CloseAllChannels() {
CloseImeChannel();
CloseInputChannel();
CloseIntentHelperChannel();
CloseNetChannel();
CloseNotificationsChannel();
ClosePowerChannel();
CloseProcessChannel();
......
......@@ -101,6 +101,10 @@ class ArcBridgeService : public ArcBridgeHost {
virtual void OnNotificationsInstanceReady() {}
virtual void OnNotificationsInstanceClosed() {}
// Called whenever the ARC net interface state changes.
virtual void OnNetInstanceReady() {}
virtual void OnNetInstanceClosed() {}
// Called whenever the ARC power interface state changes.
virtual void OnPowerInstanceReady() {}
virtual void OnPowerInstanceClosed() {}
......@@ -154,6 +158,7 @@ class ArcBridgeService : public ArcBridgeHost {
IntentHelperInstance* intent_helper_instance() {
return intent_helper_ptr_.get();
}
NetInstance* net_instance() { return net_ptr_.get(); }
NotificationsInstance* notifications_instance() {
return notifications_ptr_.get();
}
......@@ -178,6 +183,7 @@ class ArcBridgeService : public ArcBridgeHost {
void OnInputInstanceReady(InputInstancePtr input_ptr) override;
void OnIntentHelperInstanceReady(
IntentHelperInstancePtr intent_helper_ptr) override;
void OnNetInstanceReady(NetInstancePtr net_ptr) override;
void OnNotificationsInstanceReady(
NotificationsInstancePtr notifications_ptr) override;
void OnPowerInstanceReady(PowerInstancePtr power_ptr) override;
......@@ -220,6 +226,7 @@ class ArcBridgeService : public ArcBridgeHost {
void CloseImeChannel();
void CloseInputChannel();
void CloseIntentHelperChannel();
void CloseNetChannel();
void CloseNotificationsChannel();
void ClosePowerChannel();
void CloseProcessChannel();
......@@ -231,6 +238,7 @@ class ArcBridgeService : public ArcBridgeHost {
void OnImeVersionReady(int32_t version);
void OnInputVersionReady(int32_t version);
void OnIntentHelperVersionReady(int32_t version);
void OnNetVersionReady(int32_t version);
void OnNotificationsVersionReady(int32_t version);
void OnPowerVersionReady(int32_t version);
void OnProcessVersionReady(int32_t version);
......@@ -242,6 +250,7 @@ class ArcBridgeService : public ArcBridgeHost {
ImeInstancePtr ime_ptr_;
InputInstancePtr input_ptr_;
IntentHelperInstancePtr intent_helper_ptr_;
NetInstancePtr net_ptr_;
NotificationsInstancePtr notifications_ptr_;
PowerInstancePtr power_ptr_;
ProcessInstancePtr process_ptr_;
......@@ -258,6 +267,7 @@ class ArcBridgeService : public ArcBridgeHost {
ImeInstancePtr temporary_ime_ptr_;
InputInstancePtr temporary_input_ptr_;
IntentHelperInstancePtr temporary_intent_helper_ptr_;
NetInstancePtr temporary_net_ptr_;
NotificationsInstancePtr temporary_notifications_ptr_;
PowerInstancePtr temporary_power_ptr_;
ProcessInstancePtr temporary_process_ptr_;
......
......@@ -11,6 +11,7 @@
#include "components/arc/clipboard/arc_clipboard_bridge.h"
#include "components/arc/ime/arc_ime_bridge.h"
#include "components/arc/input/arc_input_bridge.h"
#include "components/arc/net/arc_net_host_impl.h"
#include "components/arc/power/arc_power_bridge.h"
#include "ui/arc/notification/arc_notification_manager.h"
......@@ -32,6 +33,7 @@ ArcServiceManager::ArcServiceManager()
AddService(make_scoped_ptr(new ArcClipboardBridge(arc_bridge_service())));
AddService(make_scoped_ptr(new ArcImeBridge(arc_bridge_service())));
AddService(make_scoped_ptr(new ArcInputBridge(arc_bridge_service())));
AddService(make_scoped_ptr(new ArcNetHostImpl(arc_bridge_service())));
AddService(make_scoped_ptr(new ArcPowerBridge(arc_bridge_service())));
}
......
......@@ -10,6 +10,7 @@ import "clipboard.mojom";
import "ime.mojom";
import "input.mojom";
import "intent_helper.mojom";
import "net.mojom";
import "notifications.mojom";
import "power.mojom";
import "process.mojom";
......@@ -39,6 +40,9 @@ interface ArcBridgeHost {
[MinVersion=4] OnIntentHelperInstanceReady@111(
IntentHelperInstance instance_ptr);
// Notifies Chrome that the NetInstance interface is ready.
[MinVersion=5] OnNetInstanceReady@108(NetInstance instance_ptr);
// Notifies Chrome that the NotificationsInstance interface is ready.
OnNotificationsInstanceReady@102(NotificationsInstance instance_ptr);
......
// Copyright 2015 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.
module arc;
enum NetworkResult {
SUCCESS = 0,
FAILURE = 1,
};
struct WifiConfiguration {
// These correspond to ONC properties returned by
// chrome.networkingPrivate.getNetworks().
// See components/onc/docs/onc_spec.html
string ssid;
int32 frequency;
int32 signal_strength;
string bssid;
string security;
};
struct NetworkData {
NetworkResult status;
array<WifiConfiguration> networks;
};
interface NetHost {
// Sends a request to get configured or visible WiFi networks based on the
// |configured_only| and |visible_only| flags.
GetNetworks@0(bool configured_only, bool visible_only) => (NetworkData data);
};
interface NetInstance {
// Establishes full-duplex communication with the host.
Init@0(NetHost host_ptr);
};
include_rules = [
"+chromeos/network",
"+components/onc",
]
// Copyright 2015 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 "components/arc/net/arc_net_host_impl.h"
#include <string>
#include <vector>
#include "base/logging.h"
#include "base/posix/eintr_wrapper.h"
#include "base/thread_task_runner_handle.h"
#include "base/time/time.h"
#include "chromeos/network/network_util.h"
#include "chromeos/network/onc/onc_utils.h"
#include "components/arc/arc_bridge_service.h"
#include "third_party/mojo/src/mojo/edk/embedder/embedder.h"
namespace {
const int kGetNetworksListLimit = 100;
} // namespace
namespace arc {
ArcNetHostImpl::ArcNetHostImpl(ArcBridgeService* bridge_service)
: ArcService(bridge_service), binding_(this) {
arc_bridge_service()->AddObserver(this);
}
ArcNetHostImpl::~ArcNetHostImpl() {
DCHECK(thread_checker_.CalledOnValidThread());
arc_bridge_service()->RemoveObserver(this);
}
void ArcNetHostImpl::OnNetInstanceReady() {
DCHECK(thread_checker_.CalledOnValidThread());
NetHostPtr host;
binding_.Bind(GetProxy(&host));
arc_bridge_service()->net_instance()->Init(std::move(host));
}
void ArcNetHostImpl::GetNetworks(bool configured_only,
bool visible_only,
const GetNetworksCallback& callback) {
NetworkDataPtr data = NetworkData::New();
data->status = NetworkResult::SUCCESS;
// Retrieve list of nearby wifi networks
chromeos::NetworkTypePattern network_pattern =
chromeos::onc::NetworkTypePatternFromOncType(onc::network_type::kWiFi);
scoped_ptr<base::ListValue> network_properties_list =
chromeos::network_util::TranslateNetworkListToONC(
network_pattern, configured_only, visible_only,
kGetNetworksListLimit);
// Extract info for each network and add it to the list.
for (base::Value* value : *network_properties_list) {
WifiConfigurationPtr wc = WifiConfiguration::New();
base::DictionaryValue* network_dict = nullptr;
value->GetAsDictionary(&network_dict);
DCHECK(network_dict);
// kName is a post-processed version of kHexSSID.
std::string tmp;
network_dict->GetString(onc::network_config::kName, &tmp);
DCHECK(!tmp.empty());
wc->ssid = tmp;
base::DictionaryValue* wifi_dict = nullptr;
network_dict->GetDictionary(onc::network_config::kWiFi, &wifi_dict);
DCHECK(wifi_dict);
if (!wifi_dict->GetInteger(onc::wifi::kFrequency, &wc->frequency))
wc->frequency = 0;
if (!wifi_dict->GetInteger(onc::wifi::kSignalStrength,
&wc->signal_strength))
wc->signal_strength = 0;
if (!wifi_dict->GetString(onc::wifi::kSecurity, &tmp))
NOTREACHED();
DCHECK(!tmp.empty());
wc->security = tmp;
if (!wifi_dict->GetString(onc::wifi::kBSSID, &tmp))
NOTREACHED();
DCHECK(!tmp.empty());
wc->bssid = tmp;
data->networks.push_back(std::move(wc));
}
callback.Run(std::move(data));
}
} // namespace arc
// Copyright 2015 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 COMPONENTS_ARC_NET_ARC_NET_HOST_IMPL_H_
#define COMPONENTS_ARC_NET_ARC_NET_HOST_IMPL_H_
#include <stdint.h>
#include <string>
#include <vector>
#include "base/files/scoped_file.h"
#include "base/macros.h"
#include "base/threading/thread_checker.h"
#include "components/arc/arc_bridge_service.h"
#include "components/arc/arc_service.h"
#include "components/arc/common/net.mojom.h"
#include "mojo/public/cpp/bindings/binding.h"
namespace arc {
class ArcBridgeService;
// Private implementation of ArcNetHost.
class ArcNetHostImpl : public ArcService,
public ArcBridgeService::Observer,
public NetHost {
public:
// The constructor will register an Observer with ArcBridgeService.
explicit ArcNetHostImpl(ArcBridgeService* arc_bridge_service);
~ArcNetHostImpl() override;
// Called when a GetNetworks call is sent from ARC.
void GetNetworks(bool configured_only,
bool visible_only,
const GetNetworksCallback& callback) override;
// Overridden from ArcBridgeService::Observer:
void OnNetInstanceReady() override;
private:
base::ThreadChecker thread_checker_;
mojo::Binding<arc::NetHost> binding_;
DISALLOW_COPY_AND_ASSIGN(ArcNetHostImpl);
};
} // namespace arc
#endif // COMPONENTS_ARC_NET_ARC_NET_HOST_IMPL_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment