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

Side by Side Diff: components/arc/net/arc_net_host_impl.cc

Issue 1751793002: ARC: Remove error status setting in GetNetworks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/arc/net/arc_net_host_impl.h" 5 #include "components/arc/net/arc_net_host_impl.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 } 45 }
46 46
47 void ArcNetHostImpl::OnNetInstanceReady() { 47 void ArcNetHostImpl::OnNetInstanceReady() {
48 DCHECK(thread_checker_.CalledOnValidThread()); 48 DCHECK(thread_checker_.CalledOnValidThread());
49 49
50 NetHostPtr host; 50 NetHostPtr host;
51 binding_.Bind(GetProxy(&host)); 51 binding_.Bind(GetProxy(&host));
52 arc_bridge_service()->net_instance()->Init(std::move(host)); 52 arc_bridge_service()->net_instance()->Init(std::move(host));
53 } 53 }
54 54
55 void ArcNetHostImpl::OnNetInstanceClosed() {
56 VLOG(1) << "OnNetInstanceClosed()";
57 }
58
55 void ArcNetHostImpl::GetNetworks(bool configured_only, 59 void ArcNetHostImpl::GetNetworks(bool configured_only,
56 bool visible_only, 60 bool visible_only,
57 const GetNetworksCallback& callback) { 61 const GetNetworksCallback& callback) {
Luis Héctor Chávez 2016/03/01 16:22:31 nit: add DCHECK(thread_checker_.CalledOnValidThrea
58 NetworkDataPtr data = NetworkData::New(); 62 NetworkDataPtr network_data = NetworkData::New();
59 data->status = NetworkResult::SUCCESS;
60 63
61 // Retrieve list of nearby wifi networks 64 // This API supports either configured or visible networks only. Return with a
62 chromeos::NetworkTypePattern network_pattern = 65 // failure if both flags are specified.
63 chromeos::onc::NetworkTypePatternFromOncType(onc::network_type::kWiFi); 66 if (configured_only && visible_only) {
Luis Héctor Chávez 2016/03/01 16:22:31 Hmmm this is problematic. Can you substitute these
abhishekbh 2016/03/02 19:16:31 I don't think that gets us anything for the follow
64 scoped_ptr<base::ListValue> network_properties_list = 67 network_data->status = NetworkResult::FAILURE;
65 chromeos::network_util::TranslateNetworkListToONC( 68 callback.Run(std::move(network_data));
66 network_pattern, configured_only, visible_only, 69 return;
67 kGetNetworksListLimit);
68
69 // Extract info for each network and add it to the list.
70 for (base::Value* value : *network_properties_list) {
71 WifiConfigurationPtr wc = WifiConfiguration::New();
72
73 base::DictionaryValue* network_dict = nullptr;
74 value->GetAsDictionary(&network_dict);
75 DCHECK(network_dict);
76
77 // kName is a post-processed version of kHexSSID.
78 std::string tmp;
79 network_dict->GetString(onc::network_config::kName, &tmp);
80 DCHECK(!tmp.empty());
81 wc->ssid = tmp;
82
83 base::DictionaryValue* wifi_dict = nullptr;
84 network_dict->GetDictionary(onc::network_config::kWiFi, &wifi_dict);
85 DCHECK(wifi_dict);
86
87 if (!wifi_dict->GetInteger(onc::wifi::kFrequency, &wc->frequency))
88 wc->frequency = 0;
89 if (!wifi_dict->GetInteger(onc::wifi::kSignalStrength,
90 &wc->signal_strength))
91 wc->signal_strength = 0;
92
93 if (!wifi_dict->GetString(onc::wifi::kSecurity, &tmp))
94 NOTREACHED();
95 DCHECK(!tmp.empty());
96 wc->security = tmp;
97
98 if (!wifi_dict->GetString(onc::wifi::kBSSID, &tmp))
99 NOTREACHED();
100 DCHECK(!tmp.empty());
101 wc->bssid = tmp;
102
103 data->networks.push_back(std::move(wc));
104 } 70 }
105 71
106 callback.Run(std::move(data)); 72 network_data->status = NetworkResult::SUCCESS;
73 // The network list is populated only if it wasn't invalidated by a scan
74 // completed event, else send over the cached networks list.
75 visible_networks_lock_.Acquire();
Luis Héctor Chávez 2016/03/01 16:22:31 This is the UI thred, so this is not allowed. How
76 if (cached_visible_networks_.size() == 0) {
77 // Retrieve list of nearby wifi networks
78 chromeos::NetworkTypePattern network_pattern =
79 chromeos::onc::NetworkTypePatternFromOncType(onc::network_type::kWiFi);
80 scoped_ptr<base::ListValue> network_properties_list =
81 chromeos::network_util::TranslateNetworkListToONC(
82 network_pattern, configured_only, visible_only,
83 kGetNetworksListLimit);
84
85 // Extract info for each network and add it to the list.
86 for (base::Value* value : *network_properties_list) {
87 WifiConfigurationPtr wc = WifiConfiguration::New();
88
89 base::DictionaryValue* network_dict = nullptr;
90 value->GetAsDictionary(&network_dict);
91 DCHECK(network_dict);
92
93 // kName is a post-processed version of kHexSSID.
94 std::string tmp;
95 network_dict->GetString(onc::network_config::kName, &tmp);
96 DCHECK(!tmp.empty());
97 wc->ssid = tmp;
98
99 base::DictionaryValue* wifi_dict = nullptr;
100 network_dict->GetDictionary(onc::network_config::kWiFi, &wifi_dict);
101 DCHECK(wifi_dict);
102
103 if (!wifi_dict->GetInteger(onc::wifi::kFrequency, &wc->frequency))
104 wc->frequency = 0;
105 if (!wifi_dict->GetInteger(onc::wifi::kSignalStrength,
106 &wc->signal_strength))
107 wc->signal_strength = 0;
108
109 if (!wifi_dict->GetString(onc::wifi::kSecurity, &tmp))
110 NOTREACHED();
111 DCHECK(!tmp.empty());
112 wc->security = tmp;
113
114 if (!wifi_dict->GetString(onc::wifi::kBSSID, &tmp))
115 NOTREACHED();
116 DCHECK(!tmp.empty());
117 wc->bssid = tmp;
118
119 network_data->networks.push_back(std::move(wc));
120 }
121 cached_visible_networks_ = network_data->networks.Clone();
122 } else {
123 network_data->networks = cached_visible_networks_.Clone();
124 }
125 visible_networks_lock_.Release();
126
127 callback.Run(std::move(network_data));
107 } 128 }
108 129
109 void ArcNetHostImpl::GetWifiEnabledState( 130 void ArcNetHostImpl::GetWifiEnabledState(
110 const GetWifiEnabledStateCallback& callback) { 131 const GetWifiEnabledStateCallback& callback) {
111 bool is_enabled = GetStateHandler()->IsTechnologyEnabled( 132 bool is_enabled = GetStateHandler()->IsTechnologyEnabled(
112 chromeos::NetworkTypePattern::WiFi()); 133 chromeos::NetworkTypePattern::WiFi());
113 134
114 callback.Run(is_enabled); 135 callback.Run(is_enabled);
115 } 136 }
116 137
117 void ArcNetHostImpl::StartScan() { 138 void ArcNetHostImpl::StartScan() {
118 GetStateHandler()->RequestScan(); 139 GetStateHandler()->RequestScan();
119 } 140 }
120 141
121 void ArcNetHostImpl::ScanCompleted(const chromeos::DeviceState* /*unused*/) { 142 void ArcNetHostImpl::ScanCompleted(const chromeos::DeviceState* /*unused*/) {
122 if (arc_bridge_service()->net_version() < 1) { 143 if (arc_bridge_service()->net_version() < 1) {
123 VLOG(1) << "ArcBridgeService does not support ScanCompleted."; 144 VLOG(1) << "ArcBridgeService does not support ScanCompleted.";
124 return; 145 return;
125 } 146 }
126 147
148 // Invalidate the networks list on a scan completion.
149 visible_networks_lock_.Acquire();
150 cached_visible_networks_.SetToEmpty();
151 visible_networks_lock_.Release();
152
127 arc_bridge_service()->net_instance()->ScanCompleted(); 153 arc_bridge_service()->net_instance()->ScanCompleted();
128 } 154 }
129 155
130 void ArcNetHostImpl::OnShuttingDown() { 156 void ArcNetHostImpl::OnShuttingDown() {
131 GetStateHandler()->RemoveObserver(this, FROM_HERE); 157 GetStateHandler()->RemoveObserver(this, FROM_HERE);
132 } 158 }
133 159
134 } // namespace arc 160 } // 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