OLD | NEW |
---|---|
(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), weak_factory_(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); | |
dcheng
2016/01/25 23:35:32
How come there's no DCHECK here?
cernekee
2016/01/25 23:49:53
Done.
| |
70 wc->ssid = tmp; | |
71 | |
72 base::DictionaryValue* wifi_dict = nullptr; | |
73 network_dict->GetDictionary(onc::network_config::kWiFi, &wifi_dict); | |
74 DCHECK(wifi_dict); | |
75 | |
76 if (!wifi_dict->GetInteger(onc::wifi::kFrequency, &wc->frequency)) | |
77 wc->frequency = 0; | |
78 if (!wifi_dict->GetInteger(onc::wifi::kSignalStrength, | |
79 &wc->signal_strength)) | |
80 wc->signal_strength = 0; | |
81 | |
82 wifi_dict->GetString(onc::wifi::kSecurity, &tmp); | |
83 CHECK(!tmp.empty()); | |
dcheng
2016/01/25 23:35:32
DCHECK is fine here, since it should never happen.
cernekee
2016/01/25 23:49:53
Done.
| |
84 wc->security = tmp; | |
85 | |
86 wifi_dict->GetString(onc::wifi::kBSSID, &tmp); | |
87 CHECK(!tmp.empty()); | |
dcheng
2016/01/25 23:35:32
Ditto.
cernekee
2016/01/25 23:49:53
Done.
| |
88 wc->bssid = tmp; | |
89 | |
90 data->networks.push_back(std::move(wc)); | |
91 } | |
92 | |
93 callback.Run(std::move(data)); | |
94 } | |
95 | |
96 } // namespace arc | |
OLD | NEW |