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

Side by Side Diff: chrome/browser/chromeos/cros/network_library.cc

Issue 661392: Refactor libcros calls for ChromeOS (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/chromeos/cros/network_library.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "chrome/browser/chromeos/cros/network_library.h" 5 #include "chrome/browser/chromeos/cros/network_library.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "chrome/browser/chrome_thread.h" 10 #include "chrome/browser/chrome_thread.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 } 80 }
81 81
82 void NetworkLibrary::AddObserver(Observer* observer) { 82 void NetworkLibrary::AddObserver(Observer* observer) {
83 observers_.AddObserver(observer); 83 observers_.AddObserver(observer);
84 } 84 }
85 85
86 void NetworkLibrary::RemoveObserver(Observer* observer) { 86 void NetworkLibrary::RemoveObserver(Observer* observer) {
87 observers_.RemoveObserver(observer); 87 observers_.RemoveObserver(observer);
88 } 88 }
89 89
90 static const char* GetEncryptionString(chromeos::EncryptionType encryption) {
91 switch (encryption) {
92 case chromeos::NONE:
93 return "none";
94 case chromeos::RSN:
95 return "rsn";
96 case chromeos::WEP:
97 return "wep";
98 case chromeos::WPA:
99 return "wpa";
100 }
101 return "none";
102 }
103
104 void NetworkLibrary::ConnectToWifiNetwork(WifiNetwork network, 90 void NetworkLibrary::ConnectToWifiNetwork(WifiNetwork network,
105 const string16& password) { 91 const string16& password) {
106 if (CrosLibrary::EnsureLoaded()) { 92 if (CrosLibrary::EnsureLoaded()) {
107 // This call kicks off a request to connect to this network, the results of 93 chromeos::ConnectToNetwork(network.service_path.c_str(),
108 // which we'll hear about through the monitoring we've set up in Init(); 94 password.empty() ? NULL : UTF16ToUTF8(password).c_str());
109 chromeos::ConnectToWifiNetwork(
110 network.ssid.c_str(),
111 password.empty() ? NULL : UTF16ToUTF8(password).c_str(),
112 GetEncryptionString(network.encryption));
113 } 95 }
114 } 96 }
115 97
116 void NetworkLibrary::ConnectToWifiNetwork(const string16& ssid, 98 void NetworkLibrary::ConnectToWifiNetwork(const string16& ssid,
117 const string16& password) { 99 const string16& password) {
118 if (CrosLibrary::EnsureLoaded()) { 100 if (CrosLibrary::EnsureLoaded()) {
119 // This call kicks off a request to connect to this network, the results of 101 // TODO(chocobo): Implement connect to hidden network.
120 // which we'll hear about through the monitoring we've set up in Init(); 102 // First create a service from hidden network.
121 chromeos::ConnectToWifiNetwork( 103 // Now connect to that service..
122 UTF16ToUTF8(ssid).c_str(), 104 // chromeos::ConnectToNetwork(service_path,
123 password.empty() ? NULL : UTF16ToUTF8(password).c_str(), 105 // password.empty() ? NULL : UTF16ToUTF8(password).c_str());
124 "rsn");
125 // TODO(chocobo): Make it support other encryptions.
126 } 106 }
127 } 107 }
128 108
129 void NetworkLibrary::ConnectToCellularNetwork(CellularNetwork network) { 109 void NetworkLibrary::ConnectToCellularNetwork(CellularNetwork network) {
130 if (CrosLibrary::EnsureLoaded()) { 110 if (CrosLibrary::EnsureLoaded()) {
131 // This call kicks off a request to connect to this network, the results of 111 chromeos::ConnectToNetwork(network.service_path.c_str(), NULL);
132 // which we'll hear about through the monitoring we've set up in Init();
133 chromeos::ConnectToWifiNetwork(network.name.c_str(), NULL, NULL);
134 } 112 }
135 } 113 }
136 114
137 void NetworkLibrary::EnableEthernetNetworkDevice(bool enable) { 115 void NetworkLibrary::EnableEthernetNetworkDevice(bool enable) {
138 EnableNetworkDevice(chromeos::TYPE_ETHERNET, enable); 116 EnableNetworkDevice(chromeos::TYPE_ETHERNET, enable);
139 } 117 }
140 118
141 void NetworkLibrary::EnableWifiNetworkDevice(bool enable) { 119 void NetworkLibrary::EnableWifiNetworkDevice(bool enable) {
142 EnableNetworkDevice(chromeos::TYPE_WIFI, enable); 120 EnableNetworkDevice(chromeos::TYPE_WIFI, enable);
143 } 121 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 178
201 // static 179 // static
202 void NetworkLibrary::ParseNetworks( 180 void NetworkLibrary::ParseNetworks(
203 const chromeos::ServiceStatus& service_status, EthernetNetwork* ethernet, 181 const chromeos::ServiceStatus& service_status, EthernetNetwork* ethernet,
204 WifiNetworkVector* wifi_networks, 182 WifiNetworkVector* wifi_networks,
205 CellularNetworkVector* cellular_networks) { 183 CellularNetworkVector* cellular_networks) {
206 DLOG(INFO) << "ParseNetworks:"; 184 DLOG(INFO) << "ParseNetworks:";
207 for (int i = 0; i < service_status.size; i++) { 185 for (int i = 0; i < service_status.size; i++) {
208 const chromeos::ServiceInfo& service = service_status.services[i]; 186 const chromeos::ServiceInfo& service = service_status.services[i];
209 DLOG(INFO) << " (" << service.type << 187 DLOG(INFO) << " (" << service.type <<
210 ") " << service.ssid << 188 ") " << service.name <<
211 " sta=" << service.state << 189 " mode=" << service.mode <<
212 " pas=" << service.needs_passphrase << 190 " state=" << service.state <<
213 " enc=" << service.encryption << 191 " sec=" << service.security <<
214 " sig=" << service.signal_strength; 192 " req=" << service.passphrase_required <<
193 " pass=" << service.passphrase <<
194 " str=" << service.strength <<
195 " fav=" << service.favorite <<
196 " auto=" << service.auto_connect <<
197 " error=" << service.error;
215 bool connecting = service.state == chromeos::STATE_ASSOCIATION || 198 bool connecting = service.state == chromeos::STATE_ASSOCIATION ||
216 service.state == chromeos::STATE_CONFIGURATION || 199 service.state == chromeos::STATE_CONFIGURATION ||
217 service.state == chromeos::STATE_CARRIER; 200 service.state == chromeos::STATE_CARRIER;
218 bool connected = service.state == chromeos::STATE_READY; 201 bool connected = service.state == chromeos::STATE_READY;
219 // if connected, get ip config 202 // if connected, get ip config
220 std::string ip_address; 203 std::string ip_address;
221 if (connected && service.device_path) { 204 if (connected && service.device_path) {
222 chromeos::IPConfigStatus* ipconfig_status = 205 chromeos::IPConfigStatus* ipconfig_status =
223 chromeos::ListIPConfigs(service.device_path); 206 chromeos::ListIPConfigs(service.device_path);
224 if (ipconfig_status) { 207 if (ipconfig_status) {
(...skipping 15 matching lines...) Expand all
240 chromeos::FreeIPConfigStatus(ipconfig_status); 223 chromeos::FreeIPConfigStatus(ipconfig_status);
241 } 224 }
242 } 225 }
243 if (service.type == chromeos::TYPE_ETHERNET) { 226 if (service.type == chromeos::TYPE_ETHERNET) {
244 ethernet->connecting = connecting; 227 ethernet->connecting = connecting;
245 ethernet->connected = connected; 228 ethernet->connected = connected;
246 ethernet->device_path = service.device_path ? service.device_path : 229 ethernet->device_path = service.device_path ? service.device_path :
247 std::string(); 230 std::string();
248 ethernet->ip_address = ip_address; 231 ethernet->ip_address = ip_address;
249 } else if (service.type == chromeos::TYPE_WIFI) { 232 } else if (service.type == chromeos::TYPE_WIFI) {
250 wifi_networks->push_back(WifiNetwork(service.device_path ? 233 wifi_networks->push_back(WifiNetwork(service,
251 service.device_path :
252 std::string(),
253 service.ssid,
254 service.needs_passphrase,
255 service.encryption,
256 service.signal_strength,
257 connecting, 234 connecting,
258 connected, 235 connected,
259 ip_address)); 236 ip_address));
260 } else if (service.type == chromeos::TYPE_CELLULAR) { 237 } else if (service.type == chromeos::TYPE_CELLULAR) {
261 cellular_networks->push_back(CellularNetwork(service.device_path ? 238 cellular_networks->push_back(CellularNetwork(service,
262 service.device_path :
263 std::string(),
264 service.ssid,
265 service.signal_strength,
266 connecting, 239 connecting,
267 connected, 240 connected,
268 ip_address)); 241 ip_address));
269 } 242 }
270 } 243 }
271 } 244 }
272 245
273 void NetworkLibrary::Init() { 246 void NetworkLibrary::Init() {
274 // First, get the currently available networks. This data is cached 247 // First, get the currently available networks. This data is cached
275 // on the connman side, so the call should be quick. 248 // on the connman side, so the call should be quick.
(...skipping 21 matching lines...) Expand all
297 network_devices_ = 0; 270 network_devices_ = 0;
298 } 271 }
299 } 272 }
300 273
301 void NetworkLibrary::EnableNetworkDevice(chromeos::ConnectionType device, 274 void NetworkLibrary::EnableNetworkDevice(chromeos::ConnectionType device,
302 bool enable) { 275 bool enable) {
303 if (!CrosLibrary::EnsureLoaded()) 276 if (!CrosLibrary::EnsureLoaded())
304 return; 277 return;
305 278
306 // If network device is already enabled/disabled, then don't do anything. 279 // If network device is already enabled/disabled, then don't do anything.
307 if (enable && (network_devices_ & device)) { 280 if (enable && (network_devices_ & (1 << device))) {
308 LOG(INFO) << "Trying to enable a network device that's already enabled: " 281 LOG(WARNING) << "Trying to enable a device that's already enabled: "
309 << device; 282 << device;
310 return; 283 return;
311 } 284 }
312 if (!enable && !(network_devices_ & device)) { 285 if (!enable && !(network_devices_ & (1 << device))) {
313 LOG(INFO) << "Trying to disable a network device that's already disabled: " 286 LOG(WARNING) << "Trying to disable a device that's already disabled: "
314 << device; 287 << device;
315 return; 288 return;
316 } 289 }
317 290
318 if (chromeos::EnableNetworkDevice(device, enable)) { 291 if (chromeos::EnableNetworkDevice(device, enable)) {
319 if (enable) 292 if (enable)
320 network_devices_ |= device; 293 network_devices_ |= (1 << device);
321 else 294 else
322 network_devices_ &= ~device; 295 network_devices_ &= ~(1 << device);
323 } 296 }
324 } 297 }
325 298
326 void NetworkLibrary::UpdateNetworkStatus(const EthernetNetwork& ethernet, 299 void NetworkLibrary::UpdateNetworkStatus(const EthernetNetwork& ethernet,
327 const WifiNetworkVector& wifi_networks, 300 const WifiNetworkVector& wifi_networks,
328 const CellularNetworkVector& cellular_networks) { 301 const CellularNetworkVector& cellular_networks) {
329 // Make sure we run on UI thread. 302 // Make sure we run on UI thread.
330 if (!ChromeThread::CurrentlyOn(ChromeThread::UI)) { 303 if (!ChromeThread::CurrentlyOn(ChromeThread::UI)) {
331 ChromeThread::PostTask( 304 ChromeThread::PostTask(
332 ChromeThread::UI, FROM_HERE, 305 ChromeThread::UI, FROM_HERE,
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 if (ethernet_connected()) 387 if (ethernet_connected())
415 return ethernet_.ip_address; 388 return ethernet_.ip_address;
416 if (wifi_connected()) 389 if (wifi_connected())
417 return wifi_.ip_address; 390 return wifi_.ip_address;
418 if (cellular_connected()) 391 if (cellular_connected())
419 return cellular_.ip_address; 392 return cellular_.ip_address;
420 return ethernet_.ip_address; 393 return ethernet_.ip_address;
421 } 394 }
422 395
423 } // namespace chromeos 396 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/cros/network_library.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698