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 "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 origin_task_runner_(base::ThreadTaskRunnerHandle::Get()), | |
| 31 binding_(this), | |
| 32 weak_factory_(this) { | |
| 33 arc_bridge_service->AddObserver(this); | |
| 34 if (arc_bridge_service->net_instance()) | |
| 35 OnNetInstanceReady(); | |
| 36 } | |
| 37 | |
| 38 ArcNetHostImpl::~ArcNetHostImpl() { | |
| 39 DCHECK(origin_task_runner_->RunsTasksOnCurrentThread()); | |
|
hidehiko
2016/01/13 05:58:56
base::ThreadChecker instead?
cernekee
2016/01/14 03:08:58
Done.
| |
| 40 arc_bridge_service_->RemoveObserver(this); | |
| 41 } | |
| 42 | |
| 43 void ArcNetHostImpl::OnNetInstanceReady() { | |
| 44 DCHECK(origin_task_runner_->RunsTasksOnCurrentThread()); | |
|
hidehiko
2016/01/13 05:58:56
Ditto.
cernekee
2016/01/14 03:08:58
Done.
| |
| 45 | |
| 46 NetHostPtr host; | |
| 47 binding_.Bind(GetProxy(&host)); | |
| 48 arc_bridge_service_->net_instance()->Init(std::move(host)); | |
| 49 } | |
| 50 | |
| 51 bool ArcNetHostImpl::SendNetworks(int request_id, | |
| 52 NetworkDataPtr data) { | |
|
stevenjb
2016/01/12 22:14:04
align
Kevin Cernekee
2016/01/12 23:53:27
Done.
| |
| 53 arc_bridge_service_->net_instance()->SendNetworks(request_id, | |
| 54 std::move(data)); | |
| 55 return true; | |
| 56 } | |
| 57 | |
| 58 void ArcNetHostImpl::OnGetNetworks(int request_id, | |
| 59 bool configured_only, | |
| 60 bool visible_only) { | |
| 61 NetworkDataPtr data = NetworkData::New(); | |
| 62 data->status = NETWORK_RESULT_SUCCESS; | |
| 63 | |
| 64 // Retrieve list of nearby wifi networks | |
| 65 chromeos::NetworkTypePattern network_pattern = | |
| 66 chromeos::onc::NetworkTypePatternFromOncType(onc::network_type::kWiFi); | |
| 67 scoped_ptr<base::ListValue> network_properties_list = | |
| 68 chromeos::network_util::TranslateNetworkListToONC( | |
|
stevenjb
2016/01/12 22:14:04
4 space indent
Kevin Cernekee
2016/01/12 23:53:27
Done.
| |
| 69 network_pattern, | |
| 70 configured_only, | |
| 71 visible_only, | |
| 72 kGetNetworksListLimit); | |
| 73 | |
| 74 // Extract info for each network and add it to the list. | |
| 75 for (base::Value* value : *network_properties_list) { | |
| 76 WifiConfigurationPtr wc = WifiConfiguration::New(); | |
|
stevenjb
2016/01/12 22:14:04
2 space indent
Kevin Cernekee
2016/01/12 23:53:27
Done.
| |
| 77 | |
| 78 base::DictionaryValue* network_dict = nullptr; | |
| 79 value->GetAsDictionary(&network_dict); | |
| 80 DCHECK(network_dict); | |
|
hidehiko
2016/01/13 05:58:56
Instead, you may want to check the return value of
cernekee
2016/01/14 03:08:58
Done.
stevenjb
2016/01/14 18:18:54
Actually, the DCHECK was fine (and preferred). It
cernekee
2016/01/14 21:22:23
Done.
| |
| 81 | |
| 82 std::string tmp; | |
| 83 network_dict->GetString(onc::network_config::kName, &tmp); | |
| 84 wc->ssid = tmp; | |
|
stevenjb
2016/01/12 22:14:04
Name != SSID. Use kSSID or call the member name. (
Kevin Cernekee
2016/01/12 23:53:27
OK, fixed.
Does the string handling / casting / p
cernekee
2016/01/14 03:08:58
I take that back. I did not see where kSSID gets
stevenjb
2016/01/14 18:18:54
Apologies, I forgot that we actually process the H
cernekee
2016/01/14 21:22:23
Done.
| |
| 85 | |
| 86 base::DictionaryValue* wifi_dict = nullptr; | |
| 87 network_dict->GetDictionary(onc::network_config::kWiFi, &wifi_dict); | |
| 88 DCHECK(wifi_dict); | |
| 89 | |
| 90 wifi_dict->GetInteger(onc::wifi::kFrequency, &wc->frequency); | |
| 91 wifi_dict->GetInteger(onc::wifi::kSignalStrength, | |
| 92 &wc->signal_strength); | |
| 93 wifi_dict->GetString(onc::wifi::kSecurity, &tmp); | |
| 94 wc->security = tmp; | |
| 95 wifi_dict->GetString(onc::wifi::kBSSID, &tmp); | |
| 96 wc->bssid = tmp; | |
| 97 | |
| 98 data->networks.push_back(std::move(wc)); | |
| 99 } | |
| 100 | |
| 101 SendNetworks(request_id, std::move(data)); | |
| 102 } | |
| 103 | |
| 104 } // namespace arc | |
| OLD | NEW |