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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "components/arc/net/arc_net_host_impl.h"
6
7 #include <string>
8 #include <vector>
9
10 #include "base/logging.h"
11 #include "base/posix/eintr_wrapper.h"
12 #include "base/thread_task_runner_handle.h"
13 #include "base/time/time.h"
14 #include "chromeos/network/network_util.h"
15 #include "chromeos/network/onc/onc_utils.h"
16 #include "components/arc/arc_bridge_service.h"
17 #include "components/onc/onc_constants.h"
18 #include "third_party/mojo/src/mojo/edk/embedder/embedder.h"
19
20 namespace {
21
22 const int kGetNetworksListLimit = 100;
23
24 } // namespace
25
26 namespace arc {
27
28 ArcNetHostImpl::ArcNetHostImpl(ArcBridgeService* arc_bridge_service)
29 : arc_bridge_service_(arc_bridge_service),
30 binding_(this),
31 weak_factory_(this) {
32 arc_bridge_service->AddObserver(this);
33 if (arc_bridge_service->net_instance())
34 OnNetInstanceReady();
35 }
36
37 ArcNetHostImpl::~ArcNetHostImpl() {
38 DCHECK(thread_checker_.CalledOnValidThread());
39 arc_bridge_service_->RemoveObserver(this);
40 }
41
42 void ArcNetHostImpl::OnNetInstanceReady() {
43 DCHECK(thread_checker_.CalledOnValidThread());
44
45 NetHostPtr host;
46 binding_.Bind(GetProxy(&host));
47 arc_bridge_service_->net_instance()->Init(std::move(host));
48 }
49
50 void ArcNetHostImpl::GetNetworks(bool configured_only,
51 bool visible_only,
52 const GetNetworksCallback& callback) {
53 NetworkDataPtr data = NetworkData::New();
54 data->status = NETWORK_RESULT_SUCCESS;
55
56 // Retrieve list of nearby wifi networks
57 chromeos::NetworkTypePattern network_pattern =
58 chromeos::onc::NetworkTypePatternFromOncType(onc::network_type::kWiFi);
59 scoped_ptr<base::ListValue> network_properties_list =
60 chromeos::network_util::TranslateNetworkListToONC(
61 network_pattern, configured_only, visible_only,
62 kGetNetworksListLimit);
63
64 // Extract info for each network and add it to the list.
65 for (base::Value* value : *network_properties_list) {
66 WifiConfigurationPtr wc = WifiConfiguration::New();
67
68 base::DictionaryValue* network_dict = nullptr;
69 value->GetAsDictionary(&network_dict);
70 DCHECK(network_dict);
71
72 // kName is a post-processed version of kHexSSID.
73 std::string tmp;
74 network_dict->GetString(onc::network_config::kName, &tmp);
75 wc->ssid = tmp;
76
77 base::DictionaryValue* wifi_dict = nullptr;
78 network_dict->GetDictionary(onc::network_config::kWiFi, &wifi_dict);
79 DCHECK(wifi_dict);
80
81 wifi_dict->GetInteger(onc::wifi::kFrequency, &wc->frequency);
82 wifi_dict->GetInteger(onc::wifi::kSignalStrength, &wc->signal_strength);
83 wifi_dict->GetString(onc::wifi::kSecurity, &tmp);
84 wc->security = tmp;
85 wifi_dict->GetString(onc::wifi::kBSSID, &tmp);
86 wc->bssid = tmp;
87
88 data->networks.push_back(std::move(wc));
89 }
90
91 callback.Run(std::move(data));
92 }
93
94 } // namespace arc
OLDNEW
« 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