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

Unified Diff: components/arc/net/arc_net_host_impl.cc

Issue 1572483002: Implement OnGetNetworks for net.mojom (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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: components/arc/net/arc_net_host_impl.cc
diff --git a/components/arc/net/arc_net_host_impl.cc b/components/arc/net/arc_net_host_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..44f7226478735399049c45adbd7698e0798520bf
--- /dev/null
+++ b/components/arc/net/arc_net_host_impl.cc
@@ -0,0 +1,104 @@
+// 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 "components/onc/onc_constants.h"
+#include "third_party/mojo/src/mojo/edk/embedder/embedder.h"
+
+namespace {
+
+const int kGetNetworksListLimit = 100;
+
+} // namespace
+
+namespace arc {
+
+ArcNetHostImpl::ArcNetHostImpl(ArcBridgeService* arc_bridge_service)
+ : arc_bridge_service_(arc_bridge_service),
+ origin_task_runner_(base::ThreadTaskRunnerHandle::Get()),
+ binding_(this),
+ weak_factory_(this) {
+ arc_bridge_service->AddObserver(this);
+ if (arc_bridge_service->net_instance())
+ OnNetInstanceReady();
+}
+
+ArcNetHostImpl::~ArcNetHostImpl() {
+ DCHECK(origin_task_runner_->RunsTasksOnCurrentThread());
hidehiko 2016/01/13 05:58:56 base::ThreadChecker instead?
cernekee 2016/01/14 03:08:58 Done.
+ arc_bridge_service_->RemoveObserver(this);
+}
+
+void ArcNetHostImpl::OnNetInstanceReady() {
+ DCHECK(origin_task_runner_->RunsTasksOnCurrentThread());
hidehiko 2016/01/13 05:58:56 Ditto.
cernekee 2016/01/14 03:08:58 Done.
+
+ NetHostPtr host;
+ binding_.Bind(GetProxy(&host));
+ arc_bridge_service_->net_instance()->Init(std::move(host));
+}
+
+bool ArcNetHostImpl::SendNetworks(int request_id,
+ NetworkDataPtr data) {
stevenjb 2016/01/12 22:14:04 align
Kevin Cernekee 2016/01/12 23:53:27 Done.
+ arc_bridge_service_->net_instance()->SendNetworks(request_id,
+ std::move(data));
+ return true;
+}
+
+void ArcNetHostImpl::OnGetNetworks(int request_id,
+ bool configured_only,
+ bool visible_only) {
+ NetworkDataPtr data = NetworkData::New();
+ data->status = NETWORK_RESULT_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(
stevenjb 2016/01/12 22:14:04 4 space indent
Kevin Cernekee 2016/01/12 23:53:27 Done.
+ 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();
stevenjb 2016/01/12 22:14:04 2 space indent
Kevin Cernekee 2016/01/12 23:53:27 Done.
+
+ base::DictionaryValue* network_dict = nullptr;
+ value->GetAsDictionary(&network_dict);
+ DCHECK(network_dict);
hidehiko 2016/01/13 05:58:56 Instead, you may want to check the return value of
cernekee 2016/01/14 03:08:58 Done.
stevenjb 2016/01/14 18:18:54 Actually, the DCHECK was fine (and preferred). It
cernekee 2016/01/14 21:22:23 Done.
+
+ std::string tmp;
+ network_dict->GetString(onc::network_config::kName, &tmp);
+ wc->ssid = tmp;
stevenjb 2016/01/12 22:14:04 Name != SSID. Use kSSID or call the member name. (
Kevin Cernekee 2016/01/12 23:53:27 OK, fixed. Does the string handling / casting / p
cernekee 2016/01/14 03:08:58 I take that back. I did not see where kSSID gets
stevenjb 2016/01/14 18:18:54 Apologies, I forgot that we actually process the H
cernekee 2016/01/14 21:22:23 Done.
+
+ base::DictionaryValue* wifi_dict = nullptr;
+ network_dict->GetDictionary(onc::network_config::kWiFi, &wifi_dict);
+ DCHECK(wifi_dict);
+
+ wifi_dict->GetInteger(onc::wifi::kFrequency, &wc->frequency);
+ wifi_dict->GetInteger(onc::wifi::kSignalStrength,
+ &wc->signal_strength);
+ wifi_dict->GetString(onc::wifi::kSecurity, &tmp);
+ wc->security = tmp;
+ wifi_dict->GetString(onc::wifi::kBSSID, &tmp);
+ wc->bssid = tmp;
+
+ data->networks.push_back(std::move(wc));
+ }
+
+ SendNetworks(request_id, std::move(data));
+}
+
+} // namespace arc
« components/arc/net/arc_net_host_impl.h ('K') | « 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