Chromium Code Reviews| 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 <dbus/dbus-glib.h> | 7 #include <dbus/dbus-glib.h> |
| 8 #include <dbus/dbus-gtype-specialized.h> | 8 #include <dbus/dbus-gtype-specialized.h> |
| 9 #include <glib-object.h> | 9 #include <glib-object.h> |
| 10 | 10 |
| (...skipping 1726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1737 // virtual DisconnectFromNetwork implemented in derived classes. | 1737 // virtual DisconnectFromNetwork implemented in derived classes. |
| 1738 virtual void ForgetNetwork(const std::string& service_path) OVERRIDE; | 1738 virtual void ForgetNetwork(const std::string& service_path) OVERRIDE; |
| 1739 virtual void EnableEthernetNetworkDevice(bool enable) OVERRIDE; | 1739 virtual void EnableEthernetNetworkDevice(bool enable) OVERRIDE; |
| 1740 virtual void EnableWifiNetworkDevice(bool enable) OVERRIDE; | 1740 virtual void EnableWifiNetworkDevice(bool enable) OVERRIDE; |
| 1741 virtual void EnableCellularNetworkDevice(bool enable) OVERRIDE; | 1741 virtual void EnableCellularNetworkDevice(bool enable) OVERRIDE; |
| 1742 // virtual EnableOfflineMode implemented in derived classes. | 1742 // virtual EnableOfflineMode implemented in derived classes. |
| 1743 // virtual GetIPConfigs implemented in derived classes. | 1743 // virtual GetIPConfigs implemented in derived classes. |
| 1744 // virtual SetIPConfig implemented in derived classes. | 1744 // virtual SetIPConfig implemented in derived classes. |
| 1745 virtual void SwitchToPreferredNetwork() OVERRIDE; | 1745 virtual void SwitchToPreferredNetwork() OVERRIDE; |
| 1746 virtual bool LoadOncNetworks(const std::string& onc_blob, | 1746 virtual bool LoadOncNetworks(const std::string& onc_blob, |
| 1747 const std::string& passcode) OVERRIDE; | 1747 const std::string& passcode, |
| 1748 std::string* error) OVERRIDE; | |
| 1748 virtual bool SetActiveNetwork(ConnectionType type, | 1749 virtual bool SetActiveNetwork(ConnectionType type, |
| 1749 const std::string& service_path) OVERRIDE; | 1750 const std::string& service_path) OVERRIDE; |
| 1750 | 1751 |
| 1751 protected: | 1752 protected: |
| 1752 typedef ObserverList<NetworkObserver> NetworkObserverList; | 1753 typedef ObserverList<NetworkObserver> NetworkObserverList; |
| 1753 typedef std::map<std::string, NetworkObserverList*> NetworkObserverMap; | 1754 typedef std::map<std::string, NetworkObserverList*> NetworkObserverMap; |
| 1754 | 1755 |
| 1755 typedef ObserverList<NetworkDeviceObserver> NetworkDeviceObserverList; | 1756 typedef ObserverList<NetworkDeviceObserver> NetworkDeviceObserverList; |
| 1756 typedef std::map<std::string, NetworkDeviceObserverList*> | 1757 typedef std::map<std::string, NetworkDeviceObserverList*> |
| 1757 NetworkDeviceObserverMap; | 1758 NetworkDeviceObserverMap; |
| (...skipping 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2826 if (!wifi->preferred()) // All preferred networks are sorted in front. | 2827 if (!wifi->preferred()) // All preferred networks are sorted in front. |
| 2827 break; | 2828 break; |
| 2828 if (wifi->auto_connect()) { | 2829 if (wifi->auto_connect()) { |
| 2829 ConnectToWifiNetwork(wifi); | 2830 ConnectToWifiNetwork(wifi); |
| 2830 break; | 2831 break; |
| 2831 } | 2832 } |
| 2832 } | 2833 } |
| 2833 } | 2834 } |
| 2834 | 2835 |
| 2835 bool NetworkLibraryImplBase::LoadOncNetworks(const std::string& onc_blob, | 2836 bool NetworkLibraryImplBase::LoadOncNetworks(const std::string& onc_blob, |
| 2836 const std::string& passcode) { | 2837 const std::string& passcode, |
| 2838 std::string* error) { | |
| 2837 // TODO(gspencer): Add support for decrypting onc files. crbug.com/19397 | 2839 // TODO(gspencer): Add support for decrypting onc files. crbug.com/19397 |
| 2838 OncNetworkParser parser(onc_blob); | 2840 OncNetworkParser parser(onc_blob); |
| 2839 | 2841 |
| 2842 if (!parser.parse_error().empty()) { | |
| 2843 if (error) | |
| 2844 *error = parser.parse_error(); | |
| 2845 return false; | |
| 2846 } | |
| 2847 | |
| 2840 for (int i = 0; i < parser.GetCertificatesSize(); i++) { | 2848 for (int i = 0; i < parser.GetCertificatesSize(); i++) { |
| 2841 // Insert each of the available certs into the certificate DB. | 2849 // Insert each of the available certs into the certificate DB. |
| 2842 if (!parser.ParseCertificate(i)) { | 2850 if (!parser.ParseCertificate(i)) { |
| 2843 DLOG(WARNING) << "Cannot parse certificate in ONC file"; | 2851 DLOG(WARNING) << "Cannot parse certificate in ONC file"; |
| 2852 if (error) | |
| 2853 *error = parser.parse_error(); | |
| 2844 return false; | 2854 return false; |
| 2845 } | 2855 } |
| 2846 } | 2856 } |
| 2847 | 2857 |
| 2848 for (int i = 0; i < parser.GetNetworkConfigsSize(); i++) { | 2858 for (int i = 0; i < parser.GetNetworkConfigsSize(); i++) { |
| 2849 // Parse Open Network Configuration blob into a temporary Network object. | 2859 // Parse Open Network Configuration blob into a temporary Network object. |
| 2850 scoped_ptr<Network> network(parser.ParseNetwork(i)); | 2860 scoped_ptr<Network> network(parser.ParseNetwork(i)); |
| 2851 if (!network.get()) { | 2861 if (!network.get()) { |
| 2852 DLOG(WARNING) << "Cannot parse network in ONC file"; | 2862 DLOG(WARNING) << "Cannot parse network in ONC file"; |
| 2863 if (error) | |
| 2864 *error = parser.parse_error(); | |
| 2853 return false; | 2865 return false; |
| 2854 } | 2866 } |
| 2855 | 2867 |
| 2856 DictionaryValue dict; | 2868 DictionaryValue dict; |
| 2857 for (Network::PropertyMap::const_iterator props = | 2869 for (Network::PropertyMap::const_iterator props = |
| 2858 network->property_map_.begin(); | 2870 network->property_map_.begin(); |
| 2859 props != network->property_map_.end(); ++props) { | 2871 props != network->property_map_.end(); ++props) { |
| 2860 std::string key = | 2872 std::string key = |
| 2861 NativeNetworkParser::property_mapper()->GetKey(props->first); | 2873 NativeNetworkParser::property_mapper()->GetKey(props->first); |
| 2862 if (!key.empty()) | 2874 if (!key.empty()) |
| 2863 dict.SetWithoutPathExpansion(key, props->second->DeepCopy()); | 2875 dict.SetWithoutPathExpansion(key, props->second->DeepCopy()); |
| 2864 else | 2876 else |
| 2865 VLOG(2) << "Property " << props->first << " will not be sent"; | 2877 VLOG(2) << "Property " << props->first << " will not be sent"; |
| 2866 } | 2878 } |
| 2867 | 2879 |
| 2868 CallConfigureService(network->unique_id(), &dict); | 2880 CallConfigureService(network->unique_id(), &dict); |
| 2869 } | 2881 } |
| 2870 return parser.GetNetworkConfigsSize() != 0; | 2882 |
| 2883 if (parser.GetNetworkConfigsSize() == 0) { | |
|
kmixter1
2011/12/10 15:13:09
rebase...
Charlie Lee
2011/12/14 17:02:20
Done.
| |
| 2884 if (error) | |
| 2885 *error = l10n_util::GetStringUTF8( | |
| 2886 IDS_NETWORK_CONFIG_ERROR_NETWORK_IMPORT); | |
| 2887 return false; | |
| 2888 } | |
| 2889 return true; | |
| 2871 } | 2890 } |
| 2872 | 2891 |
| 2873 //////////////////////////////////////////////////////////////////////////// | 2892 //////////////////////////////////////////////////////////////////////////// |
| 2874 // Testing functions. | 2893 // Testing functions. |
| 2875 | 2894 |
| 2876 bool NetworkLibraryImplBase::SetActiveNetwork( | 2895 bool NetworkLibraryImplBase::SetActiveNetwork( |
| 2877 ConnectionType type, const std::string& service_path) { | 2896 ConnectionType type, const std::string& service_path) { |
| 2878 Network* network = NULL; | 2897 Network* network = NULL; |
| 2879 if (!service_path.empty()) | 2898 if (!service_path.empty()) |
| 2880 network = FindNetworkByPath(service_path); | 2899 network = FindNetworkByPath(service_path); |
| (...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3690 | 3709 |
| 3691 ///////////////////////////////////////////////////////////////////////////// | 3710 ///////////////////////////////////////////////////////////////////////////// |
| 3692 // NetworkLibraryImplBase connect implementation. | 3711 // NetworkLibraryImplBase connect implementation. |
| 3693 | 3712 |
| 3694 // static callback | 3713 // static callback |
| 3695 void NetworkLibraryImplCros::ConfigureServiceCallback( | 3714 void NetworkLibraryImplCros::ConfigureServiceCallback( |
| 3696 void* object, | 3715 void* object, |
| 3697 const char* service_path, | 3716 const char* service_path, |
| 3698 NetworkMethodErrorType error, | 3717 NetworkMethodErrorType error, |
| 3699 const char* error_message) { | 3718 const char* error_message) { |
| 3700 if (error != NETWORK_METHOD_ERROR_NONE) { | 3719 if (error != NETWORK_METHOD_ERROR_NONE) { |
|
kmixter1
2011/12/10 15:13:09
This is an important error that we really should b
Charlie Lee
2011/12/14 17:02:20
I agree. This will be for R18.
| |
| 3701 LOG(WARNING) << "Error from ConfigureService callback for: " | 3720 LOG(WARNING) << "Error from ConfigureService callback for: " |
| 3702 << service_path | 3721 << service_path |
| 3703 << " Error: " << error << " Message: " << error_message; | 3722 << " Error: " << error << " Message: " << error_message; |
| 3704 } | 3723 } |
| 3705 } | 3724 } |
| 3706 | 3725 |
| 3707 void NetworkLibraryImplCros::CallConfigureService(const std::string& identifier, | 3726 void NetworkLibraryImplCros::CallConfigureService(const std::string& identifier, |
| 3708 const DictionaryValue* info) { | 3727 const DictionaryValue* info) { |
| 3709 GHashTable* ghash = ConvertDictionaryValueToGValueMap(info); | 3728 GHashTable* ghash = ConvertDictionaryValueToGValueMap(info); |
| 3710 if (VLOG_IS_ON(2)) { | 3729 if (VLOG_IS_ON(2)) { |
| (...skipping 1382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5093 " \"GUID\": \"guid\"," | 5112 " \"GUID\": \"guid\"," |
| 5094 " \"Type\": \"WiFi\"," | 5113 " \"Type\": \"WiFi\"," |
| 5095 " \"WiFi\": {" | 5114 " \"WiFi\": {" |
| 5096 " \"Security\": \"WEP\"," | 5115 " \"Security\": \"WEP\"," |
| 5097 " \"SSID\": \"MySSID\"," | 5116 " \"SSID\": \"MySSID\"," |
| 5098 " }" | 5117 " }" |
| 5099 " }" | 5118 " }" |
| 5100 " ]," | 5119 " ]," |
| 5101 " \"Certificates\": []" | 5120 " \"Certificates\": []" |
| 5102 "}"); | 5121 "}"); |
| 5103 LoadOncNetworks(test_blob, ""); | 5122 LoadOncNetworks(test_blob, "", NULL); |
| 5104 } | 5123 } |
| 5105 | 5124 |
| 5106 //////////////////////////////////////////////////////////////////////////// | 5125 //////////////////////////////////////////////////////////////////////////// |
| 5107 // NetworkLibraryImplStub private methods. | 5126 // NetworkLibraryImplStub private methods. |
| 5108 | 5127 |
| 5109 void NetworkLibraryImplStub::AddStubNetwork( | 5128 void NetworkLibraryImplStub::AddStubNetwork( |
| 5110 Network* network, NetworkProfileType profile_type) { | 5129 Network* network, NetworkProfileType profile_type) { |
| 5111 network->priority_order_ = network_priority_order_++; | 5130 network->priority_order_ = network_priority_order_++; |
| 5112 network->CalculateUniqueId(); | 5131 network->CalculateUniqueId(); |
| 5113 if (!network->unique_id().empty()) | 5132 if (!network->unique_id().empty()) |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5341 return impl; | 5360 return impl; |
| 5342 } | 5361 } |
| 5343 | 5362 |
| 5344 ///////////////////////////////////////////////////////////////////////////// | 5363 ///////////////////////////////////////////////////////////////////////////// |
| 5345 | 5364 |
| 5346 } // namespace chromeos | 5365 } // namespace chromeos |
| 5347 | 5366 |
| 5348 // Allows InvokeLater without adding refcounting. This class is a Singleton and | 5367 // Allows InvokeLater without adding refcounting. This class is a Singleton and |
| 5349 // won't be deleted until its last InvokeLater is run. | 5368 // won't be deleted until its last InvokeLater is run. |
| 5350 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::NetworkLibraryImplBase); | 5369 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::NetworkLibraryImplBase); |
| OLD | NEW |