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 1727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1738 // virtual DisconnectFromNetwork implemented in derived classes. | 1738 // virtual DisconnectFromNetwork implemented in derived classes. |
1739 virtual void ForgetNetwork(const std::string& service_path) OVERRIDE; | 1739 virtual void ForgetNetwork(const std::string& service_path) OVERRIDE; |
1740 virtual void EnableEthernetNetworkDevice(bool enable) OVERRIDE; | 1740 virtual void EnableEthernetNetworkDevice(bool enable) OVERRIDE; |
1741 virtual void EnableWifiNetworkDevice(bool enable) OVERRIDE; | 1741 virtual void EnableWifiNetworkDevice(bool enable) OVERRIDE; |
1742 virtual void EnableCellularNetworkDevice(bool enable) OVERRIDE; | 1742 virtual void EnableCellularNetworkDevice(bool enable) OVERRIDE; |
1743 // virtual EnableOfflineMode implemented in derived classes. | 1743 // virtual EnableOfflineMode implemented in derived classes. |
1744 // virtual GetIPConfigs implemented in derived classes. | 1744 // virtual GetIPConfigs implemented in derived classes. |
1745 // virtual SetIPConfig implemented in derived classes. | 1745 // virtual SetIPConfig implemented in derived classes. |
1746 virtual void SwitchToPreferredNetwork() OVERRIDE; | 1746 virtual void SwitchToPreferredNetwork() OVERRIDE; |
1747 virtual bool LoadOncNetworks(const std::string& onc_blob, | 1747 virtual bool LoadOncNetworks(const std::string& onc_blob, |
1748 const std::string& passcode) OVERRIDE; | 1748 const std::string& passcode, |
1749 std::string* error) OVERRIDE; | |
1749 virtual bool SetActiveNetwork(ConnectionType type, | 1750 virtual bool SetActiveNetwork(ConnectionType type, |
1750 const std::string& service_path) OVERRIDE; | 1751 const std::string& service_path) OVERRIDE; |
1751 | 1752 |
1752 protected: | 1753 protected: |
1753 typedef ObserverList<NetworkObserver> NetworkObserverList; | 1754 typedef ObserverList<NetworkObserver> NetworkObserverList; |
1754 typedef std::map<std::string, NetworkObserverList*> NetworkObserverMap; | 1755 typedef std::map<std::string, NetworkObserverList*> NetworkObserverMap; |
1755 | 1756 |
1756 typedef ObserverList<NetworkDeviceObserver> NetworkDeviceObserverList; | 1757 typedef ObserverList<NetworkDeviceObserver> NetworkDeviceObserverList; |
1757 typedef std::map<std::string, NetworkDeviceObserverList*> | 1758 typedef std::map<std::string, NetworkDeviceObserverList*> |
1758 NetworkDeviceObserverMap; | 1759 NetworkDeviceObserverMap; |
(...skipping 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2827 if (!wifi->preferred()) // All preferred networks are sorted in front. | 2828 if (!wifi->preferred()) // All preferred networks are sorted in front. |
2828 break; | 2829 break; |
2829 if (wifi->auto_connect()) { | 2830 if (wifi->auto_connect()) { |
2830 ConnectToWifiNetwork(wifi); | 2831 ConnectToWifiNetwork(wifi); |
2831 break; | 2832 break; |
2832 } | 2833 } |
2833 } | 2834 } |
2834 } | 2835 } |
2835 | 2836 |
2836 bool NetworkLibraryImplBase::LoadOncNetworks(const std::string& onc_blob, | 2837 bool NetworkLibraryImplBase::LoadOncNetworks(const std::string& onc_blob, |
2837 const std::string& passcode) { | 2838 const std::string& passcode, |
2839 std::string* error) { | |
2838 // TODO(gspencer): Add support for decrypting onc files. crbug.com/19397 | 2840 // TODO(gspencer): Add support for decrypting onc files. crbug.com/19397 |
2839 OncNetworkParser parser(onc_blob); | 2841 OncNetworkParser parser(onc_blob); |
2840 | 2842 |
2843 if (!parser.parse_error().empty()) { | |
2844 if (error) | |
2845 *error = parser.parse_error(); | |
2846 return false; | |
2847 } | |
2848 | |
2841 for (int i = 0; i < parser.GetCertificatesSize(); i++) { | 2849 for (int i = 0; i < parser.GetCertificatesSize(); i++) { |
2842 // Insert each of the available certs into the certificate DB. | 2850 // Insert each of the available certs into the certificate DB. |
2843 if (parser.ParseCertificate(i).get() == NULL) { | 2851 if (parser.ParseCertificate(i).get() == NULL) { |
2844 DLOG(WARNING) << "Cannot parse certificate in ONC file"; | 2852 DLOG(WARNING) << "Cannot parse certificate in ONC file"; |
2853 if (error) | |
kmixter1
2011/12/14 19:46:38
There are cases where false is returned but error
kmixter1
2011/12/14 19:48:36
Sorry, misread the code. I think error is always
| |
2854 *error = parser.parse_error(); | |
2845 return false; | 2855 return false; |
2846 } | 2856 } |
2847 } | 2857 } |
2848 | 2858 |
2849 for (int i = 0; i < parser.GetNetworkConfigsSize(); i++) { | 2859 for (int i = 0; i < parser.GetNetworkConfigsSize(); i++) { |
2850 // Parse Open Network Configuration blob into a temporary Network object. | 2860 // Parse Open Network Configuration blob into a temporary Network object. |
2851 scoped_ptr<Network> network(parser.ParseNetwork(i)); | 2861 scoped_ptr<Network> network(parser.ParseNetwork(i)); |
2852 if (!network.get()) { | 2862 if (!network.get()) { |
2853 DLOG(WARNING) << "Cannot parse network in ONC file"; | 2863 DLOG(WARNING) << "Cannot parse network in ONC file"; |
2864 if (error) | |
2865 *error = parser.parse_error(); | |
2854 return false; | 2866 return false; |
2855 } | 2867 } |
2856 | 2868 |
2857 DictionaryValue dict; | 2869 DictionaryValue dict; |
2858 for (Network::PropertyMap::const_iterator props = | 2870 for (Network::PropertyMap::const_iterator props = |
2859 network->property_map_.begin(); | 2871 network->property_map_.begin(); |
2860 props != network->property_map_.end(); ++props) { | 2872 props != network->property_map_.end(); ++props) { |
2861 std::string key = | 2873 std::string key = |
2862 NativeNetworkParser::property_mapper()->GetKey(props->first); | 2874 NativeNetworkParser::property_mapper()->GetKey(props->first); |
2863 if (!key.empty()) | 2875 if (!key.empty()) |
2864 dict.SetWithoutPathExpansion(key, props->second->DeepCopy()); | 2876 dict.SetWithoutPathExpansion(key, props->second->DeepCopy()); |
2865 else | 2877 else |
2866 VLOG(2) << "Property " << props->first << " will not be sent"; | 2878 VLOG(2) << "Property " << props->first << " will not be sent"; |
2867 } | 2879 } |
2868 | 2880 |
2869 CallConfigureService(network->unique_id(), &dict); | 2881 CallConfigureService(network->unique_id(), &dict); |
2870 } | 2882 } |
2871 return (parser.GetNetworkConfigsSize() != 0 || | 2883 |
2872 parser.GetCertificatesSize() != 0); | 2884 if (parser.GetNetworkConfigsSize() != 0 || |
2885 parser.GetCertificatesSize() != 0) { | |
2886 if (error) | |
2887 *error = l10n_util::GetStringUTF8( | |
2888 IDS_NETWORK_CONFIG_ERROR_NETWORK_IMPORT); | |
2889 return false; | |
2890 } | |
2891 return true; | |
2873 } | 2892 } |
2874 | 2893 |
2875 //////////////////////////////////////////////////////////////////////////// | 2894 //////////////////////////////////////////////////////////////////////////// |
2876 // Testing functions. | 2895 // Testing functions. |
2877 | 2896 |
2878 bool NetworkLibraryImplBase::SetActiveNetwork( | 2897 bool NetworkLibraryImplBase::SetActiveNetwork( |
2879 ConnectionType type, const std::string& service_path) { | 2898 ConnectionType type, const std::string& service_path) { |
2880 Network* network = NULL; | 2899 Network* network = NULL; |
2881 if (!service_path.empty()) | 2900 if (!service_path.empty()) |
2882 network = FindNetworkByPath(service_path); | 2901 network = FindNetworkByPath(service_path); |
(...skipping 2212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5095 " \"GUID\": \"guid\"," | 5114 " \"GUID\": \"guid\"," |
5096 " \"Type\": \"WiFi\"," | 5115 " \"Type\": \"WiFi\"," |
5097 " \"WiFi\": {" | 5116 " \"WiFi\": {" |
5098 " \"Security\": \"WEP\"," | 5117 " \"Security\": \"WEP\"," |
5099 " \"SSID\": \"MySSID\"," | 5118 " \"SSID\": \"MySSID\"," |
5100 " }" | 5119 " }" |
5101 " }" | 5120 " }" |
5102 " ]," | 5121 " ]," |
5103 " \"Certificates\": []" | 5122 " \"Certificates\": []" |
5104 "}"); | 5123 "}"); |
5105 LoadOncNetworks(test_blob, ""); | 5124 LoadOncNetworks(test_blob, "", NULL); |
5106 } | 5125 } |
5107 | 5126 |
5108 //////////////////////////////////////////////////////////////////////////// | 5127 //////////////////////////////////////////////////////////////////////////// |
5109 // NetworkLibraryImplStub private methods. | 5128 // NetworkLibraryImplStub private methods. |
5110 | 5129 |
5111 void NetworkLibraryImplStub::AddStubNetwork( | 5130 void NetworkLibraryImplStub::AddStubNetwork( |
5112 Network* network, NetworkProfileType profile_type) { | 5131 Network* network, NetworkProfileType profile_type) { |
5113 network->priority_order_ = network_priority_order_++; | 5132 network->priority_order_ = network_priority_order_++; |
5114 network->CalculateUniqueId(); | 5133 network->CalculateUniqueId(); |
5115 if (!network->unique_id().empty()) | 5134 if (!network->unique_id().empty()) |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5343 return impl; | 5362 return impl; |
5344 } | 5363 } |
5345 | 5364 |
5346 ///////////////////////////////////////////////////////////////////////////// | 5365 ///////////////////////////////////////////////////////////////////////////// |
5347 | 5366 |
5348 } // namespace chromeos | 5367 } // namespace chromeos |
5349 | 5368 |
5350 // Allows InvokeLater without adding refcounting. This class is a Singleton and | 5369 // Allows InvokeLater without adding refcounting. This class is a Singleton and |
5351 // won't be deleted until its last InvokeLater is run. | 5370 // won't be deleted until its last InvokeLater is run. |
5352 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::NetworkLibraryImplBase); | 5371 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::NetworkLibraryImplBase); |
OLD | NEW |