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 |
11 #include <algorithm> | 11 #include <algorithm> |
12 #include <list> | 12 #include <list> |
13 #include <map> | 13 #include <map> |
14 #include <set> | 14 #include <set> |
15 #include <utility> | 15 #include <utility> |
16 | 16 |
17 #include "base/bind.h" | 17 #include "base/bind.h" |
18 #include "base/i18n/icu_encoding_detection.h" | 18 #include "base/i18n/icu_encoding_detection.h" |
19 #include "base/i18n/icu_string_conversions.h" | 19 #include "base/i18n/icu_string_conversions.h" |
20 #include "base/i18n/time_formatting.h" | 20 #include "base/i18n/time_formatting.h" |
| 21 #include "base/memory/scoped_vector.h" |
21 #include "base/json/json_writer.h" // for debug output only. | 22 #include "base/json/json_writer.h" // for debug output only. |
22 #include "base/metrics/histogram.h" | 23 #include "base/metrics/histogram.h" |
23 #include "base/stl_util.h" | 24 #include "base/stl_util.h" |
24 #include "base/string_number_conversions.h" | 25 #include "base/string_number_conversions.h" |
25 #include "base/string_tokenizer.h" | 26 #include "base/string_tokenizer.h" |
26 #include "base/string_util.h" | 27 #include "base/string_util.h" |
27 #include "base/stringprintf.h" | 28 #include "base/stringprintf.h" |
28 #include "base/utf_string_conversion_utils.h" | 29 #include "base/utf_string_conversion_utils.h" |
29 #include "base/utf_string_conversions.h" | 30 #include "base/utf_string_conversions.h" |
30 #include "base/values.h" | 31 #include "base/values.h" |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 bool is_unicode_char = base::ReadUnicodeCharacter(str.c_str(), str.size(), | 157 bool is_unicode_char = base::ReadUnicodeCharacter(str.c_str(), str.size(), |
157 &index, &code_point_out); | 158 &index, &code_point_out); |
158 if (is_unicode_char && (code_point_out >= 0x20)) | 159 if (is_unicode_char && (code_point_out >= 0x20)) |
159 base::WriteUnicodeCharacter(code_point_out, output); | 160 base::WriteUnicodeCharacter(code_point_out, output); |
160 else | 161 else |
161 // Puts REPLACEMENT CHARACTER (U+FFFD) if character is not readable UTF-8 | 162 // Puts REPLACEMENT CHARACTER (U+FFFD) if character is not readable UTF-8 |
162 base::WriteUnicodeCharacter(0xFFFD, output); | 163 base::WriteUnicodeCharacter(0xFFFD, output); |
163 } | 164 } |
164 } | 165 } |
165 | 166 |
| 167 NetworkProfileType GetProfileTypeForSource(NetworkUIData::ONCSource source) { |
| 168 switch (source) { |
| 169 case NetworkUIData::ONC_SOURCE_DEVICE_POLICY: |
| 170 return PROFILE_SHARED; |
| 171 case NetworkUIData::ONC_SOURCE_USER_POLICY: |
| 172 return PROFILE_USER; |
| 173 case NetworkUIData::ONC_SOURCE_NONE: |
| 174 case NetworkUIData::ONC_SOURCE_USER_IMPORT: |
| 175 return PROFILE_NONE; |
| 176 } |
| 177 NOTREACHED() << "Unknown ONC source " << source; |
| 178 return PROFILE_NONE; |
| 179 } |
| 180 |
166 //////////////////////////////////////////////////////////////////////////////// | 181 //////////////////////////////////////////////////////////////////////////////// |
167 // glib | 182 // glib |
168 | 183 |
169 Value* ConvertGlibValue(const GValue* gvalue); | 184 Value* ConvertGlibValue(const GValue* gvalue); |
170 | 185 |
171 void AppendListElement(const GValue* gvalue, gpointer user_data) { | 186 void AppendListElement(const GValue* gvalue, gpointer user_data) { |
172 ListValue* list = static_cast<ListValue*>(user_data); | 187 ListValue* list = static_cast<ListValue*>(user_data); |
173 Value* value = ConvertGlibValue(gvalue); | 188 Value* value = ConvertGlibValue(gvalue); |
174 list->Append(value); | 189 list->Append(value); |
175 } | 190 } |
(...skipping 2674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2850 for (int i = 0; i < parser.GetCertificatesSize(); i++) { | 2865 for (int i = 0; i < parser.GetCertificatesSize(); i++) { |
2851 // Insert each of the available certs into the certificate DB. | 2866 // Insert each of the available certs into the certificate DB. |
2852 if (parser.ParseCertificate(i).get() == NULL) { | 2867 if (parser.ParseCertificate(i).get() == NULL) { |
2853 DLOG(WARNING) << "Cannot parse certificate in ONC file"; | 2868 DLOG(WARNING) << "Cannot parse certificate in ONC file"; |
2854 if (error) | 2869 if (error) |
2855 *error = parser.parse_error(); | 2870 *error = parser.parse_error(); |
2856 return false; | 2871 return false; |
2857 } | 2872 } |
2858 } | 2873 } |
2859 | 2874 |
| 2875 // Parse all networks. Bail out if that fails. |
| 2876 ScopedVector<Network> networks; |
2860 for (int i = 0; i < parser.GetNetworkConfigsSize(); i++) { | 2877 for (int i = 0; i < parser.GetNetworkConfigsSize(); i++) { |
2861 // Parse Open Network Configuration blob into a temporary Network object. | 2878 // Parse Open Network Configuration blob into a temporary Network object. |
2862 scoped_ptr<Network> network(parser.ParseNetwork(i)); | 2879 Network* network = parser.ParseNetwork(i); |
2863 if (!network.get()) { | 2880 if (!network) { |
2864 DLOG(WARNING) << "Cannot parse network in ONC file"; | 2881 DLOG(WARNING) << "Cannot parse network in ONC file"; |
2865 if (error) | 2882 if (error) |
2866 *error = parser.parse_error(); | 2883 *error = parser.parse_error(); |
2867 return false; | 2884 return false; |
2868 } | 2885 } |
| 2886 networks.push_back(network); |
| 2887 } |
2869 | 2888 |
| 2889 // Configure the networks. While doing so, collect unique identifiers of the |
| 2890 // networks that are defined in the ONC blob in |network_ids|. They're later |
| 2891 // used to clean out any previously-existing networks that had been configured |
| 2892 // through policy but are no longer specified in the updated ONC blob. |
| 2893 std::set<std::string> network_ids; |
| 2894 std::string profile_path(GetProfilePath(GetProfileTypeForSource(source))); |
| 2895 for (std::vector<Network*>::iterator iter(networks.begin()); |
| 2896 iter != networks.end(); ++iter) { |
| 2897 Network* network = *iter; |
2870 DictionaryValue dict; | 2898 DictionaryValue dict; |
2871 for (Network::PropertyMap::const_iterator props = | 2899 for (Network::PropertyMap::const_iterator props = |
2872 network->property_map_.begin(); | 2900 network->property_map_.begin(); |
2873 props != network->property_map_.end(); ++props) { | 2901 props != network->property_map_.end(); ++props) { |
2874 std::string key = | 2902 std::string key = |
2875 NativeNetworkParser::property_mapper()->GetKey(props->first); | 2903 NativeNetworkParser::property_mapper()->GetKey(props->first); |
2876 if (!key.empty()) | 2904 if (!key.empty()) |
2877 dict.SetWithoutPathExpansion(key, props->second->DeepCopy()); | 2905 dict.SetWithoutPathExpansion(key, props->second->DeepCopy()); |
2878 else | 2906 else |
2879 VLOG(2) << "Property " << props->first << " will not be sent"; | 2907 VLOG(2) << "Property " << props->first << " will not be sent"; |
2880 } | 2908 } |
2881 | 2909 |
| 2910 // Set the appropriate profile for |source|. |
| 2911 if (!profile_path.empty()) |
| 2912 dict.SetString(flimflam::kProfileProperty, profile_path); |
| 2913 |
2882 CallConfigureService(network->unique_id(), &dict); | 2914 CallConfigureService(network->unique_id(), &dict); |
| 2915 network_ids.insert(network->unique_id()); |
| 2916 } |
| 2917 |
| 2918 // Go through the list of existing remembered networks and clean out the ones |
| 2919 // that no longer have a definition in the ONC blob. We first collect the |
| 2920 // networks and do the actual deletion later because ForgetNetwork() changes |
| 2921 // the remembered network vectors. |
| 2922 if (source != NetworkUIData::ONC_SOURCE_USER_IMPORT) { |
| 2923 std::vector<std::string> to_be_deleted; |
| 2924 for (WifiNetworkVector::iterator i(remembered_wifi_networks_.begin()); |
| 2925 i != remembered_wifi_networks_.end(); ++i) { |
| 2926 WifiNetwork* network = *i; |
| 2927 if (NetworkUIData::GetONCSource(network) == source && |
| 2928 network_ids.find(network->unique_id()) == network_ids.end()) |
| 2929 to_be_deleted.push_back(network->service_path()); |
| 2930 } |
| 2931 |
| 2932 for (VirtualNetworkVector::iterator i(remembered_virtual_networks_.begin()); |
| 2933 i != remembered_virtual_networks_.end(); ++i) { |
| 2934 VirtualNetwork* network = *i; |
| 2935 if (NetworkUIData::GetONCSource(network) == source && |
| 2936 network_ids.find(network->unique_id()) == network_ids.end()) |
| 2937 to_be_deleted.push_back(network->service_path()); |
| 2938 } |
| 2939 |
| 2940 for (std::vector<std::string>::const_iterator i(to_be_deleted.begin()); |
| 2941 i != to_be_deleted.end(); ++i) { |
| 2942 ForgetNetwork(*i); |
| 2943 } |
2883 } | 2944 } |
2884 | 2945 |
2885 if (parser.GetNetworkConfigsSize() != 0 || | 2946 if (parser.GetNetworkConfigsSize() != 0 || |
2886 parser.GetCertificatesSize() != 0) { | 2947 parser.GetCertificatesSize() != 0) { |
2887 if (error) | 2948 if (error) |
2888 *error = l10n_util::GetStringUTF8( | 2949 *error = l10n_util::GetStringUTF8( |
2889 IDS_NETWORK_CONFIG_ERROR_NETWORK_IMPORT); | 2950 IDS_NETWORK_CONFIG_ERROR_NETWORK_IMPORT); |
2890 return false; | 2951 return false; |
2891 } | 2952 } |
2892 return true; | 2953 return true; |
(...skipping 2470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5363 return impl; | 5424 return impl; |
5364 } | 5425 } |
5365 | 5426 |
5366 ///////////////////////////////////////////////////////////////////////////// | 5427 ///////////////////////////////////////////////////////////////////////////// |
5367 | 5428 |
5368 } // namespace chromeos | 5429 } // namespace chromeos |
5369 | 5430 |
5370 // Allows InvokeLater without adding refcounting. This class is a Singleton and | 5431 // Allows InvokeLater without adding refcounting. This class is a Singleton and |
5371 // won't be deleted until its last InvokeLater is run. | 5432 // won't be deleted until its last InvokeLater is run. |
5372 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::NetworkLibraryImplBase); | 5433 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::NetworkLibraryImplBase); |
OLD | NEW |