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

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: fix more review comments 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"
stevenjb 2016/01/20 01:43:42 This should fail to compile on non chromeos platfo
cernekee 2016/01/22 19:58:41 Acknowledged.
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* arc_bridge_service)
28 : arc_bridge_service_(arc_bridge_service),
29 binding_(this),
30 weak_factory_(this) {
31 arc_bridge_service->AddObserver(this);
32 if (arc_bridge_service->net_instance())
33 OnNetInstanceReady();
34 }
35
36 ArcNetHostImpl::~ArcNetHostImpl() {
37 DCHECK(thread_checker_.CalledOnValidThread());
38 arc_bridge_service_->RemoveObserver(this);
39 }
40
41 void ArcNetHostImpl::OnNetInstanceReady() {
42 DCHECK(thread_checker_.CalledOnValidThread());
43
44 NetHostPtr host;
45 binding_.Bind(GetProxy(&host));
46 arc_bridge_service_->net_instance()->Init(std::move(host));
47 }
48
49 void ArcNetHostImpl::GetNetworks(bool configured_only,
50 bool visible_only,
51 const GetNetworksCallback& callback) {
52 NetworkDataPtr data = NetworkData::New();
53 data->status = NETWORK_RESULT_SUCCESS;
54
55 // Retrieve list of nearby wifi networks
56 chromeos::NetworkTypePattern network_pattern =
57 chromeos::onc::NetworkTypePatternFromOncType(onc::network_type::kWiFi);
58 scoped_ptr<base::ListValue> network_properties_list =
59 chromeos::network_util::TranslateNetworkListToONC(
dcheng 2016/01/22 07:17:43 Can we just call GetNetworkListByType() directly?
cernekee 2016/01/22 19:58:41 Not sure - I think abhishekbh and stevenjb made a
stevenjb 2016/01/22 21:08:28 ONC is preferred for high level communication betw
dcheng 2016/01/23 05:12:41 They can fail though (for example, if the format o
60 network_pattern, configured_only, visible_only,
61 kGetNetworksListLimit);
62
63 // Extract info for each network and add it to the list.
64 for (base::Value* value : *network_properties_list) {
65 WifiConfigurationPtr wc = WifiConfiguration::New();
66
67 base::DictionaryValue* network_dict = nullptr;
68 value->GetAsDictionary(&network_dict);
69 DCHECK(network_dict);
70
71 // kName is a post-processed version of kHexSSID.
72 std::string tmp;
73 network_dict->GetString(onc::network_config::kName, &tmp);
74 wc->ssid = tmp;
75
76 base::DictionaryValue* wifi_dict = nullptr;
77 network_dict->GetDictionary(onc::network_config::kWiFi, &wifi_dict);
78 DCHECK(wifi_dict);
79
80 wifi_dict->GetInteger(onc::wifi::kFrequency, &wc->frequency);
81 wifi_dict->GetInteger(onc::wifi::kSignalStrength, &wc->signal_strength);
82 wifi_dict->GetString(onc::wifi::kSecurity, &tmp);
83 wc->security = tmp;
84 wifi_dict->GetString(onc::wifi::kBSSID, &tmp);
85 wc->bssid = tmp;
86
87 data->networks.push_back(std::move(wc));
88 }
89
90 callback.Run(std::move(data));
91 }
92
93 } // 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