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

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: remove weak_factory_ Created 4 years, 10 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
(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 "third_party/mojo/src/mojo/edk/embedder/embedder.h"
18
19 namespace {
20
21 const int kGetNetworksListLimit = 100;
22
23 } // namespace
24
25 namespace arc {
26
27 ArcNetHostImpl::ArcNetHostImpl(ArcBridgeService* bridge_service)
28 : ArcService(bridge_service), binding_(this) {
29 arc_bridge_service()->AddObserver(this);
30 }
31
32 ArcNetHostImpl::~ArcNetHostImpl() {
33 DCHECK(thread_checker_.CalledOnValidThread());
34 arc_bridge_service()->RemoveObserver(this);
35 }
36
37 void ArcNetHostImpl::OnNetInstanceReady() {
38 DCHECK(thread_checker_.CalledOnValidThread());
39
40 NetHostPtr host;
41 binding_.Bind(GetProxy(&host));
42 arc_bridge_service()->net_instance()->Init(std::move(host));
43 }
44
45 void ArcNetHostImpl::GetNetworks(bool configured_only,
46 bool visible_only,
47 const GetNetworksCallback& callback) {
48 NetworkDataPtr data = NetworkData::New();
49 data->status = NetworkResult::SUCCESS;
50
51 // Retrieve list of nearby wifi networks
52 chromeos::NetworkTypePattern network_pattern =
53 chromeos::onc::NetworkTypePatternFromOncType(onc::network_type::kWiFi);
54 scoped_ptr<base::ListValue> network_properties_list =
55 chromeos::network_util::TranslateNetworkListToONC(
56 network_pattern, configured_only, visible_only,
57 kGetNetworksListLimit);
58
59 // Extract info for each network and add it to the list.
60 for (base::Value* value : *network_properties_list) {
61 WifiConfigurationPtr wc = WifiConfiguration::New();
62
63 base::DictionaryValue* network_dict = nullptr;
64 value->GetAsDictionary(&network_dict);
65 DCHECK(network_dict);
66
67 // kName is a post-processed version of kHexSSID.
68 std::string tmp;
69 network_dict->GetString(onc::network_config::kName, &tmp);
70 DCHECK(!tmp.empty());
71 wc->ssid = tmp;
72
73 base::DictionaryValue* wifi_dict = nullptr;
74 network_dict->GetDictionary(onc::network_config::kWiFi, &wifi_dict);
75 DCHECK(wifi_dict);
76
77 if (!wifi_dict->GetInteger(onc::wifi::kFrequency, &wc->frequency))
78 wc->frequency = 0;
79 if (!wifi_dict->GetInteger(onc::wifi::kSignalStrength,
80 &wc->signal_strength))
81 wc->signal_strength = 0;
82
83 if (!wifi_dict->GetString(onc::wifi::kSecurity, &tmp))
84 NOTREACHED();
85 DCHECK(!tmp.empty());
86 wc->security = tmp;
87
88 if (!wifi_dict->GetString(onc::wifi::kBSSID, &tmp))
89 NOTREACHED();
90 DCHECK(!tmp.empty());
91 wc->bssid = tmp;
92
93 data->networks.push_back(std::move(wc));
94 }
95
96 callback.Run(std::move(data));
97 }
98
99 } // 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