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 "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 if (!value->GetAsDictionary(&network_dict)) { | |
70 LOG(ERROR) << "Error parsing NetworkStateProperties"; | |
71 continue; | |
72 } | |
73 | |
74 std::string tmp; | |
75 network_dict->GetString(onc::network_config::kName, &tmp); | |
76 wc->ssid = tmp; | |
77 | |
78 base::DictionaryValue* wifi_dict = nullptr; | |
79 if (!network_dict->GetDictionary(onc::network_config::kWiFi, &wifi_dict)) { | |
80 LOG(ERROR) << "Error parsing NetworkStateProperties.WiFi"; | |
81 continue; | |
stevenjb
2016/01/14 18:18:54
DCHECK
cernekee
2016/01/14 21:22:23
Done.
| |
82 } | |
83 | |
84 wifi_dict->GetInteger(onc::wifi::kFrequency, &wc->frequency); | |
85 wifi_dict->GetInteger(onc::wifi::kSignalStrength, &wc->signal_strength); | |
86 wifi_dict->GetString(onc::wifi::kSecurity, &tmp); | |
87 wc->security = tmp; | |
88 wifi_dict->GetString(onc::wifi::kBSSID, &tmp); | |
89 wc->bssid = tmp; | |
90 | |
91 data->networks.push_back(std::move(wc)); | |
92 } | |
93 | |
94 callback.Run(std::move(data)); | |
95 } | |
96 | |
97 } // namespace arc | |
OLD | NEW |