Chromium Code Reviews| 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), | |
| 29 binding_(this), | |
| 30 weak_factory_(this) { | |
| 31 arc_bridge_service()->AddObserver(this); | |
| 32 } | |
| 33 | |
| 34 ArcNetHostImpl::~ArcNetHostImpl() { | |
| 35 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 36 arc_bridge_service()->RemoveObserver(this); | |
| 37 } | |
| 38 | |
| 39 void ArcNetHostImpl::OnNetInstanceReady() { | |
| 40 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 41 | |
| 42 NetHostPtr host; | |
| 43 binding_.Bind(GetProxy(&host)); | |
| 44 arc_bridge_service()->net_instance()->Init(std::move(host)); | |
| 45 } | |
| 46 | |
| 47 void ArcNetHostImpl::GetNetworks(bool configured_only, | |
| 48 bool visible_only, | |
| 49 const GetNetworksCallback& callback) { | |
| 50 NetworkDataPtr data = NetworkData::New(); | |
| 51 data->status = NetworkResult::SUCCESS; | |
| 52 | |
| 53 // Retrieve list of nearby wifi networks | |
| 54 chromeos::NetworkTypePattern network_pattern = | |
| 55 chromeos::onc::NetworkTypePatternFromOncType(onc::network_type::kWiFi); | |
| 56 scoped_ptr<base::ListValue> network_properties_list = | |
| 57 chromeos::network_util::TranslateNetworkListToONC( | |
| 58 network_pattern, configured_only, visible_only, | |
| 59 kGetNetworksListLimit); | |
| 60 | |
| 61 // Extract info for each network and add it to the list. | |
| 62 for (base::Value* value : *network_properties_list) { | |
| 63 WifiConfigurationPtr wc = WifiConfiguration::New(); | |
| 64 | |
| 65 base::DictionaryValue* network_dict = nullptr; | |
| 66 value->GetAsDictionary(&network_dict); | |
| 67 DCHECK(network_dict); | |
| 68 | |
| 69 // kName is a post-processed version of kHexSSID. | |
| 70 std::string tmp; | |
| 71 network_dict->GetString(onc::network_config::kName, &tmp); | |
| 72 wc->ssid = tmp; | |
| 73 | |
| 74 base::DictionaryValue* wifi_dict = nullptr; | |
| 75 network_dict->GetDictionary(onc::network_config::kWiFi, &wifi_dict); | |
| 76 DCHECK(wifi_dict); | |
| 77 | |
| 78 wifi_dict->GetInteger(onc::wifi::kFrequency, &wc->frequency); | |
| 79 wifi_dict->GetInteger(onc::wifi::kSignalStrength, &wc->signal_strength); | |
|
stevenjb
2016/01/25 18:58:22
Is there a way to specify default values in mojo?
cernekee
2016/01/25 20:49:36
Done.
| |
| 80 wifi_dict->GetString(onc::wifi::kSecurity, &tmp); | |
|
stevenjb
2016/01/25 18:58:22
This should never fail or return empty (no wifi se
cernekee
2016/01/25 20:49:36
Done.
| |
| 81 wc->security = tmp; | |
| 82 wifi_dict->GetString(onc::wifi::kBSSID, &tmp); | |
|
stevenjb
2016/01/25 18:58:22
We can also CHECK this.
cernekee
2016/01/25 20:49:36
Done.
| |
| 83 wc->bssid = tmp; | |
| 84 | |
| 85 data->networks.push_back(std::move(wc)); | |
| 86 } | |
| 87 | |
| 88 callback.Run(std::move(data)); | |
| 89 } | |
| 90 | |
| 91 } // namespace arc | |
| OLD | NEW |