| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/i18n/time_formatting.h" | 10 #include "base/i18n/time_formatting.h" |
| (...skipping 3272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3283 // Set active_virtual_ to the first connected or connecting vpn service. | 3283 // Set active_virtual_ to the first connected or connecting vpn service. |
| 3284 if (active_virtual_ == NULL && network->connecting_or_connected()) | 3284 if (active_virtual_ == NULL && network->connecting_or_connected()) |
| 3285 active_virtual_ = static_cast<VirtualNetwork*>(network); | 3285 active_virtual_ = static_cast<VirtualNetwork*>(network); |
| 3286 } | 3286 } |
| 3287 } | 3287 } |
| 3288 | 3288 |
| 3289 void AddNetwork(Network* network) { | 3289 void AddNetwork(Network* network) { |
| 3290 std::pair<NetworkMap::iterator,bool> result = | 3290 std::pair<NetworkMap::iterator,bool> result = |
| 3291 network_map_.insert(std::make_pair(network->service_path(), network)); | 3291 network_map_.insert(std::make_pair(network->service_path(), network)); |
| 3292 DCHECK(result.second); // Should only get called with new network. | 3292 DCHECK(result.second); // Should only get called with new network. |
| 3293 VLOG(2) << "Adding Network: " << network->service_path() |
| 3294 << " (" << network->name() << ")"; |
| 3293 ConnectionType type(network->type()); | 3295 ConnectionType type(network->type()); |
| 3294 if (type == TYPE_WIFI) { | 3296 if (type == TYPE_WIFI) { |
| 3295 if (wifi_enabled()) | 3297 if (wifi_enabled()) |
| 3296 wifi_networks_.push_back(static_cast<WifiNetwork*>(network)); | 3298 wifi_networks_.push_back(static_cast<WifiNetwork*>(network)); |
| 3297 } else if (type == TYPE_CELLULAR) { | 3299 } else if (type == TYPE_CELLULAR) { |
| 3298 if (cellular_enabled()) | 3300 if (cellular_enabled()) |
| 3299 cellular_networks_.push_back(static_cast<CellularNetwork*>(network)); | 3301 cellular_networks_.push_back(static_cast<CellularNetwork*>(network)); |
| 3300 } else if (type == TYPE_VPN) { | 3302 } else if (type == TYPE_VPN) { |
| 3301 virtual_networks_.push_back(static_cast<VirtualNetwork*>(network)); | 3303 virtual_networks_.push_back(static_cast<VirtualNetwork*>(network)); |
| 3302 } | 3304 } |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3454 if (!service_path.empty()) { | 3456 if (!service_path.empty()) { |
| 3455 VLOG(1) << "Watched Service: " << service_path; | 3457 VLOG(1) << "Watched Service: " << service_path; |
| 3456 RequestNetworkServiceInfo( | 3458 RequestNetworkServiceInfo( |
| 3457 service_path.c_str(), &NetworkServiceUpdate, this); | 3459 service_path.c_str(), &NetworkServiceUpdate, this); |
| 3458 } | 3460 } |
| 3459 } | 3461 } |
| 3460 } | 3462 } |
| 3461 | 3463 |
| 3462 // Request the active profile which lists the remembered networks. | 3464 // Request the active profile which lists the remembered networks. |
| 3463 void RequestRememberedNetworksUpdate() { | 3465 void RequestRememberedNetworksUpdate() { |
| 3464 RequestNetworkProfile( | 3466 if (!active_profile_path_.empty()) { |
| 3465 active_profile_path_.c_str(), &ProfileUpdate, this); | 3467 RequestNetworkProfile( |
| 3468 active_profile_path_.c_str(), &ProfileUpdate, this); |
| 3469 } |
| 3466 } | 3470 } |
| 3467 | 3471 |
| 3468 // Update the list of remembered (profile) networks, and request associated | 3472 // Update the list of remembered (profile) networks, and request associated |
| 3469 // service updates. | 3473 // service updates. |
| 3470 void UpdateRememberedServiceList(const char* profile_path, | 3474 void UpdateRememberedServiceList(const char* profile_path, |
| 3471 const ListValue* profile_entries) { | 3475 const ListValue* profile_entries) { |
| 3472 // Copy the list of existing networks to "old" and clear the map and list. | 3476 // Copy the list of existing networks to "old" and clear the map and list. |
| 3473 NetworkMap old_network_map = remembered_network_map_; | 3477 NetworkMap old_network_map = remembered_network_map_; |
| 3474 ClearRememberedNetworks(false /*don't delete*/); | 3478 ClearRememberedNetworks(false /*don't delete*/); |
| 3475 // |profile_entries| represents a complete list of remembered networks. | 3479 // |profile_entries| represents a complete list of remembered networks. |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3636 NetworkDeviceMap old_device_map = device_map_; | 3640 NetworkDeviceMap old_device_map = device_map_; |
| 3637 device_map_.clear(); | 3641 device_map_.clear(); |
| 3638 VLOG(2) << "Updating Device List."; | 3642 VLOG(2) << "Updating Device List."; |
| 3639 for (ListValue::const_iterator iter = devices->begin(); | 3643 for (ListValue::const_iterator iter = devices->begin(); |
| 3640 iter != devices->end(); ++iter) { | 3644 iter != devices->end(); ++iter) { |
| 3641 std::string device_path; | 3645 std::string device_path; |
| 3642 (*iter)->GetAsString(&device_path); | 3646 (*iter)->GetAsString(&device_path); |
| 3643 if (!device_path.empty()) { | 3647 if (!device_path.empty()) { |
| 3644 NetworkDeviceMap::iterator found = old_device_map.find(device_path); | 3648 NetworkDeviceMap::iterator found = old_device_map.find(device_path); |
| 3645 if (found != old_device_map.end()) { | 3649 if (found != old_device_map.end()) { |
| 3646 VLOG(2) << " Adding device: " << device_path; | 3650 VLOG(2) << " Adding existing device: " << device_path; |
| 3647 device_map_[device_path] = found->second; | 3651 device_map_[device_path] = found->second; |
| 3648 old_device_map.erase(found); | 3652 old_device_map.erase(found); |
| 3649 // Add device property monitor before we request the | |
| 3650 // full property list, to ensure that we won't miss any | |
| 3651 // property changes. | |
| 3652 network_device_observers_[device_path] = | |
| 3653 new NetworkDeviceObserverList(this, device_path); | |
| 3654 | |
| 3655 } | 3653 } |
| 3656 RequestNetworkDeviceInfo( | 3654 RequestNetworkDeviceInfo( |
| 3657 device_path.c_str(), &NetworkDeviceUpdate, this); | 3655 device_path.c_str(), &NetworkDeviceUpdate, this); |
| 3658 } | 3656 } |
| 3659 } | 3657 } |
| 3660 // Delete any old devices that no longer exist. | 3658 // Delete any old devices that no longer exist. |
| 3661 for (NetworkDeviceMap::iterator iter = old_device_map.begin(); | 3659 for (NetworkDeviceMap::iterator iter = old_device_map.begin(); |
| 3662 iter != old_device_map.end(); ++iter) { | 3660 iter != old_device_map.end(); ++iter) { |
| 3663 DeleteDeviceFromDeviceObserversMap(iter->first); | 3661 DeleteDeviceFromDeviceObserversMap(iter->first); |
| 3664 // Delete device. | 3662 // Delete device. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 3693 void ParseNetworkDevice(const std::string& device_path, | 3691 void ParseNetworkDevice(const std::string& device_path, |
| 3694 const DictionaryValue* info) { | 3692 const DictionaryValue* info) { |
| 3695 NetworkDeviceMap::iterator found = device_map_.find(device_path); | 3693 NetworkDeviceMap::iterator found = device_map_.find(device_path); |
| 3696 NetworkDevice* device; | 3694 NetworkDevice* device; |
| 3697 if (found != device_map_.end()) { | 3695 if (found != device_map_.end()) { |
| 3698 device = found->second; | 3696 device = found->second; |
| 3699 } else { | 3697 } else { |
| 3700 device = new NetworkDevice(device_path); | 3698 device = new NetworkDevice(device_path); |
| 3701 VLOG(2) << " Adding device: " << device_path; | 3699 VLOG(2) << " Adding device: " << device_path; |
| 3702 device_map_[device_path] = device; | 3700 device_map_[device_path] = device; |
| 3701 if (network_device_observers_.find(device_path) == |
| 3702 network_device_observers_.end()) { |
| 3703 network_device_observers_[device_path] = |
| 3704 new NetworkDeviceObserverList(this, device_path); |
| 3705 } |
| 3703 } | 3706 } |
| 3704 device->ParseInfo(info); | 3707 device->ParseInfo(info); |
| 3705 VLOG(1) << "ParseNetworkDevice:" << device->name(); | 3708 VLOG(1) << "ParseNetworkDevice:" << device->name(); |
| 3706 NotifyNetworkManagerChanged(false); // Not forced. | 3709 NotifyNetworkManagerChanged(false); // Not forced. |
| 3707 } | 3710 } |
| 3708 | 3711 |
| 3709 //////////////////////////////////////////////////////////////////////////// | 3712 //////////////////////////////////////////////////////////////////////////// |
| 3710 | 3713 |
| 3711 void EnableNetworkDeviceType(ConnectionType device, bool enable) { | 3714 void EnableNetworkDeviceType(ConnectionType device, bool enable) { |
| 3712 if (!EnsureCrosLoaded()) | 3715 if (!EnsureCrosLoaded()) |
| (...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4398 return new NetworkLibraryStubImpl(); | 4401 return new NetworkLibraryStubImpl(); |
| 4399 else | 4402 else |
| 4400 return new NetworkLibraryImpl(); | 4403 return new NetworkLibraryImpl(); |
| 4401 } | 4404 } |
| 4402 | 4405 |
| 4403 } // namespace chromeos | 4406 } // namespace chromeos |
| 4404 | 4407 |
| 4405 // Allows InvokeLater without adding refcounting. This class is a Singleton and | 4408 // Allows InvokeLater without adding refcounting. This class is a Singleton and |
| 4406 // won't be deleted until it's last InvokeLater is run. | 4409 // won't be deleted until it's last InvokeLater is run. |
| 4407 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::NetworkLibraryImpl); | 4410 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::NetworkLibraryImpl); |
| OLD | NEW |