| 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 3323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3334 // Set active_virtual_ to the first connected or connecting vpn service. | 3334 // Set active_virtual_ to the first connected or connecting vpn service. |
| 3335 if (active_virtual_ == NULL && network->connecting_or_connected()) | 3335 if (active_virtual_ == NULL && network->connecting_or_connected()) |
| 3336 active_virtual_ = static_cast<VirtualNetwork*>(network); | 3336 active_virtual_ = static_cast<VirtualNetwork*>(network); |
| 3337 } | 3337 } |
| 3338 } | 3338 } |
| 3339 | 3339 |
| 3340 void AddNetwork(Network* network) { | 3340 void AddNetwork(Network* network) { |
| 3341 std::pair<NetworkMap::iterator,bool> result = | 3341 std::pair<NetworkMap::iterator,bool> result = |
| 3342 network_map_.insert(std::make_pair(network->service_path(), network)); | 3342 network_map_.insert(std::make_pair(network->service_path(), network)); |
| 3343 DCHECK(result.second); // Should only get called with new network. | 3343 DCHECK(result.second); // Should only get called with new network. |
| 3344 VLOG(2) << "Adding Network: " << network->name(); | 3344 VLOG(2) << "Adding Network: " << network->service_path() |
| 3345 << " (" << network->name() << ")"; |
| 3345 ConnectionType type(network->type()); | 3346 ConnectionType type(network->type()); |
| 3346 if (type == TYPE_WIFI) { | 3347 if (type == TYPE_WIFI) { |
| 3347 if (wifi_enabled()) | 3348 if (wifi_enabled()) |
| 3348 wifi_networks_.push_back(static_cast<WifiNetwork*>(network)); | 3349 wifi_networks_.push_back(static_cast<WifiNetwork*>(network)); |
| 3349 } else if (type == TYPE_CELLULAR) { | 3350 } else if (type == TYPE_CELLULAR) { |
| 3350 if (cellular_enabled()) | 3351 if (cellular_enabled()) |
| 3351 cellular_networks_.push_back(static_cast<CellularNetwork*>(network)); | 3352 cellular_networks_.push_back(static_cast<CellularNetwork*>(network)); |
| 3352 } else if (type == TYPE_VPN) { | 3353 } else if (type == TYPE_VPN) { |
| 3353 virtual_networks_.push_back(static_cast<VirtualNetwork*>(network)); | 3354 virtual_networks_.push_back(static_cast<VirtualNetwork*>(network)); |
| 3354 } | 3355 } |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3475 if (!service_path.empty()) { | 3476 if (!service_path.empty()) { |
| 3476 VLOG(1) << "Watched Service: " << service_path; | 3477 VLOG(1) << "Watched Service: " << service_path; |
| 3477 RequestNetworkServiceInfo( | 3478 RequestNetworkServiceInfo( |
| 3478 service_path.c_str(), &NetworkServiceUpdate, this); | 3479 service_path.c_str(), &NetworkServiceUpdate, this); |
| 3479 } | 3480 } |
| 3480 } | 3481 } |
| 3481 } | 3482 } |
| 3482 | 3483 |
| 3483 // Request the active profile which lists the remembered networks. | 3484 // Request the active profile which lists the remembered networks. |
| 3484 void RequestRememberedNetworksUpdate() { | 3485 void RequestRememberedNetworksUpdate() { |
| 3485 RequestNetworkProfile( | 3486 if (!active_profile_path_.empty()) { |
| 3486 active_profile_path_.c_str(), &ProfileUpdate, this); | 3487 RequestNetworkProfile( |
| 3488 active_profile_path_.c_str(), &ProfileUpdate, this); |
| 3489 } |
| 3487 } | 3490 } |
| 3488 | 3491 |
| 3489 // Update the list of remembered (profile) networks, and request associated | 3492 // Update the list of remembered (profile) networks, and request associated |
| 3490 // service updates. | 3493 // service updates. |
| 3491 void UpdateRememberedServiceList(const char* profile_path, | 3494 void UpdateRememberedServiceList(const char* profile_path, |
| 3492 const ListValue* profile_entries) { | 3495 const ListValue* profile_entries) { |
| 3493 // Copy the list of existing networks to "old" and clear the map and list. | 3496 // Copy the list of existing networks to "old" and clear the map and list. |
| 3494 NetworkMap old_network_map = remembered_network_map_; | 3497 NetworkMap old_network_map = remembered_network_map_; |
| 3495 ClearRememberedNetworks(false /*don't delete*/); | 3498 ClearRememberedNetworks(false /*don't delete*/); |
| 3496 // |profile_entries| represents a complete list of remembered networks. | 3499 // |profile_entries| represents a complete list of remembered networks. |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3659 NetworkDeviceMap old_device_map = device_map_; | 3662 NetworkDeviceMap old_device_map = device_map_; |
| 3660 device_map_.clear(); | 3663 device_map_.clear(); |
| 3661 VLOG(2) << "Updating Device List."; | 3664 VLOG(2) << "Updating Device List."; |
| 3662 for (ListValue::const_iterator iter = devices->begin(); | 3665 for (ListValue::const_iterator iter = devices->begin(); |
| 3663 iter != devices->end(); ++iter) { | 3666 iter != devices->end(); ++iter) { |
| 3664 std::string device_path; | 3667 std::string device_path; |
| 3665 (*iter)->GetAsString(&device_path); | 3668 (*iter)->GetAsString(&device_path); |
| 3666 if (!device_path.empty()) { | 3669 if (!device_path.empty()) { |
| 3667 NetworkDeviceMap::iterator found = old_device_map.find(device_path); | 3670 NetworkDeviceMap::iterator found = old_device_map.find(device_path); |
| 3668 if (found != old_device_map.end()) { | 3671 if (found != old_device_map.end()) { |
| 3669 VLOG(2) << " Adding device: " << device_path; | 3672 VLOG(2) << " Adding existing device: " << device_path; |
| 3670 device_map_[device_path] = found->second; | 3673 device_map_[device_path] = found->second; |
| 3671 old_device_map.erase(found); | 3674 old_device_map.erase(found); |
| 3672 // Add device property monitor before we request the | |
| 3673 // full property list, to ensure that we won't miss any | |
| 3674 // property changes. | |
| 3675 network_device_observers_[device_path] = | |
| 3676 new NetworkDeviceObserverList(this, device_path); | |
| 3677 | |
| 3678 } | 3675 } |
| 3679 RequestNetworkDeviceInfo( | 3676 RequestNetworkDeviceInfo( |
| 3680 device_path.c_str(), &NetworkDeviceUpdate, this); | 3677 device_path.c_str(), &NetworkDeviceUpdate, this); |
| 3681 } | 3678 } |
| 3682 } | 3679 } |
| 3683 // Delete any old devices that no longer exist. | 3680 // Delete any old devices that no longer exist. |
| 3684 for (NetworkDeviceMap::iterator iter = old_device_map.begin(); | 3681 for (NetworkDeviceMap::iterator iter = old_device_map.begin(); |
| 3685 iter != old_device_map.end(); ++iter) { | 3682 iter != old_device_map.end(); ++iter) { |
| 3686 DeleteDeviceFromDeviceObserversMap(iter->first); | 3683 DeleteDeviceFromDeviceObserversMap(iter->first); |
| 3687 // Delete device. | 3684 // Delete device. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 3716 void ParseNetworkDevice(const std::string& device_path, | 3713 void ParseNetworkDevice(const std::string& device_path, |
| 3717 const DictionaryValue* info) { | 3714 const DictionaryValue* info) { |
| 3718 NetworkDeviceMap::iterator found = device_map_.find(device_path); | 3715 NetworkDeviceMap::iterator found = device_map_.find(device_path); |
| 3719 NetworkDevice* device; | 3716 NetworkDevice* device; |
| 3720 if (found != device_map_.end()) { | 3717 if (found != device_map_.end()) { |
| 3721 device = found->second; | 3718 device = found->second; |
| 3722 } else { | 3719 } else { |
| 3723 device = new NetworkDevice(device_path); | 3720 device = new NetworkDevice(device_path); |
| 3724 VLOG(2) << " Adding device: " << device_path; | 3721 VLOG(2) << " Adding device: " << device_path; |
| 3725 device_map_[device_path] = device; | 3722 device_map_[device_path] = device; |
| 3723 if (network_device_observers_.find(device_path) == |
| 3724 network_device_observers_.end()) { |
| 3725 network_device_observers_[device_path] = |
| 3726 new NetworkDeviceObserverList(this, device_path); |
| 3727 } |
| 3726 } | 3728 } |
| 3727 device->ParseInfo(info); | 3729 device->ParseInfo(info); |
| 3728 VLOG(1) << "ParseNetworkDevice:" << device->name(); | 3730 VLOG(1) << "ParseNetworkDevice:" << device->name(); |
| 3729 NotifyNetworkManagerChanged(false); // Not forced. | 3731 NotifyNetworkManagerChanged(false); // Not forced. |
| 3730 } | 3732 } |
| 3731 | 3733 |
| 3732 //////////////////////////////////////////////////////////////////////////// | 3734 //////////////////////////////////////////////////////////////////////////// |
| 3733 | 3735 |
| 3734 void EnableNetworkDeviceType(ConnectionType device, bool enable) { | 3736 void EnableNetworkDeviceType(ConnectionType device, bool enable) { |
| 3735 if (!EnsureCrosLoaded()) | 3737 if (!EnsureCrosLoaded()) |
| (...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4443 return new NetworkLibraryStubImpl(); | 4445 return new NetworkLibraryStubImpl(); |
| 4444 else | 4446 else |
| 4445 return new NetworkLibraryImpl(); | 4447 return new NetworkLibraryImpl(); |
| 4446 } | 4448 } |
| 4447 | 4449 |
| 4448 } // namespace chromeos | 4450 } // namespace chromeos |
| 4449 | 4451 |
| 4450 // Allows InvokeLater without adding refcounting. This class is a Singleton and | 4452 // Allows InvokeLater without adding refcounting. This class is a Singleton and |
| 4451 // won't be deleted until it's last InvokeLater is run. | 4453 // won't be deleted until it's last InvokeLater is run. |
| 4452 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::NetworkLibraryImpl); | 4454 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::NetworkLibraryImpl); |
| OLD | NEW |