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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 bool is_unicode_char = base::ReadUnicodeCharacter(str.c_str(), str.size(), | 155 bool is_unicode_char = base::ReadUnicodeCharacter(str.c_str(), str.size(), |
156 &index, &code_point_out); | 156 &index, &code_point_out); |
157 if (is_unicode_char && (code_point_out >= 0x20)) | 157 if (is_unicode_char && (code_point_out >= 0x20)) |
158 base::WriteUnicodeCharacter(code_point_out, output); | 158 base::WriteUnicodeCharacter(code_point_out, output); |
159 else | 159 else |
160 // Puts REPLACEMENT CHARACTER (U+FFFD) if character is not readable UTF-8 | 160 // Puts REPLACEMENT CHARACTER (U+FFFD) if character is not readable UTF-8 |
161 base::WriteUnicodeCharacter(0xFFFD, output); | 161 base::WriteUnicodeCharacter(0xFFFD, output); |
162 } | 162 } |
163 } | 163 } |
164 | 164 |
165 NetworkProfileType GetProfileTypeForSource(NetworkUIData::ONCSource source) { | |
166 switch (source) { | |
167 case NetworkUIData::ONC_SOURCE_DEVICE_POLICY: | |
168 return PROFILE_SHARED; | |
169 case NetworkUIData::ONC_SOURCE_USER_POLICY: | |
170 return PROFILE_USER; | |
171 case NetworkUIData::ONC_SOURCE_NONE: | |
172 case NetworkUIData::ONC_SOURCE_USER_IMPORT: | |
173 return PROFILE_NONE; | |
174 } | |
175 NOTREACHED() << "Unknown ONC source " << source; | |
176 return PROFILE_NONE; | |
177 } | |
178 | |
165 //////////////////////////////////////////////////////////////////////////////// | 179 //////////////////////////////////////////////////////////////////////////////// |
166 // glib | 180 // glib |
167 | 181 |
168 Value* ConvertGlibValue(const GValue* gvalue); | 182 Value* ConvertGlibValue(const GValue* gvalue); |
169 | 183 |
170 void AppendListElement(const GValue* gvalue, gpointer user_data) { | 184 void AppendListElement(const GValue* gvalue, gpointer user_data) { |
171 ListValue* list = static_cast<ListValue*>(user_data); | 185 ListValue* list = static_cast<ListValue*>(user_data); |
172 Value* value = ConvertGlibValue(gvalue); | 186 Value* value = ConvertGlibValue(gvalue); |
173 list->Append(value); | 187 list->Append(value); |
174 } | 188 } |
(...skipping 2664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2839 OncNetworkParser parser(onc_blob, source); | 2853 OncNetworkParser parser(onc_blob, source); |
2840 | 2854 |
2841 for (int i = 0; i < parser.GetCertificatesSize(); i++) { | 2855 for (int i = 0; i < parser.GetCertificatesSize(); i++) { |
2842 // Insert each of the available certs into the certificate DB. | 2856 // Insert each of the available certs into the certificate DB. |
2843 if (!parser.ParseCertificate(i)) { | 2857 if (!parser.ParseCertificate(i)) { |
2844 DLOG(WARNING) << "Cannot parse certificate in ONC file"; | 2858 DLOG(WARNING) << "Cannot parse certificate in ONC file"; |
2845 return false; | 2859 return false; |
2846 } | 2860 } |
2847 } | 2861 } |
2848 | 2862 |
2863 // Parse all networks. Bail out if that fails. | |
2864 std::vector<Network*> networks; | |
stevenjb
2011/12/05 20:36:38
Can use ScopedVector here instead of STLDeleteElem
Mattias Nissler (ping if slow)
2011/12/05 20:58:29
Done.
| |
2849 for (int i = 0; i < parser.GetNetworkConfigsSize(); i++) { | 2865 for (int i = 0; i < parser.GetNetworkConfigsSize(); i++) { |
2850 // Parse Open Network Configuration blob into a temporary Network object. | 2866 // Parse Open Network Configuration blob into a temporary Network object. |
2851 scoped_ptr<Network> network(parser.ParseNetwork(i)); | 2867 Network* network = parser.ParseNetwork(i); |
2852 if (!network.get()) { | 2868 if (!network) { |
2853 DLOG(WARNING) << "Cannot parse network in ONC file"; | 2869 DLOG(WARNING) << "Cannot parse network in ONC file"; |
2870 STLDeleteElements(&networks); | |
2854 return false; | 2871 return false; |
2855 } | 2872 } |
2873 networks.push_back(network); | |
2874 } | |
2856 | 2875 |
2876 // Configure the networks. | |
2877 std::string profile_path(GetProfilePath(GetProfileTypeForSource(source))); | |
2878 | |
2879 // This map collects the unique identifiers of the networks that are defined | |
2880 // in this ONC blob. It's later used to clean out any previously-existing | |
2881 // networks that had been configured through policy but are no longer | |
2882 // specified in the updated ONC blob. | |
2883 std::set<std::string> network_ids; | |
stevenjb
2011/12/05 20:36:38
These comments are a little confusing; the "Config
Mattias Nissler (ping if slow)
2011/12/05 20:58:29
Done.
| |
2884 | |
2885 for (std::vector<Network*>::iterator iter(networks.begin()); | |
2886 iter != networks.end(); ++iter) { | |
2887 Network* network = *iter; | |
2857 DictionaryValue dict; | 2888 DictionaryValue dict; |
2858 for (Network::PropertyMap::const_iterator props = | 2889 for (Network::PropertyMap::const_iterator props = |
2859 network->property_map_.begin(); | 2890 network->property_map_.begin(); |
2860 props != network->property_map_.end(); ++props) { | 2891 props != network->property_map_.end(); ++props) { |
2861 std::string key = | 2892 std::string key = |
2862 NativeNetworkParser::property_mapper()->GetKey(props->first); | 2893 NativeNetworkParser::property_mapper()->GetKey(props->first); |
2863 if (!key.empty()) | 2894 if (!key.empty()) |
2864 dict.SetWithoutPathExpansion(key, props->second->DeepCopy()); | 2895 dict.SetWithoutPathExpansion(key, props->second->DeepCopy()); |
2865 else | 2896 else |
2866 VLOG(2) << "Property " << props->first << " will not be sent"; | 2897 VLOG(2) << "Property " << props->first << " will not be sent"; |
2867 } | 2898 } |
2868 | 2899 |
2900 // Set the appropriate profile for |source|. | |
2901 if (!profile_path.empty()) | |
2902 dict.SetString(flimflam::kProfileProperty, profile_path); | |
2903 | |
2869 CallConfigureService(network->unique_id(), &dict); | 2904 CallConfigureService(network->unique_id(), &dict); |
2905 network_ids.insert(network->unique_id()); | |
2870 } | 2906 } |
2907 | |
2908 // Go through the list of existing remembered networks and clean out the ones | |
2909 // that no longer have a definition in the ONC blob. We first collect the | |
2910 // networks and the actual deletion later because ForgetNetwork() changes the | |
stevenjb
2011/12/05 20:36:38
s/and the/and do the/
Mattias Nissler (ping if slow)
2011/12/05 20:58:29
Done.
| |
2911 // remembered network vectors. | |
2912 if (source != NetworkUIData::ONC_SOURCE_USER_IMPORT) { | |
2913 std::vector<std::string> to_be_deleted; | |
2914 for (WifiNetworkVector::iterator i(remembered_wifi_networks_.begin()); | |
2915 i != remembered_wifi_networks_.end(); ++i) { | |
2916 WifiNetwork* network = *i; | |
2917 if (NetworkUIData::GetONCSource(network) == source && | |
2918 network_ids.find(network->unique_id()) == network_ids.end()) | |
2919 to_be_deleted.push_back(network->service_path()); | |
2920 } | |
2921 | |
2922 for (VirtualNetworkVector::iterator i(remembered_virtual_networks_.begin()); | |
2923 i != remembered_virtual_networks_.end(); ++i) { | |
2924 VirtualNetwork* network = *i; | |
2925 if (NetworkUIData::GetONCSource(network) == source && | |
2926 network_ids.find(network->unique_id()) == network_ids.end()) | |
2927 to_be_deleted.push_back(network->service_path()); | |
2928 } | |
2929 | |
2930 for (std::vector<std::string>::const_iterator i(to_be_deleted.begin()); | |
2931 i != to_be_deleted.end(); ++i) { | |
2932 ForgetNetwork(*i); | |
2933 } | |
2934 } | |
2935 | |
2936 STLDeleteElements(&networks); | |
2871 return parser.GetNetworkConfigsSize() != 0; | 2937 return parser.GetNetworkConfigsSize() != 0; |
2872 } | 2938 } |
2873 | 2939 |
2874 //////////////////////////////////////////////////////////////////////////// | 2940 //////////////////////////////////////////////////////////////////////////// |
2875 // Testing functions. | 2941 // Testing functions. |
2876 | 2942 |
2877 bool NetworkLibraryImplBase::SetActiveNetwork( | 2943 bool NetworkLibraryImplBase::SetActiveNetwork( |
2878 ConnectionType type, const std::string& service_path) { | 2944 ConnectionType type, const std::string& service_path) { |
2879 Network* network = NULL; | 2945 Network* network = NULL; |
2880 if (!service_path.empty()) | 2946 if (!service_path.empty()) |
(...skipping 2461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5342 return impl; | 5408 return impl; |
5343 } | 5409 } |
5344 | 5410 |
5345 ///////////////////////////////////////////////////////////////////////////// | 5411 ///////////////////////////////////////////////////////////////////////////// |
5346 | 5412 |
5347 } // namespace chromeos | 5413 } // namespace chromeos |
5348 | 5414 |
5349 // Allows InvokeLater without adding refcounting. This class is a Singleton and | 5415 // Allows InvokeLater without adding refcounting. This class is a Singleton and |
5350 // won't be deleted until its last InvokeLater is run. | 5416 // won't be deleted until its last InvokeLater is run. |
5351 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::NetworkLibraryImplBase); | 5417 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::NetworkLibraryImplBase); |
OLD | NEW |