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

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

Issue 2817036: Push change for stevenjb:... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years, 5 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 } 256 }
257 257
258 void NetworkLibraryImpl::AddObserver(Observer* observer) { 258 void NetworkLibraryImpl::AddObserver(Observer* observer) {
259 observers_.AddObserver(observer); 259 observers_.AddObserver(observer);
260 } 260 }
261 261
262 void NetworkLibraryImpl::RemoveObserver(Observer* observer) { 262 void NetworkLibraryImpl::RemoveObserver(Observer* observer) {
263 observers_.RemoveObserver(observer); 263 observers_.RemoveObserver(observer);
264 } 264 }
265 265
266 ////////////////////////////////////////////////////////////////////////////////
267
268 bool NetworkLibraryImpl::FindWifiNetworkByPath(
269 const std::string& path, WifiNetwork* result) const {
270 const WifiNetwork* wifi =
271 GetWirelessNetworkByPath(wifi_networks_, path);
272 if (wifi) {
273 if (result)
274 *result = *wifi;
275 return true;
276 }
277 return false;
278 }
279
280 bool NetworkLibraryImpl::FindCellularNetworkByPath(
281 const std::string& path, CellularNetwork* result) const {
282 const CellularNetwork* cellular =
283 GetWirelessNetworkByPath(cellular_networks_, path);
284 if (cellular) {
285 if (result)
286 *result = *cellular;
287 return true;
288 }
289 return false;
290 }
291
266 void NetworkLibraryImpl::RequestWifiScan() { 292 void NetworkLibraryImpl::RequestWifiScan() {
267 if (CrosLibrary::Get()->EnsureLoaded()) { 293 if (CrosLibrary::Get()->EnsureLoaded()) {
268 RequestScan(TYPE_WIFI); 294 RequestScan(TYPE_WIFI);
269 } 295 }
270 } 296 }
271 297
272 bool NetworkLibraryImpl::ConnectToPreferredNetworkIfAvailable() { 298 bool NetworkLibraryImpl::ConnectToPreferredNetworkIfAvailable() {
273 // TODO(chocobo): Add the concept of preferred network to libcros. 299 // TODO(chocobo): Add the concept of preferred network to libcros.
274 // So that we don't have to hard-code Google-A here. 300 // So that we don't have to hard-code Google-A here.
275 if (CrosLibrary::Get()->EnsureLoaded()) { 301 if (CrosLibrary::Get()->EnsureLoaded()) {
(...skipping 17 matching lines...) Expand all
293 const std::string wifi_path = wifi->service_path(); 319 const std::string wifi_path = wifi->service_path();
294 320
295 // It takes some time for the enterprise daemon to start up and populate the 321 // It takes some time for the enterprise daemon to start up and populate the
296 // certificate and identity. So we wait at most 3 seconds here. And every 322 // certificate and identity. So we wait at most 3 seconds here. And every
297 // 100ms, we refetch the system info and check the cert and identify on the 323 // 100ms, we refetch the system info and check the cert and identify on the
298 // wifi. The enterprise daemon takes between 0.4 to 0.9 seconds to setup. 324 // wifi. The enterprise daemon takes between 0.4 to 0.9 seconds to setup.
299 bool setup = false; 325 bool setup = false;
300 for (int i = 0; i < 30; i++) { 326 for (int i = 0; i < 30; i++) {
301 // Update the system and refetch the network. 327 // Update the system and refetch the network.
302 UpdateSystemInfo(); 328 UpdateSystemInfo();
303 wifi = GetWifiNetworkByPath(wifi_path); 329 wifi = GetWirelessNetworkByPath(wifi_networks_, wifi_path);
304 // See if identity and certpath are available. 330 // See if identity and certpath are available.
305 if (wifi && !wifi->identity().empty() && !wifi->cert_path().empty()) { 331 if (wifi && !wifi->identity().empty() && !wifi->cert_path().empty()) {
306 LOG(INFO) << "Google wifi set up after " << (i*0.1) << " seconds."; 332 LOG(INFO) << "Google wifi set up after " << (i*0.1) << " seconds.";
307 setup = true; 333 setup = true;
308 break; 334 break;
309 } 335 }
310 PlatformThread::Sleep(100); 336 PlatformThread::Sleep(100);
311 } 337 }
312 338
313 if (!setup) { 339 if (!setup) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 405
380 void NetworkLibraryImpl::DisconnectFromWirelessNetwork( 406 void NetworkLibraryImpl::DisconnectFromWirelessNetwork(
381 const WirelessNetwork& network) { 407 const WirelessNetwork& network) {
382 if (CrosLibrary::Get()->EnsureLoaded()) { 408 if (CrosLibrary::Get()->EnsureLoaded()) {
383 DisconnectFromNetwork(network.service_path().c_str()); 409 DisconnectFromNetwork(network.service_path().c_str());
384 } 410 }
385 } 411 }
386 412
387 void NetworkLibraryImpl::SaveWifiNetwork(const WifiNetwork& network) { 413 void NetworkLibraryImpl::SaveWifiNetwork(const WifiNetwork& network) {
388 // Update the wifi network in the local cache. 414 // Update the wifi network in the local cache.
389 WifiNetwork* wifi = GetWifiNetworkByPath(network.service_path()); 415 WifiNetwork* wifi = GetWirelessNetworkByPath(wifi_networks_,
416 network.service_path());
390 if (wifi) 417 if (wifi)
391 *wifi = network; 418 *wifi = network;
392 419
393 // Update the wifi network with libcros. 420 // Update the wifi network with libcros.
394 if (CrosLibrary::Get()->EnsureLoaded()) { 421 if (CrosLibrary::Get()->EnsureLoaded()) {
395 SetPassphrase(network.service_path().c_str(), network.passphrase().c_str()); 422 SetPassphrase(network.service_path().c_str(), network.passphrase().c_str());
396 SetIdentity(network.service_path().c_str(), network.identity().c_str()); 423 SetIdentity(network.service_path().c_str(), network.identity().c_str());
397 SetCertPath(network.service_path().c_str(), network.cert_path().c_str()); 424 SetCertPath(network.service_path().c_str(), network.cert_path().c_str());
398 SetAutoConnect(network.service_path().c_str(), network.auto_connect()); 425 SetAutoConnect(network.service_path().c_str(), network.auto_connect());
399 } 426 }
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 639
613 WifiNetwork* NetworkLibraryImpl::GetWifiNetworkByName(const std::string& name) { 640 WifiNetwork* NetworkLibraryImpl::GetWifiNetworkByName(const std::string& name) {
614 for (size_t i = 0; i < wifi_networks_.size(); ++i) { 641 for (size_t i = 0; i < wifi_networks_.size(); ++i) {
615 if (wifi_networks_[i].name().compare(name) == 0) { 642 if (wifi_networks_[i].name().compare(name) == 0) {
616 return &wifi_networks_[i]; 643 return &wifi_networks_[i];
617 } 644 }
618 } 645 }
619 return NULL; 646 return NULL;
620 } 647 }
621 648
622 WifiNetwork* NetworkLibraryImpl::GetWifiNetworkByPath(const std::string& path) { 649 template<typename T> T* NetworkLibraryImpl::GetWirelessNetworkByPath(
623 for (size_t i = 0; i < wifi_networks_.size(); ++i) { 650 std::vector<T>& networks, const std::string& path) {
624 if (wifi_networks_[i].service_path().compare(path) == 0) { 651 typedef typename std::vector<T>::iterator iter_t;
625 return &wifi_networks_[i]; 652 iter_t iter = std::find_if(networks.begin(), networks.end(),
626 } 653 WirelessNetwork::ServicePathEq(path));
627 } 654 return (iter != networks.end()) ? &(*iter) : NULL;
628 return NULL; 655 }
656
657 // const version
658 template<typename T> const T* NetworkLibraryImpl::GetWirelessNetworkByPath(
659 const std::vector<T>& networks, const std::string& path) const {
660 typedef typename std::vector<T>::const_iterator iter_t;
661 iter_t iter = std::find_if(networks.begin(), networks.end(),
662 WirelessNetwork::ServicePathEq(path));
663 return (iter != networks.end()) ? &(*iter) : NULL;
629 } 664 }
630 665
631 void NetworkLibraryImpl::EnableNetworkDeviceType(ConnectionType device, 666 void NetworkLibraryImpl::EnableNetworkDeviceType(ConnectionType device,
632 bool enable) { 667 bool enable) {
633 if (!CrosLibrary::Get()->EnsureLoaded()) 668 if (!CrosLibrary::Get()->EnsureLoaded())
634 return; 669 return;
635 670
636 // If network device is already enabled/disabled, then don't do anything. 671 // If network device is already enabled/disabled, then don't do anything.
637 if (enable && (enabled_devices_ & (1 << device))) { 672 if (enable && (enabled_devices_ & (1 << device))) {
638 LOG(WARNING) << "Trying to enable a device that's already enabled: " 673 LOG(WARNING) << "Trying to enable a device that's already enabled: "
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 if (ethernet_connected()) 778 if (ethernet_connected())
744 return ethernet_.ip_address(); 779 return ethernet_.ip_address();
745 if (wifi_connected()) 780 if (wifi_connected())
746 return wifi_.ip_address(); 781 return wifi_.ip_address();
747 if (cellular_connected()) 782 if (cellular_connected())
748 return cellular_.ip_address(); 783 return cellular_.ip_address();
749 return ethernet_.ip_address(); 784 return ethernet_.ip_address();
750 } 785 }
751 786
752 } // namespace chromeos 787 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/cros/network_library.h ('k') | chrome/browser/chromeos/status/network_menu_button.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698