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 <dbus/dbus-glib.h> | |
9 #include <dbus/dbus-gtype-specialized.h> | |
10 #include <glib-object.h> | |
8 #include <map> | 11 #include <map> |
9 #include <set> | 12 #include <set> |
10 | 13 |
11 #include "base/i18n/icu_encoding_detection.h" | 14 #include "base/i18n/icu_encoding_detection.h" |
12 #include "base/i18n/icu_string_conversions.h" | 15 #include "base/i18n/icu_string_conversions.h" |
13 #include "base/i18n/time_formatting.h" | 16 #include "base/i18n/time_formatting.h" |
14 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
15 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
16 #include "base/string_number_conversions.h" | 19 #include "base/string_number_conversions.h" |
17 #include "base/string_tokenizer.h" | 20 #include "base/string_tokenizer.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
62 // remembered_network_map_, in descending order of preference. | 65 // remembered_network_map_, in descending order of preference. |
63 // | 66 // |
64 // network_manager_monitor_: a handle to the libcros network Manager handler. | 67 // network_manager_monitor_: a handle to the libcros network Manager handler. |
65 // NetworkManagerStatusChanged: This handles all messages from the Manager. | 68 // NetworkManagerStatusChanged: This handles all messages from the Manager. |
66 // Messages are parsed here and the appropriate updates are then requested. | 69 // Messages are parsed here and the appropriate updates are then requested. |
67 // | 70 // |
68 // UpdateNetworkServiceList: This is the primary Manager handler. It handles | 71 // UpdateNetworkServiceList: This is the primary Manager handler. It handles |
69 // the "Services" message which list all visible networks. The handler | 72 // the "Services" message which list all visible networks. The handler |
70 // rebuilds the network lists without destroying existing Network structures, | 73 // rebuilds the network lists without destroying existing Network structures, |
71 // then requests neccessary updates to be fetched asynchronously from | 74 // then requests neccessary updates to be fetched asynchronously from |
72 // libcros (RequestNetworkServiceInfo). | 75 // libcros (RequestNetworkServiceProperties). |
73 // | 76 // |
74 // TODO(stevenjb): Document cellular data plan handlers. | 77 // TODO(stevenjb): Document cellular data plan handlers. |
75 // | 78 // |
76 // AddNetworkObserver: Adds an observer for a specific network. | 79 // AddNetworkObserver: Adds an observer for a specific network. |
77 // UpdateNetworkStatus: This handles changes to a monitored service, typically | 80 // UpdateNetworkStatus: This handles changes to a monitored service, typically |
78 // changes to transient states like Strength. (Note: also updates State). | 81 // changes to transient states like Strength. (Note: also updates State). |
79 // | 82 // |
80 // AddNetworkDeviceObserver: Adds an observer for a specific device. | 83 // AddNetworkDeviceObserver: Adds an observer for a specific device. |
81 // Will be called on any device property change. | 84 // Will be called on any device property change. |
82 // UpdateNetworkDeviceStatus: Handles changes to a monitored device, like | 85 // UpdateNetworkDeviceStatus: Handles changes to a monitored device, like |
(...skipping 24 matching lines...) Expand all Loading... | |
107 // to be able to connect to any network. | 110 // to be able to connect to any network. |
108 const char* kAlwaysInRoamingOperators[] = { | 111 const char* kAlwaysInRoamingOperators[] = { |
109 "CUBIC" | 112 "CUBIC" |
110 }; | 113 }; |
111 | 114 |
112 //////////////////////////////////////////////////////////////////////////////// | 115 //////////////////////////////////////////////////////////////////////////////// |
113 // Misc. | 116 // Misc. |
114 | 117 |
115 // Safe string constructor since we can't rely on non NULL pointers | 118 // Safe string constructor since we can't rely on non NULL pointers |
116 // for string values from libcros. | 119 // for string values from libcros. |
117 static std::string SafeString(const char* s) { | 120 std::string SafeString(const char* s) { |
118 return s ? std::string(s) : std::string(); | 121 return s ? std::string(s) : std::string(); |
119 } | 122 } |
120 | 123 |
121 // Erase the memory used by a string, then clear it. | 124 // Erase the memory used by a string, then clear it. |
122 static void WipeString(std::string* str) { | 125 void WipeString(std::string* str) { |
123 str->assign(str->size(), '\0'); | 126 str->assign(str->size(), '\0'); |
124 str->clear(); | 127 str->clear(); |
125 } | 128 } |
126 | 129 |
127 static bool EnsureCrosLoaded() { | 130 bool EnsureCrosLoaded() { |
128 if (!CrosLibrary::Get()->EnsureLoaded() || | 131 if (!CrosLibrary::Get()->EnsureLoaded() || |
129 !CrosLibrary::Get()->GetNetworkLibrary()->IsCros()) { | 132 !CrosLibrary::Get()->GetNetworkLibrary()->IsCros()) { |
130 return false; | 133 return false; |
131 } else { | 134 } else { |
132 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)) | 135 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)) |
133 << "chromeos_network calls made from non UI thread!"; | 136 << "chromeos_network calls made from non UI thread!"; |
134 return true; | 137 return true; |
135 } | 138 } |
136 } | 139 } |
137 | 140 |
138 static void ValidateUTF8(const std::string& str, std::string* output) { | 141 void ValidateUTF8(const std::string& str, std::string* output) { |
139 output->clear(); | 142 output->clear(); |
140 | 143 |
141 for (int32 index = 0; index < static_cast<int32>(str.size()); ++index) { | 144 for (int32 index = 0; index < static_cast<int32>(str.size()); ++index) { |
142 uint32 code_point_out; | 145 uint32 code_point_out; |
143 bool is_unicode_char = base::ReadUnicodeCharacter(str.c_str(), str.size(), | 146 bool is_unicode_char = base::ReadUnicodeCharacter(str.c_str(), str.size(), |
144 &index, &code_point_out); | 147 &index, &code_point_out); |
145 if (is_unicode_char && (code_point_out >= 0x20)) | 148 if (is_unicode_char && (code_point_out >= 0x20)) |
146 base::WriteUnicodeCharacter(code_point_out, output); | 149 base::WriteUnicodeCharacter(code_point_out, output); |
147 else | 150 else |
148 // Puts REPLACEMENT CHARACTER (U+FFFD) if character is not readable UTF-8 | 151 // Puts REPLACEMENT CHARACTER (U+FFFD) if character is not readable UTF-8 |
149 base::WriteUnicodeCharacter(0xFFFD, output); | 152 base::WriteUnicodeCharacter(0xFFFD, output); |
150 } | 153 } |
151 } | 154 } |
152 | 155 |
156 //////////////////////////////////////////////////////////////////////////////// | |
157 // glib | |
158 | |
159 Value* ConvertGlibValue(const GValue* gvalue); | |
160 | |
161 void AppendListElement(const GValue *gvalue, ::gpointer user_data) { | |
tony
2011/08/29 17:01:22
Nit: GValue* gvalue. I would probably also drop t
stevenjb
2011/08/29 20:36:31
Done.
| |
162 ListValue* list = static_cast<ListValue*>(user_data); | |
163 Value* value = ConvertGlibValue(gvalue); | |
164 list->Append(value); | |
165 } | |
166 | |
167 void AppendDictionaryElement(const GValue *keyvalue, | |
168 const GValue *gvalue, | |
169 ::gpointer user_data) { | |
tony
2011/08/29 17:01:22
ditto
stevenjb
2011/08/29 20:36:31
Done.
| |
170 DictionaryValue* dict = static_cast<DictionaryValue*>(user_data); | |
171 std::string key(g_value_get_string(keyvalue)); | |
172 Value* value = ConvertGlibValue(gvalue); | |
173 dict->SetWithoutPathExpansion(key, value); | |
174 } | |
175 | |
176 Value* ConvertGlibValue(const GValue* gvalue) { | |
177 if (G_VALUE_HOLDS_STRING(gvalue)) { | |
178 return Value::CreateStringValue(g_value_get_string(gvalue)); | |
179 } else if (G_VALUE_HOLDS_BOOLEAN(gvalue)) { | |
180 return Value::CreateBooleanValue( | |
181 static_cast<bool>(g_value_get_boolean(gvalue))); | |
182 } else if (G_VALUE_HOLDS_INT(gvalue)) { | |
183 return Value::CreateIntegerValue(g_value_get_int(gvalue)); | |
184 } else if (G_VALUE_HOLDS_UINT(gvalue)) { | |
185 return Value::CreateIntegerValue( | |
186 static_cast<int>(g_value_get_uint(gvalue))); | |
187 } else if (G_VALUE_HOLDS_UCHAR(gvalue)) { | |
188 return Value::CreateIntegerValue( | |
189 static_cast<int>(g_value_get_uchar(gvalue))); | |
190 } else if (G_VALUE_HOLDS(gvalue, DBUS_TYPE_G_OBJECT_PATH)) { | |
191 const char* path = static_cast<const char*>(::g_value_get_boxed(gvalue)); | |
tony
2011/08/29 17:01:22
Nit: drop :: here and other users in this function
stevenjb
2011/08/29 20:36:31
Done.
| |
192 return Value::CreateStringValue(path); | |
193 } else if (G_VALUE_HOLDS(gvalue, G_TYPE_STRV)) { | |
194 ListValue* list = new ListValue(); | |
195 for (GStrv strv = static_cast<GStrv>(::g_value_get_boxed(gvalue)); | |
196 *strv != NULL; ++strv) { | |
197 list->Append(Value::CreateStringValue(*strv)); | |
198 } | |
199 return list; | |
200 } else if (::dbus_g_type_is_collection(G_VALUE_TYPE(gvalue))) { | |
201 ListValue* list = new ListValue(); | |
202 ::dbus_g_type_collection_value_iterate(gvalue, AppendListElement, list); | |
203 return list; | |
204 } else if (::dbus_g_type_is_map(G_VALUE_TYPE(gvalue))) { | |
205 DictionaryValue* dict = new DictionaryValue(); | |
206 ::dbus_g_type_map_value_iterate(gvalue, AppendDictionaryElement, dict); | |
207 return dict; | |
208 } else if (G_VALUE_HOLDS(gvalue, G_TYPE_VALUE)) { | |
209 const GValue* bvalue = static_cast<GValue*>(::g_value_get_boxed(gvalue)); | |
210 return ConvertGlibValue(bvalue); | |
211 } else { | |
212 LOG(ERROR) << "Unrecognized Glib value type: " << G_VALUE_TYPE(gvalue); | |
213 return Value::CreateNullValue(); | |
214 } | |
215 } | |
216 | |
217 DictionaryValue* ConvertGHashTable(GHashTable* ghash) { | |
218 DictionaryValue* dict = new DictionaryValue(); | |
219 GHashTableIter iter; | |
220 gpointer gkey, gvalue; | |
221 g_hash_table_iter_init(&iter, ghash); | |
222 while (g_hash_table_iter_next(&iter, &gkey, &gvalue)) { | |
223 std::string key(static_cast<char*>(gkey)); | |
224 Value* value = ConvertGlibValue(static_cast<GValue*>(gvalue)); | |
225 dict->SetWithoutPathExpansion(key, value); | |
226 } | |
227 return dict; | |
228 } | |
229 | |
230 GValue* ConvertBoolToGValue(bool b) { | |
231 GValue* gvalue = new GValue(); | |
232 g_value_init(gvalue, G_TYPE_BOOLEAN); | |
233 g_value_set_boolean(gvalue, b); | |
234 return gvalue; | |
235 } | |
236 | |
237 GValue* ConvertIntToGValue(int i) { | |
238 // Converting to a 32-bit signed int type in particular, since | |
239 // that's what flimflam expects in its DBus API | |
240 GValue* gvalue = new GValue(); | |
241 g_value_init(gvalue, G_TYPE_INT); | |
242 g_value_set_int(gvalue, i); | |
243 return gvalue; | |
244 } | |
245 | |
246 GValue* ConvertStringToGValue(const std::string& s) { | |
247 GValue* gvalue = new GValue(); | |
248 g_value_init(gvalue, G_TYPE_STRING); | |
249 g_value_set_string(gvalue, s.c_str()); | |
250 return gvalue; | |
251 } | |
252 | |
253 GValue* ConvertValueToGValue(const Value* value) { | |
254 switch (value->GetType()) { | |
255 case ::Value::TYPE_BOOLEAN: { | |
256 bool out; | |
257 if (value->GetAsBoolean(&out)) | |
258 return ConvertBoolToGValue(out); | |
259 break; | |
260 } | |
261 case ::Value::TYPE_INTEGER: { | |
262 int out; | |
263 if (value->GetAsInteger(&out)) | |
264 return ConvertIntToGValue(out); | |
265 break; | |
266 } | |
267 case ::Value::TYPE_STRING: { | |
268 std::string out; | |
269 if (value->GetAsString(&out)) | |
270 return ConvertStringToGValue(out); | |
271 break; | |
272 } | |
273 default: | |
274 // Other Value types - DICTIONARY, LIST, NULL, REAL, BINARY - | |
tony
2011/08/29 17:01:22
Nit: I prefer to list all the types explicitly rat
stevenjb
2011/08/29 20:36:31
Done.
| |
275 // aren't passed through this mechanism, and so we're not going to | |
276 // bother to try converting them. | |
277 NOTREACHED() << "Unconverted Value of type: " << value->GetType(); | |
278 return NULL; | |
279 } | |
280 NOTREACHED() << "Value conversion failed, type: " << value->GetType(); | |
281 return NULL; | |
282 } | |
283 | |
153 } // namespace | 284 } // namespace |
154 | 285 |
155 //////////////////////////////////////////////////////////////////////////////// | 286 //////////////////////////////////////////////////////////////////////////////// |
156 // FoundCellularNetwork | 287 // FoundCellularNetwork |
157 | 288 |
158 FoundCellularNetwork::FoundCellularNetwork() {} | 289 FoundCellularNetwork::FoundCellularNetwork() {} |
159 | 290 |
160 FoundCellularNetwork::~FoundCellularNetwork() {} | 291 FoundCellularNetwork::~FoundCellularNetwork() {} |
161 | 292 |
162 //////////////////////////////////////////////////////////////////////////////// | 293 //////////////////////////////////////////////////////////////////////////////// |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
253 unique_id_ = name_; | 384 unique_id_ = name_; |
254 } | 385 } |
255 | 386 |
256 bool Network::RequiresUserProfile() const { | 387 bool Network::RequiresUserProfile() const { |
257 return false; | 388 return false; |
258 } | 389 } |
259 | 390 |
260 void Network::CopyCredentialsFromRemembered(Network* remembered) { | 391 void Network::CopyCredentialsFromRemembered(Network* remembered) { |
261 } | 392 } |
262 | 393 |
263 void Network::SetValueProperty(const char* prop, Value* val) { | 394 void Network::SetValueProperty(const char* prop, Value* value) { |
264 DCHECK(prop); | 395 DCHECK(prop); |
265 DCHECK(val); | 396 DCHECK(value); |
266 if (!EnsureCrosLoaded()) | 397 if (!EnsureCrosLoaded()) |
267 return; | 398 return; |
268 chromeos::SetNetworkServiceProperty(service_path_.c_str(), prop, val); | 399 scoped_ptr<GValue> gvalue(ConvertValueToGValue(value)); |
400 chromeos::SetNetworkServicePropertyGValue( | |
401 service_path_.c_str(), prop, gvalue.get()); | |
269 } | 402 } |
270 | 403 |
271 void Network::ClearProperty(const char* prop) { | 404 void Network::ClearProperty(const char* prop) { |
272 DCHECK(prop); | 405 DCHECK(prop); |
273 if (!EnsureCrosLoaded()) | 406 if (!EnsureCrosLoaded()) |
274 return; | 407 return; |
275 chromeos::ClearNetworkServiceProperty(service_path_.c_str(), prop); | 408 chromeos::ClearNetworkServiceProperty(service_path_.c_str(), prop); |
276 } | 409 } |
277 | 410 |
278 void Network::SetStringProperty( | 411 void Network::SetStringProperty( |
(...skipping 2694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2973 | 3106 |
2974 virtual NetworkIPConfigVector GetIPConfigs( | 3107 virtual NetworkIPConfigVector GetIPConfigs( |
2975 const std::string& device_path, | 3108 const std::string& device_path, |
2976 std::string* hardware_address, | 3109 std::string* hardware_address, |
2977 HardwareAddressFormat format) OVERRIDE; | 3110 HardwareAddressFormat format) OVERRIDE; |
2978 virtual void SetIPConfig(const NetworkIPConfig& ipconfig) OVERRIDE; | 3111 virtual void SetIPConfig(const NetworkIPConfig& ipconfig) OVERRIDE; |
2979 | 3112 |
2980 ////////////////////////////////////////////////////////////////////////////// | 3113 ////////////////////////////////////////////////////////////////////////////// |
2981 // Calbacks. | 3114 // Calbacks. |
2982 static void NetworkStatusChangedHandler( | 3115 static void NetworkStatusChangedHandler( |
2983 void* object, const char* path, const char* key, const Value* value); | 3116 void* object, const char* path, const char* key, const GValue* value); |
2984 void UpdateNetworkStatus( | 3117 void UpdateNetworkStatus( |
2985 const std::string& path, const std::string& key, const Value& value); | 3118 const std::string& path, const std::string& key, const Value& value); |
2986 | 3119 |
2987 static void NetworkDevicePropertyChangedHandler( | 3120 static void NetworkDevicePropertyChangedHandler( |
2988 void* object, const char* path, const char* key, const Value* value); | 3121 void* object, const char* path, const char* key, const GValue* gvalue); |
2989 void UpdateNetworkDeviceStatus( | 3122 void UpdateNetworkDeviceStatus( |
2990 const std::string& path, const std::string& key, const Value& value); | 3123 const std::string& path, const std::string& key, const Value& value); |
2991 | 3124 |
2992 static void PinOperationCallback(void* object, | 3125 static void PinOperationCallback(void* object, |
2993 const char* path, | 3126 const char* path, |
2994 NetworkMethodErrorType error, | 3127 NetworkMethodErrorType error, |
2995 const char* error_message); | 3128 const char* error_message); |
2996 | 3129 |
2997 static void CellularRegisterCallback(void* object, | 3130 static void CellularRegisterCallback(void* object, |
2998 const char* path, | 3131 const char* path, |
2999 NetworkMethodErrorType error, | 3132 NetworkMethodErrorType error, |
3000 const char* error_message); | 3133 const char* error_message); |
3001 | 3134 |
3002 static void NetworkConnectCallback(void* object, | 3135 static void NetworkConnectCallback(void* object, |
3003 const char* service_path, | 3136 const char* service_path, |
3004 NetworkMethodErrorType error, | 3137 NetworkMethodErrorType error, |
3005 const char* error_message); | 3138 const char* error_message); |
3006 | 3139 |
3007 static void WifiServiceUpdateAndConnect( | 3140 static void WifiServiceUpdateAndConnect( |
3008 void* object, const char* service_path, const Value* info); | 3141 void* object, const char* service_path, GHashTable* ghash); |
3009 static void VPNServiceUpdateAndConnect( | 3142 static void VPNServiceUpdateAndConnect( |
3010 void* object, const char* service_path, const Value* info); | 3143 void* object, const char* service_path, GHashTable* ghash); |
3011 | 3144 |
3012 static void NetworkManagerStatusChangedHandler( | 3145 static void NetworkManagerStatusChangedHandler( |
3013 void* object, const char* path, const char* key, const Value* value); | 3146 void* object, const char* path, const char* key, const GValue* value); |
3014 static void NetworkManagerUpdate( | 3147 static void NetworkManagerUpdate( |
3015 void* object, const char* manager_path, const Value* info); | 3148 void* object, const char* manager_path, GHashTable* ghsash); |
tony
2011/08/29 17:01:22
Nit: typo
stevenjb
2011/08/29 20:36:31
Done.
| |
3016 | 3149 |
3017 static void DataPlanUpdateHandler(void* object, | 3150 static void DataPlanUpdateHandler(void* object, |
3018 const char* modem_service_path, | 3151 const char* modem_service_path, |
3019 const CellularDataPlanList* dataplan); | 3152 const CellularDataPlanList* dataplan); |
3020 | 3153 |
3021 static void NetworkServiceUpdate( | 3154 static void NetworkServiceUpdate( |
3022 void* object, const char* service_path, const Value* info); | 3155 void* object, const char* service_path, GHashTable* ghash); |
3023 static void RememberedNetworkServiceUpdate( | 3156 static void RememberedNetworkServiceUpdate( |
3024 void* object, const char* service_path, const Value* info); | 3157 void* object, const char* service_path, GHashTable* ghash); |
3025 static void ProfileUpdate( | 3158 static void ProfileUpdate( |
3026 void* object, const char* profile_path, const Value* info); | 3159 void* object, const char* profile_path, GHashTable* ghash); |
3027 static void NetworkDeviceUpdate( | 3160 static void NetworkDeviceUpdate( |
3028 void* object, const char* device_path, const Value* info); | 3161 void* object, const char* device_path, GHashTable* ghash); |
3029 | 3162 |
3030 private: | 3163 private: |
3031 // This processes all Manager update messages. | 3164 // This processes all Manager update messages. |
3032 void NetworkManagerStatusChanged(const char* key, const Value* value); | 3165 void NetworkManagerStatusChanged(const char* key, const Value* value); |
3033 void ParseNetworkManager(const DictionaryValue& dict); | 3166 void ParseNetworkManager(const DictionaryValue& dict); |
3034 void UpdateTechnologies(const ListValue* technologies, int* bitfieldp); | 3167 void UpdateTechnologies(const ListValue* technologies, int* bitfieldp); |
3035 void UpdateAvailableTechnologies(const ListValue* technologies); | 3168 void UpdateAvailableTechnologies(const ListValue* technologies); |
3036 void UpdateEnabledTechnologies(const ListValue* technologies); | 3169 void UpdateEnabledTechnologies(const ListValue* technologies); |
3037 void UpdateConnectedTechnologies(const ListValue* technologies); | 3170 void UpdateConnectedTechnologies(const ListValue* technologies); |
3038 | 3171 |
(...skipping 16 matching lines...) Expand all Loading... | |
3055 const DictionaryValue& info); | 3188 const DictionaryValue& info); |
3056 | 3189 |
3057 // Empty device observer to ensure that device property updates are received. | 3190 // Empty device observer to ensure that device property updates are received. |
3058 class NetworkLibraryDeviceObserver : public NetworkDeviceObserver { | 3191 class NetworkLibraryDeviceObserver : public NetworkDeviceObserver { |
3059 public: | 3192 public: |
3060 virtual ~NetworkLibraryDeviceObserver() {} | 3193 virtual ~NetworkLibraryDeviceObserver() {} |
3061 virtual void OnNetworkDeviceChanged( | 3194 virtual void OnNetworkDeviceChanged( |
3062 NetworkLibrary* cros, const NetworkDevice* device) OVERRIDE {} | 3195 NetworkLibrary* cros, const NetworkDevice* device) OVERRIDE {} |
3063 }; | 3196 }; |
3064 | 3197 |
3065 typedef std::map<std::string, chromeos::PropertyChangeMonitor> | 3198 typedef std::map<std::string, chromeos::NetworkPropertiesMonitor> |
3066 PropertyChangeMonitorMap; | 3199 NetworkPropertiesMonitorMap; |
3067 | 3200 |
3068 // For monitoring network manager status changes. | 3201 // For monitoring network manager status changes. |
3069 PropertyChangeMonitor network_manager_monitor_; | 3202 NetworkPropertiesMonitor network_manager_monitor_; |
3070 | 3203 |
3071 // For monitoring data plan changes to the connected cellular network. | 3204 // For monitoring data plan changes to the connected cellular network. |
3072 DataPlanUpdateMonitor data_plan_monitor_; | 3205 DataPlanUpdateMonitor data_plan_monitor_; |
3073 | 3206 |
3074 // Network device observer. | 3207 // Network device observer. |
3075 scoped_ptr<NetworkLibraryDeviceObserver> network_device_observer_; | 3208 scoped_ptr<NetworkLibraryDeviceObserver> network_device_observer_; |
3076 | 3209 |
3077 // Map of monitored networks. | 3210 // Map of monitored networks. |
3078 PropertyChangeMonitorMap montitored_networks_; | 3211 NetworkPropertiesMonitorMap montitored_networks_; |
3079 | 3212 |
3080 // Map of monitored devices. | 3213 // Map of monitored devices. |
3081 PropertyChangeMonitorMap montitored_devices_; | 3214 NetworkPropertiesMonitorMap montitored_devices_; |
3082 | 3215 |
3083 DISALLOW_COPY_AND_ASSIGN(NetworkLibraryImplCros); | 3216 DISALLOW_COPY_AND_ASSIGN(NetworkLibraryImplCros); |
3084 }; | 3217 }; |
3085 | 3218 |
3086 //////////////////////////////////////////////////////////////////////////// | 3219 //////////////////////////////////////////////////////////////////////////// |
3087 | 3220 |
3088 NetworkLibraryImplCros::NetworkLibraryImplCros() | 3221 NetworkLibraryImplCros::NetworkLibraryImplCros() |
3089 : NetworkLibraryImplBase(), | 3222 : NetworkLibraryImplBase(), |
3090 network_manager_monitor_(NULL), | 3223 network_manager_monitor_(NULL), |
3091 data_plan_monitor_(NULL) { | 3224 data_plan_monitor_(NULL) { |
3092 } | 3225 } |
3093 | 3226 |
3094 NetworkLibraryImplCros::~NetworkLibraryImplCros() { | 3227 NetworkLibraryImplCros::~NetworkLibraryImplCros() { |
3095 if (network_manager_monitor_) | 3228 if (network_manager_monitor_) |
3096 chromeos::DisconnectPropertyChangeMonitor(network_manager_monitor_); | 3229 chromeos::DisconnectNetworkPropertiesMonitor(network_manager_monitor_); |
3097 if (data_plan_monitor_) | 3230 if (data_plan_monitor_) |
3098 chromeos::DisconnectDataPlanUpdateMonitor(data_plan_monitor_); | 3231 chromeos::DisconnectDataPlanUpdateMonitor(data_plan_monitor_); |
3099 for (PropertyChangeMonitorMap::iterator iter = montitored_networks_.begin(); | 3232 for (NetworkPropertiesMonitorMap::iterator iter = |
3233 montitored_networks_.begin(); | |
3100 iter != montitored_networks_.end(); ++iter) { | 3234 iter != montitored_networks_.end(); ++iter) { |
3101 chromeos::DisconnectPropertyChangeMonitor(iter->second); | 3235 chromeos::DisconnectNetworkPropertiesMonitor(iter->second); |
3102 } | 3236 } |
3103 for (PropertyChangeMonitorMap::iterator iter = montitored_devices_.begin(); | 3237 for (NetworkPropertiesMonitorMap::iterator iter = |
3238 montitored_devices_.begin(); | |
3104 iter != montitored_devices_.end(); ++iter) { | 3239 iter != montitored_devices_.end(); ++iter) { |
3105 chromeos::DisconnectPropertyChangeMonitor(iter->second); | 3240 chromeos::DisconnectNetworkPropertiesMonitor(iter->second); |
3106 } | 3241 } |
3107 } | 3242 } |
3108 | 3243 |
3109 void NetworkLibraryImplCros::Init() { | 3244 void NetworkLibraryImplCros::Init() { |
3110 // First, get the currently available networks. This data is cached | 3245 // First, get the currently available networks. This data is cached |
3111 // on the connman side, so the call should be quick. | 3246 // on the connman side, so the call should be quick. |
3112 VLOG(1) << "Requesting initial network manager info from libcros."; | 3247 VLOG(1) << "Requesting initial network manager info from libcros."; |
3113 chromeos::RequestNetworkManagerInfo(&NetworkManagerUpdate, this); | 3248 chromeos::RequestNetworkManagerProperties(&NetworkManagerUpdate, this); |
3114 network_manager_monitor_ = | 3249 network_manager_monitor_ = |
3115 chromeos::MonitorNetworkManager(&NetworkManagerStatusChangedHandler, | 3250 chromeos::MonitorNetworkManagerProperties( |
3116 this); | 3251 &NetworkManagerStatusChangedHandler, this); |
3117 data_plan_monitor_ = | 3252 data_plan_monitor_ = |
3118 chromeos::MonitorCellularDataPlan(&DataPlanUpdateHandler, this); | 3253 chromeos::MonitorCellularDataPlan(&DataPlanUpdateHandler, this); |
3119 // Always have at least one device obsever so that device updates are | 3254 // Always have at least one device obsever so that device updates are |
3120 // always received. | 3255 // always received. |
3121 network_device_observer_.reset(new NetworkLibraryDeviceObserver()); | 3256 network_device_observer_.reset(new NetworkLibraryDeviceObserver()); |
3122 } | 3257 } |
3123 | 3258 |
3124 ////////////////////////////////////////////////////////////////////////////// | 3259 ////////////////////////////////////////////////////////////////////////////// |
3125 // NetworkLibraryImplBase implementation. | 3260 // NetworkLibraryImplBase implementation. |
3126 | 3261 |
3127 void NetworkLibraryImplCros::MonitorNetworkStart( | 3262 void NetworkLibraryImplCros::MonitorNetworkStart( |
3128 const std::string& service_path) { | 3263 const std::string& service_path) { |
3129 if (montitored_networks_.find(service_path) == montitored_networks_.end()) { | 3264 if (montitored_networks_.find(service_path) == montitored_networks_.end()) { |
3130 chromeos::PropertyChangeMonitor monitor = | 3265 chromeos::NetworkPropertiesMonitor monitor = |
3131 chromeos::MonitorNetworkService(&NetworkStatusChangedHandler, | 3266 chromeos::MonitorNetworkServiceProperties( |
3132 service_path.c_str(), | 3267 &NetworkStatusChangedHandler, service_path.c_str(), this); |
3133 this); | |
3134 montitored_networks_[service_path] = monitor; | 3268 montitored_networks_[service_path] = monitor; |
3135 } | 3269 } |
3136 } | 3270 } |
3137 | 3271 |
3138 void NetworkLibraryImplCros::MonitorNetworkStop( | 3272 void NetworkLibraryImplCros::MonitorNetworkStop( |
3139 const std::string& service_path) { | 3273 const std::string& service_path) { |
3140 PropertyChangeMonitorMap::iterator iter = | 3274 NetworkPropertiesMonitorMap::iterator iter = |
3141 montitored_networks_.find(service_path); | 3275 montitored_networks_.find(service_path); |
3142 if (iter != montitored_networks_.end()) { | 3276 if (iter != montitored_networks_.end()) { |
3143 chromeos::DisconnectPropertyChangeMonitor(iter->second); | 3277 chromeos::DisconnectNetworkPropertiesMonitor(iter->second); |
3144 montitored_networks_.erase(iter); | 3278 montitored_networks_.erase(iter); |
3145 } | 3279 } |
3146 } | 3280 } |
3147 | 3281 |
3148 void NetworkLibraryImplCros::MonitorNetworkDeviceStart( | 3282 void NetworkLibraryImplCros::MonitorNetworkDeviceStart( |
3149 const std::string& device_path) { | 3283 const std::string& device_path) { |
3150 if (montitored_devices_.find(device_path) == montitored_devices_.end()) { | 3284 if (montitored_devices_.find(device_path) == montitored_devices_.end()) { |
3151 chromeos::PropertyChangeMonitor monitor = | 3285 chromeos::NetworkPropertiesMonitor monitor = |
3152 chromeos::MonitorNetworkDevice(&NetworkDevicePropertyChangedHandler, | 3286 chromeos::MonitorNetworkDeviceProperties( |
3153 device_path.c_str(), | 3287 &NetworkDevicePropertyChangedHandler, device_path.c_str(), this); |
3154 this); | |
3155 montitored_devices_[device_path] = monitor; | 3288 montitored_devices_[device_path] = monitor; |
3156 } | 3289 } |
3157 } | 3290 } |
3158 | 3291 |
3159 void NetworkLibraryImplCros::MonitorNetworkDeviceStop( | 3292 void NetworkLibraryImplCros::MonitorNetworkDeviceStop( |
3160 const std::string& device_path) { | 3293 const std::string& device_path) { |
3161 PropertyChangeMonitorMap::iterator iter = | 3294 NetworkPropertiesMonitorMap::iterator iter = |
3162 montitored_devices_.find(device_path); | 3295 montitored_devices_.find(device_path); |
3163 if (iter != montitored_devices_.end()) { | 3296 if (iter != montitored_devices_.end()) { |
3164 chromeos::DisconnectPropertyChangeMonitor(iter->second); | 3297 chromeos::DisconnectNetworkPropertiesMonitor(iter->second); |
3165 montitored_devices_.erase(iter); | 3298 montitored_devices_.erase(iter); |
3166 } | 3299 } |
3167 } | 3300 } |
3168 | 3301 |
3169 // static callback | 3302 // static callback |
3170 void NetworkLibraryImplCros::NetworkStatusChangedHandler( | 3303 void NetworkLibraryImplCros::NetworkStatusChangedHandler( |
3171 void* object, const char* path, const char* key, const Value* value) { | 3304 void* object, const char* path, const char* key, const GValue* gvalue) { |
3172 NetworkLibraryImplCros* networklib = | 3305 NetworkLibraryImplCros* networklib = |
3173 static_cast<NetworkLibraryImplCros*>(object); | 3306 static_cast<NetworkLibraryImplCros*>(object); |
3174 DCHECK(networklib); | 3307 DCHECK(networklib); |
3175 if (key == NULL || value == NULL || path == NULL || object == NULL) | 3308 if (key == NULL || gvalue == NULL || path == NULL || object == NULL) |
3176 return; | 3309 return; |
3310 scoped_ptr<Value> value(ConvertGlibValue(gvalue)); | |
3177 networklib->UpdateNetworkStatus(std::string(path), std::string(key), *value); | 3311 networklib->UpdateNetworkStatus(std::string(path), std::string(key), *value); |
3178 } | 3312 } |
3179 | 3313 |
3180 void NetworkLibraryImplCros::UpdateNetworkStatus( | 3314 void NetworkLibraryImplCros::UpdateNetworkStatus( |
3181 const std::string& path, const std::string& key, const Value& value) { | 3315 const std::string& path, const std::string& key, const Value& value) { |
3182 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3316 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3183 Network* network = FindNetworkByPath(path); | 3317 Network* network = FindNetworkByPath(path); |
3184 if (network) { | 3318 if (network) { |
3185 VLOG(2) << "UpdateNetworkStatus: " << network->name() << "." << key; | 3319 VLOG(2) << "UpdateNetworkStatus: " << network->name() << "." << key; |
3186 bool prev_connected = network->connected(); | 3320 bool prev_connected = network->connected(); |
3187 if (!network->UpdateStatus(key, value, NULL)) { | 3321 if (!network->UpdateStatus(key, value, NULL)) { |
3188 LOG(WARNING) << "UpdateNetworkStatus: Error updating: " | 3322 LOG(WARNING) << "UpdateNetworkStatus: Error updating: " |
3189 << path << "." << key; | 3323 << path << "." << key; |
3190 } | 3324 } |
3191 // If we just connected, this may have been added to remembered list. | 3325 // If we just connected, this may have been added to remembered list. |
3192 if (!prev_connected && network->connected()) | 3326 if (!prev_connected && network->connected()) |
3193 RequestRememberedNetworksUpdate(); | 3327 RequestRememberedNetworksUpdate(); |
3194 NotifyNetworkChanged(network); | 3328 NotifyNetworkChanged(network); |
3195 // Anything observing the manager needs to know about any service change. | 3329 // Anything observing the manager needs to know about any service change. |
3196 NotifyNetworkManagerChanged(false); // Not forced. | 3330 NotifyNetworkManagerChanged(false); // Not forced. |
3197 } | 3331 } |
3198 } | 3332 } |
3199 | 3333 |
3200 // static callback | 3334 // static callback |
3201 void NetworkLibraryImplCros::NetworkDevicePropertyChangedHandler( | 3335 void NetworkLibraryImplCros::NetworkDevicePropertyChangedHandler( |
3202 void* object, const char* path, const char* key, const Value* value) { | 3336 void* object, const char* path, const char* key, const GValue* gvalue) { |
3203 NetworkLibraryImplCros* networklib = | 3337 NetworkLibraryImplCros* networklib = |
3204 static_cast<NetworkLibraryImplCros*>(object); | 3338 static_cast<NetworkLibraryImplCros*>(object); |
3205 DCHECK(networklib); | 3339 DCHECK(networklib); |
3206 if (key == NULL || value == NULL || path == NULL || object == NULL) | 3340 if (key == NULL || gvalue == NULL || path == NULL || object == NULL) |
3207 return; | 3341 return; |
3342 scoped_ptr<Value> value(ConvertGlibValue(gvalue)); | |
3208 networklib->UpdateNetworkDeviceStatus(std::string(path), | 3343 networklib->UpdateNetworkDeviceStatus(std::string(path), |
3209 std::string(key), | 3344 std::string(key), |
3210 *value); | 3345 *value); |
3211 } | 3346 } |
3212 | 3347 |
3213 void NetworkLibraryImplCros::UpdateNetworkDeviceStatus( | 3348 void NetworkLibraryImplCros::UpdateNetworkDeviceStatus( |
3214 const std::string& path, const std::string& key, const Value& value) { | 3349 const std::string& path, const std::string& key, const Value& value) { |
3215 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3350 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3216 NetworkDevice* device = FindNetworkDeviceByPath(path); | 3351 NetworkDevice* device = FindNetworkDeviceByPath(path); |
3217 if (device) { | 3352 if (device) { |
(...skipping 14 matching lines...) Expand all Loading... | |
3232 } | 3367 } |
3233 } | 3368 } |
3234 } else { | 3369 } else { |
3235 VLOG(1) << "UpdateNetworkDeviceStatus: Failed to update: " | 3370 VLOG(1) << "UpdateNetworkDeviceStatus: Failed to update: " |
3236 << path << "." << key; | 3371 << path << "." << key; |
3237 } | 3372 } |
3238 // Notify only observers on device property change. | 3373 // Notify only observers on device property change. |
3239 NotifyNetworkDeviceChanged(device, index); | 3374 NotifyNetworkDeviceChanged(device, index); |
3240 // If a device's power state changes, new properties may become defined. | 3375 // If a device's power state changes, new properties may become defined. |
3241 if (index == PROPERTY_INDEX_POWERED) | 3376 if (index == PROPERTY_INDEX_POWERED) |
3242 chromeos::RequestNetworkDeviceInfo(path.c_str(), | 3377 chromeos::RequestNetworkDeviceProperties(path.c_str(), |
3243 &NetworkDeviceUpdate, | 3378 &NetworkDeviceUpdate, |
3244 this); | 3379 this); |
3245 } | 3380 } |
3246 } | 3381 } |
3247 | 3382 |
3248 ///////////////////////////////////////////////////////////////////////////// | 3383 ///////////////////////////////////////////////////////////////////////////// |
3249 // NetworkLibraryImplBase connect implementation. | 3384 // NetworkLibraryImplBase connect implementation. |
3250 | 3385 |
3251 // static callback | 3386 // static callback |
3252 void NetworkLibraryImplCros::NetworkConnectCallback( | 3387 void NetworkLibraryImplCros::NetworkConnectCallback( |
3253 void* object, | 3388 void* object, |
3254 const char* service_path, | 3389 const char* service_path, |
(...skipping 24 matching lines...) Expand all Loading... | |
3279 } | 3414 } |
3280 | 3415 |
3281 void NetworkLibraryImplCros::CallConnectToNetwork(Network* network) { | 3416 void NetworkLibraryImplCros::CallConnectToNetwork(Network* network) { |
3282 DCHECK(network); | 3417 DCHECK(network); |
3283 chromeos::RequestNetworkServiceConnect(network->service_path().c_str(), | 3418 chromeos::RequestNetworkServiceConnect(network->service_path().c_str(), |
3284 NetworkConnectCallback, this); | 3419 NetworkConnectCallback, this); |
3285 } | 3420 } |
3286 | 3421 |
3287 // static callback | 3422 // static callback |
3288 void NetworkLibraryImplCros::WifiServiceUpdateAndConnect( | 3423 void NetworkLibraryImplCros::WifiServiceUpdateAndConnect( |
3289 void* object, const char* service_path, const Value* info) { | 3424 void* object, const char* service_path, GHashTable* ghash) { |
3290 NetworkLibraryImplCros* networklib = | 3425 NetworkLibraryImplCros* networklib = |
3291 static_cast<NetworkLibraryImplCros*>(object); | 3426 static_cast<NetworkLibraryImplCros*>(object); |
3292 DCHECK(networklib); | 3427 DCHECK(networklib); |
3293 if (service_path && info) { | 3428 if (service_path && ghash) { |
3294 DCHECK_EQ(info->GetType(), Value::TYPE_DICTIONARY); | 3429 scoped_ptr<DictionaryValue> dict(ConvertGHashTable(ghash)); |
3295 const DictionaryValue* dict = static_cast<const DictionaryValue*>(info); | |
3296 Network* network = | 3430 Network* network = |
3297 networklib->ParseNetwork(std::string(service_path), *dict); | 3431 networklib->ParseNetwork(std::string(service_path), *(dict.get())); |
3298 DCHECK_EQ(network->type(), TYPE_WIFI); | 3432 DCHECK_EQ(network->type(), TYPE_WIFI); |
3299 networklib->ConnectToWifiNetworkUsingConnectData( | 3433 networklib->ConnectToWifiNetworkUsingConnectData( |
3300 static_cast<WifiNetwork*>(network)); | 3434 static_cast<WifiNetwork*>(network)); |
3301 } | 3435 } |
3302 } | 3436 } |
3303 | 3437 |
3304 void NetworkLibraryImplCros::CallRequestWifiNetworkAndConnect( | 3438 void NetworkLibraryImplCros::CallRequestWifiNetworkAndConnect( |
3305 const std::string& ssid, ConnectionSecurity security) { | 3439 const std::string& ssid, ConnectionSecurity security) { |
3306 // Asynchronously request service properties and call | 3440 // Asynchronously request service properties and call |
3307 // WifiServiceUpdateAndConnect. | 3441 // WifiServiceUpdateAndConnect. |
3308 chromeos::RequestHiddenWifiNetwork(ssid.c_str(), | 3442 chromeos::RequestHiddenWifiNetworkProperties( |
3309 SecurityToString(security), | 3443 ssid.c_str(), |
3310 WifiServiceUpdateAndConnect, | 3444 SecurityToString(security), |
3311 this); | 3445 WifiServiceUpdateAndConnect, |
3446 this); | |
3312 } | 3447 } |
3313 | 3448 |
3314 // static callback | 3449 // static callback |
3315 void NetworkLibraryImplCros::VPNServiceUpdateAndConnect( | 3450 void NetworkLibraryImplCros::VPNServiceUpdateAndConnect( |
3316 void* object, const char* service_path, const Value* info) { | 3451 void* object, const char* service_path, GHashTable* ghash) { |
3317 NetworkLibraryImplCros* networklib = | 3452 NetworkLibraryImplCros* networklib = |
3318 static_cast<NetworkLibraryImplCros*>(object); | 3453 static_cast<NetworkLibraryImplCros*>(object); |
3319 DCHECK(networklib); | 3454 DCHECK(networklib); |
3320 if (service_path && info) { | 3455 if (service_path && ghash) { |
3321 VLOG(1) << "Connecting to new VPN Service: " << service_path; | 3456 VLOG(1) << "Connecting to new VPN Service: " << service_path; |
3322 DCHECK_EQ(info->GetType(), Value::TYPE_DICTIONARY); | 3457 scoped_ptr<DictionaryValue> dict(ConvertGHashTable(ghash)); |
3323 const DictionaryValue* dict = static_cast<const DictionaryValue*>(info); | |
3324 Network* network = | 3458 Network* network = |
3325 networklib->ParseNetwork(std::string(service_path), *dict); | 3459 networklib->ParseNetwork(std::string(service_path), *(dict.get())); |
3326 DCHECK_EQ(network->type(), TYPE_VPN); | 3460 DCHECK_EQ(network->type(), TYPE_VPN); |
3327 networklib->ConnectToVirtualNetworkUsingConnectData( | 3461 networklib->ConnectToVirtualNetworkUsingConnectData( |
3328 static_cast<VirtualNetwork*>(network)); | 3462 static_cast<VirtualNetwork*>(network)); |
3329 } else { | 3463 } else { |
3330 LOG(WARNING) << "Unable to create VPN Service: " << service_path; | 3464 LOG(WARNING) << "Unable to create VPN Service: " << service_path; |
3331 } | 3465 } |
3332 } | 3466 } |
3333 | 3467 |
3334 void NetworkLibraryImplCros::CallRequestVirtualNetworkAndConnect( | 3468 void NetworkLibraryImplCros::CallRequestVirtualNetworkAndConnect( |
3335 const std::string& service_name, | 3469 const std::string& service_name, |
3336 const std::string& server_hostname, | 3470 const std::string& server_hostname, |
3337 ProviderType provider_type) { | 3471 ProviderType provider_type) { |
3338 chromeos::RequestVirtualNetwork(service_name.c_str(), | 3472 chromeos::RequestVirtualNetworkProperties( |
3339 server_hostname.c_str(), | 3473 service_name.c_str(), |
3340 ProviderTypeToString(provider_type), | 3474 server_hostname.c_str(), |
3341 VPNServiceUpdateAndConnect, | 3475 ProviderTypeToString(provider_type), |
3342 this); | 3476 VPNServiceUpdateAndConnect, |
3477 this); | |
3343 } | 3478 } |
3344 | 3479 |
3345 void NetworkLibraryImplCros::CallDeleteRememberedNetwork( | 3480 void NetworkLibraryImplCros::CallDeleteRememberedNetwork( |
3346 const std::string& profile_path, | 3481 const std::string& profile_path, |
3347 const std::string& service_path) { | 3482 const std::string& service_path) { |
3348 chromeos::DeleteServiceFromProfile( | 3483 chromeos::DeleteServiceFromProfile( |
3349 profile_path.c_str(), service_path.c_str()); | 3484 profile_path.c_str(), service_path.c_str()); |
3350 } | 3485 } |
3351 | 3486 |
3352 ////////////////////////////////////////////////////////////////////////////// | 3487 ////////////////////////////////////////////////////////////////////////////// |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3475 // but not UI doesn't assume such notification so just ignore result. | 3610 // but not UI doesn't assume such notification so just ignore result. |
3476 } | 3611 } |
3477 | 3612 |
3478 void NetworkLibraryImplCros::SetCellularDataRoamingAllowed(bool new_value) { | 3613 void NetworkLibraryImplCros::SetCellularDataRoamingAllowed(bool new_value) { |
3479 const NetworkDevice* cellular = FindCellularDevice(); | 3614 const NetworkDevice* cellular = FindCellularDevice(); |
3480 if (!cellular) { | 3615 if (!cellular) { |
3481 NOTREACHED() << "Calling SetCellularDataRoamingAllowed method " | 3616 NOTREACHED() << "Calling SetCellularDataRoamingAllowed method " |
3482 "w/o cellular device."; | 3617 "w/o cellular device."; |
3483 return; | 3618 return; |
3484 } | 3619 } |
3485 scoped_ptr<Value> value(Value::CreateBooleanValue(new_value)); | 3620 scoped_ptr<GValue> gvalue(ConvertBoolToGValue(new_value)); |
3486 chromeos::SetNetworkDeviceProperty(cellular->device_path().c_str(), | 3621 chromeos::SetNetworkDevicePropertyGValue(cellular->device_path().c_str(), |
3487 kCellularAllowRoamingProperty, | 3622 kCellularAllowRoamingProperty, |
3488 value.get()); | 3623 gvalue.get()); |
3489 } | 3624 } |
3490 | 3625 |
3491 bool NetworkLibraryImplCros::IsCellularAlwaysInRoaming() { | 3626 bool NetworkLibraryImplCros::IsCellularAlwaysInRoaming() { |
3492 const NetworkDevice* cellular = FindCellularDevice(); | 3627 const NetworkDevice* cellular = FindCellularDevice(); |
3493 if (!cellular) { | 3628 if (!cellular) { |
3494 NOTREACHED() << "Calling IsCellularAlwaysInRoaming method " | 3629 NOTREACHED() << "Calling IsCellularAlwaysInRoaming method " |
3495 "w/o cellular device."; | 3630 "w/o cellular device."; |
3496 return false; | 3631 return false; |
3497 } | 3632 } |
3498 const std::string& home_provider_name = cellular->home_provider_name(); | 3633 const std::string& home_provider_name = cellular->home_provider_name(); |
3499 for (size_t i = 0; i < arraysize(kAlwaysInRoamingOperators); i++) { | 3634 for (size_t i = 0; i < arraysize(kAlwaysInRoamingOperators); i++) { |
3500 if (home_provider_name == kAlwaysInRoamingOperators[i]) | 3635 if (home_provider_name == kAlwaysInRoamingOperators[i]) |
3501 return true; | 3636 return true; |
3502 } | 3637 } |
3503 return false; | 3638 return false; |
3504 } | 3639 } |
3505 | 3640 |
3506 void NetworkLibraryImplCros::RequestNetworkScan() { | 3641 void NetworkLibraryImplCros::RequestNetworkScan() { |
3507 if (wifi_enabled()) { | 3642 if (wifi_enabled()) { |
3508 wifi_scanning_ = true; // Cleared when updates are received. | 3643 wifi_scanning_ = true; // Cleared when updates are received. |
3509 chromeos::RequestNetworkScan(kTypeWifi); | 3644 chromeos::RequestNetworkScan(kTypeWifi); |
3510 } | 3645 } |
3511 if (cellular_network()) | 3646 if (cellular_network()) |
3512 cellular_network()->RefreshDataPlansIfNeeded(); | 3647 cellular_network()->RefreshDataPlansIfNeeded(); |
3513 // Make sure all Manager info is up to date. This will also update | 3648 // Make sure all Manager info is up to date. This will also update |
3514 // remembered networks and visible services. | 3649 // remembered networks and visible services. |
3515 chromeos::RequestNetworkManagerInfo(&NetworkManagerUpdate, this); | 3650 chromeos::RequestNetworkManagerProperties(&NetworkManagerUpdate, this); |
3516 } | 3651 } |
3517 | 3652 |
3518 bool NetworkLibraryImplCros::GetWifiAccessPoints( | 3653 bool NetworkLibraryImplCros::GetWifiAccessPoints( |
3519 WifiAccessPointVector* result) { | 3654 WifiAccessPointVector* result) { |
3520 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3655 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3521 DeviceNetworkList* network_list = chromeos::GetDeviceNetworkList(); | 3656 DeviceNetworkList* network_list = chromeos::GetDeviceNetworkList(); |
3522 if (network_list == NULL) | 3657 if (network_list == NULL) |
3523 return false; | 3658 return false; |
3524 result->clear(); | 3659 result->clear(); |
3525 result->reserve(network_list->network_size); | 3660 result->reserve(network_list->network_size); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3636 if (ipconfig_status2) { | 3771 if (ipconfig_status2) { |
3637 for (int i = 0; i < ipconfig_status2->size; ++i) { | 3772 for (int i = 0; i < ipconfig_status2->size; ++i) { |
3638 if (ipconfig_status2->ips[i].type == chromeos::IPCONFIG_TYPE_IPV4) | 3773 if (ipconfig_status2->ips[i].type == chromeos::IPCONFIG_TYPE_IPV4) |
3639 ipconfig_static = &ipconfig_status2->ips[i]; | 3774 ipconfig_static = &ipconfig_status2->ips[i]; |
3640 } | 3775 } |
3641 } | 3776 } |
3642 } | 3777 } |
3643 if (ipconfig_static) { | 3778 if (ipconfig_static) { |
3644 // Save any changed details. | 3779 // Save any changed details. |
3645 if (ipconfig.address != ipconfig_static->address) { | 3780 if (ipconfig.address != ipconfig_static->address) { |
3646 scoped_ptr<Value> value(Value::CreateStringValue(ipconfig.address)); | 3781 scoped_ptr<GValue> gvalue(ConvertStringToGValue(ipconfig.address)); |
3647 chromeos::SetNetworkIPConfigProperty(ipconfig_static->path, | 3782 chromeos::SetNetworkIPConfigPropertyGValue( |
3648 kAddressProperty, | 3783 ipconfig_static->path, kAddressProperty, gvalue.get()); |
3649 value.get()); | |
3650 } | 3784 } |
3651 if (ipconfig.netmask != ipconfig_static->netmask) { | 3785 if (ipconfig.netmask != ipconfig_static->netmask) { |
3652 int32 prefixlen = ipconfig.GetPrefixLength(); | 3786 int prefixlen = static_cast<int>(ipconfig.GetPrefixLength()); |
tony
2011/08/29 17:01:22
int32 and int are the same (see the typedef in bas
stevenjb
2011/08/29 20:36:31
It isn't, since int is 32 bits on all modern compi
| |
3653 if (prefixlen == -1) { | 3787 if (prefixlen == -1) { |
3654 VLOG(1) << "IP config prefixlen is invalid for netmask " | 3788 VLOG(1) << "IP config prefixlen is invalid for netmask " |
3655 << ipconfig.netmask; | 3789 << ipconfig.netmask; |
3656 } else { | 3790 } else { |
3657 scoped_ptr<Value> value(Value::CreateIntegerValue(prefixlen)); | 3791 scoped_ptr<GValue> gvalue(ConvertIntToGValue(prefixlen)); |
3658 chromeos::SetNetworkIPConfigProperty(ipconfig_static->path, | 3792 chromeos::SetNetworkIPConfigPropertyGValue( |
3659 kPrefixlenProperty, | 3793 ipconfig_static->path, kPrefixlenProperty, gvalue.get()); |
3660 value.get()); | |
3661 } | 3794 } |
3662 } | 3795 } |
3663 if (ipconfig.gateway != ipconfig_static->gateway) { | 3796 if (ipconfig.gateway != ipconfig_static->gateway) { |
3664 scoped_ptr<Value> value(Value::CreateStringValue(ipconfig.gateway)); | 3797 scoped_ptr<GValue> gvalue(ConvertStringToGValue(ipconfig.gateway)); |
3665 chromeos::SetNetworkIPConfigProperty(ipconfig_static->path, | 3798 chromeos::SetNetworkIPConfigPropertyGValue( |
3666 kGatewayProperty, | 3799 ipconfig_static->path, kGatewayProperty, gvalue.get()); |
3667 value.get()); | |
3668 } | 3800 } |
3669 if (ipconfig.name_servers != ipconfig_static->name_servers) { | 3801 if (ipconfig.name_servers != ipconfig_static->name_servers) { |
3670 scoped_ptr<Value> value( | 3802 scoped_ptr<GValue> gvalue(ConvertStringToGValue(ipconfig.name_servers)); |
3671 Value::CreateStringValue(ipconfig.name_servers)); | 3803 chromeos::SetNetworkIPConfigPropertyGValue( |
3672 chromeos::SetNetworkIPConfigProperty(ipconfig_static->path, | 3804 ipconfig_static->path, kNameServersProperty, gvalue.get()); |
3673 kNameServersProperty, | |
3674 value.get()); | |
3675 } | 3805 } |
3676 // Remove dhcp ip config if there is one. | 3806 // Remove dhcp ip config if there is one. |
3677 if (ipconfig_dhcp) | 3807 if (ipconfig_dhcp) |
3678 chromeos::RemoveIPConfig(ipconfig_dhcp); | 3808 chromeos::RemoveIPConfig(ipconfig_dhcp); |
3679 } | 3809 } |
3680 } | 3810 } |
3681 | 3811 |
3682 if (ipconfig_status) | 3812 if (ipconfig_status) |
3683 chromeos::FreeIPConfigStatus(ipconfig_status); | 3813 chromeos::FreeIPConfigStatus(ipconfig_status); |
3684 if (ipconfig_status2) | 3814 if (ipconfig_status2) |
3685 chromeos::FreeIPConfigStatus(ipconfig_status2); | 3815 chromeos::FreeIPConfigStatus(ipconfig_status2); |
3686 } | 3816 } |
3687 | 3817 |
3688 ///////////////////////////////////////////////////////////////////////////// | 3818 ///////////////////////////////////////////////////////////////////////////// |
3689 // Network Manager functions. | 3819 // Network Manager functions. |
3690 | 3820 |
3691 // static | 3821 // static |
3692 void NetworkLibraryImplCros::NetworkManagerStatusChangedHandler( | 3822 void NetworkLibraryImplCros::NetworkManagerStatusChangedHandler( |
3693 void* object, const char* path, const char* key, const Value* value) { | 3823 void* object, const char* path, const char* key, const GValue* gvalue) { |
3694 NetworkLibraryImplCros* networklib = | 3824 NetworkLibraryImplCros* networklib = |
3695 static_cast<NetworkLibraryImplCros*>(object); | 3825 static_cast<NetworkLibraryImplCros*>(object); |
3696 DCHECK(networklib); | 3826 DCHECK(networklib); |
3697 networklib->NetworkManagerStatusChanged(key, value); | 3827 scoped_ptr<Value> value(ConvertGlibValue(gvalue)); |
3828 networklib->NetworkManagerStatusChanged(key, value.get()); | |
3698 } | 3829 } |
3699 | 3830 |
3700 // This processes all Manager update messages. | 3831 // This processes all Manager update messages. |
3701 void NetworkLibraryImplCros::NetworkManagerStatusChanged( | 3832 void NetworkLibraryImplCros::NetworkManagerStatusChanged( |
3702 const char* key, const Value* value) { | 3833 const char* key, const Value* value) { |
3703 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3834 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3704 base::TimeTicks start = base::TimeTicks::Now(); | 3835 base::TimeTicks start = base::TimeTicks::Now(); |
3705 if (!key) | 3836 if (!key) |
3706 return; | 3837 return; |
3707 VLOG(1) << "NetworkManagerStatusChanged: KEY=" << key; | 3838 VLOG(1) << "NetworkManagerStatusChanged: KEY=" << key; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3783 break; | 3914 break; |
3784 } | 3915 } |
3785 base::TimeDelta delta = base::TimeTicks::Now() - start; | 3916 base::TimeDelta delta = base::TimeTicks::Now() - start; |
3786 VLOG(2) << "NetworkManagerStatusChanged: time: " | 3917 VLOG(2) << "NetworkManagerStatusChanged: time: " |
3787 << delta.InMilliseconds() << " ms."; | 3918 << delta.InMilliseconds() << " ms."; |
3788 HISTOGRAM_TIMES("CROS_NETWORK_UPDATE", delta); | 3919 HISTOGRAM_TIMES("CROS_NETWORK_UPDATE", delta); |
3789 } | 3920 } |
3790 | 3921 |
3791 // static | 3922 // static |
3792 void NetworkLibraryImplCros::NetworkManagerUpdate( | 3923 void NetworkLibraryImplCros::NetworkManagerUpdate( |
3793 void* object, const char* manager_path, const Value* info) { | 3924 void* object, const char* manager_path, GHashTable* ghash) { |
3794 NetworkLibraryImplCros* networklib = | 3925 NetworkLibraryImplCros* networklib = |
3795 static_cast<NetworkLibraryImplCros*>(object); | 3926 static_cast<NetworkLibraryImplCros*>(object); |
3796 DCHECK(networklib); | 3927 DCHECK(networklib); |
3797 if (!info) { | 3928 if (!ghash) { |
3798 LOG(ERROR) << "Error retrieving manager properties: " << manager_path; | 3929 LOG(ERROR) << "Error retrieving manager properties: " << manager_path; |
3799 return; | 3930 return; |
3800 } | 3931 } |
3801 VLOG(1) << "Received NetworkManagerUpdate."; | 3932 VLOG(1) << "Received NetworkManagerUpdate."; |
3802 DCHECK_EQ(info->GetType(), Value::TYPE_DICTIONARY); | 3933 scoped_ptr<DictionaryValue> dict(ConvertGHashTable(ghash)); |
3803 const DictionaryValue* dict = static_cast<const DictionaryValue*>(info); | 3934 networklib->ParseNetworkManager(*(dict.get())); |
3804 networklib->ParseNetworkManager(*dict); | |
3805 } | 3935 } |
3806 | 3936 |
3807 void NetworkLibraryImplCros::ParseNetworkManager(const DictionaryValue& dict) { | 3937 void NetworkLibraryImplCros::ParseNetworkManager(const DictionaryValue& dict) { |
3808 for (DictionaryValue::key_iterator iter = dict.begin_keys(); | 3938 for (DictionaryValue::key_iterator iter = dict.begin_keys(); |
3809 iter != dict.end_keys(); ++iter) { | 3939 iter != dict.end_keys(); ++iter) { |
3810 const std::string& key = *iter; | 3940 const std::string& key = *iter; |
3811 Value* value; | 3941 Value* value; |
3812 bool res = dict.GetWithoutPathExpansion(key, &value); | 3942 bool res = dict.GetWithoutPathExpansion(key, &value); |
3813 CHECK(res); | 3943 CHECK(res); |
3814 NetworkManagerStatusChanged(key.c_str(), value); | 3944 NetworkManagerStatusChanged(key.c_str(), value); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3907 AddNetwork(found->second); | 4037 AddNetwork(found->second); |
3908 old_network_map.erase(found); | 4038 old_network_map.erase(found); |
3909 } | 4039 } |
3910 // Always request network updates. | 4040 // Always request network updates. |
3911 // TODO(stevenjb): Investigate why we are missing updates then | 4041 // TODO(stevenjb): Investigate why we are missing updates then |
3912 // rely on watched network updates and only request updates here for | 4042 // rely on watched network updates and only request updates here for |
3913 // new networks. | 4043 // new networks. |
3914 // Use update_request map to store network priority. | 4044 // Use update_request map to store network priority. |
3915 network_update_requests_[service_path] = network_priority_order++; | 4045 network_update_requests_[service_path] = network_priority_order++; |
3916 wifi_scanning_ = true; | 4046 wifi_scanning_ = true; |
3917 chromeos::RequestNetworkServiceInfo(service_path.c_str(), | 4047 chromeos::RequestNetworkServiceProperties(service_path.c_str(), |
3918 &NetworkServiceUpdate, | 4048 &NetworkServiceUpdate, |
3919 this); | 4049 this); |
3920 } | 4050 } |
3921 } | 4051 } |
3922 // Iterate through list of remaining networks that are no longer in the | 4052 // Iterate through list of remaining networks that are no longer in the |
3923 // list and delete them or update their status and re-add them to the list. | 4053 // list and delete them or update their status and re-add them to the list. |
3924 for (NetworkMap::iterator iter = old_network_map.begin(); | 4054 for (NetworkMap::iterator iter = old_network_map.begin(); |
3925 iter != old_network_map.end(); ++iter) { | 4055 iter != old_network_map.end(); ++iter) { |
3926 Network* network = iter->second; | 4056 Network* network = iter->second; |
3927 VLOG(2) << "Delete Network: " << network->name() | 4057 VLOG(2) << "Delete Network: " << network->name() |
3928 << " State = " << network->GetStateString() | 4058 << " State = " << network->GetStateString() |
3929 << " connecting = " << network->connecting() | 4059 << " connecting = " << network->connecting() |
(...skipping 22 matching lines...) Expand all Loading... | |
3952 // Existing networks will be updated. There should not be any new networks | 4082 // Existing networks will be updated. There should not be any new networks |
3953 // in this list, but if there are they will be added appropriately. | 4083 // in this list, but if there are they will be added appropriately. |
3954 void NetworkLibraryImplCros::UpdateWatchedNetworkServiceList( | 4084 void NetworkLibraryImplCros::UpdateWatchedNetworkServiceList( |
3955 const ListValue* services) { | 4085 const ListValue* services) { |
3956 for (ListValue::const_iterator iter = services->begin(); | 4086 for (ListValue::const_iterator iter = services->begin(); |
3957 iter != services->end(); ++iter) { | 4087 iter != services->end(); ++iter) { |
3958 std::string service_path; | 4088 std::string service_path; |
3959 (*iter)->GetAsString(&service_path); | 4089 (*iter)->GetAsString(&service_path); |
3960 if (!service_path.empty()) { | 4090 if (!service_path.empty()) { |
3961 VLOG(1) << "Watched Service: " << service_path; | 4091 VLOG(1) << "Watched Service: " << service_path; |
3962 chromeos::RequestNetworkServiceInfo(service_path.c_str(), | 4092 chromeos::RequestNetworkServiceProperties(service_path.c_str(), |
3963 &NetworkServiceUpdate, | 4093 &NetworkServiceUpdate, |
3964 this); | 4094 this); |
3965 } | 4095 } |
3966 } | 4096 } |
3967 } | 4097 } |
3968 | 4098 |
3969 // static | 4099 // static |
3970 void NetworkLibraryImplCros::NetworkServiceUpdate( | 4100 void NetworkLibraryImplCros::NetworkServiceUpdate( |
3971 void* object, const char* service_path, const Value* info) { | 4101 void* object, const char* service_path, GHashTable* ghash) { |
3972 NetworkLibraryImplCros* networklib = | 4102 NetworkLibraryImplCros* networklib = |
3973 static_cast<NetworkLibraryImplCros*>(object); | 4103 static_cast<NetworkLibraryImplCros*>(object); |
3974 DCHECK(networklib); | 4104 DCHECK(networklib); |
3975 if (service_path) { | 4105 if (service_path) { |
3976 if (!info) | 4106 if (!ghash) |
3977 return; // Network no longer in visible list, ignore. | 4107 return; // Network no longer in visible list, ignore. |
3978 DCHECK_EQ(info->GetType(), Value::TYPE_DICTIONARY); | 4108 scoped_ptr<DictionaryValue> dict(ConvertGHashTable(ghash)); |
3979 const DictionaryValue* dict = static_cast<const DictionaryValue*>(info); | 4109 networklib->ParseNetwork(std::string(service_path), *(dict.get())); |
3980 networklib->ParseNetwork(std::string(service_path), *dict); | |
3981 } | 4110 } |
3982 } | 4111 } |
3983 | 4112 |
3984 // Called from NetworkServiceUpdate and WifiServiceUpdateAndConnect. | 4113 // Called from NetworkServiceUpdate and WifiServiceUpdateAndConnect. |
3985 Network* NetworkLibraryImplCros::ParseNetwork( | 4114 Network* NetworkLibraryImplCros::ParseNetwork( |
3986 const std::string& service_path, const DictionaryValue& info) { | 4115 const std::string& service_path, const DictionaryValue& info) { |
3987 Network* network = FindNetworkByPath(service_path); | 4116 Network* network = FindNetworkByPath(service_path); |
3988 if (!network) { | 4117 if (!network) { |
3989 NativeNetworkParser parser; | 4118 NativeNetworkParser parser; |
3990 network = parser.CreateNetworkFromInfo(service_path, info); | 4119 network = parser.CreateNetworkFromInfo(service_path, info); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4063 network->SetProfilePath(profile_path); | 4192 network->SetProfilePath(profile_path); |
4064 } | 4193 } |
4065 user_networks_.clear(); | 4194 user_networks_.clear(); |
4066 } | 4195 } |
4067 } | 4196 } |
4068 } | 4197 } |
4069 | 4198 |
4070 void NetworkLibraryImplCros::RequestRememberedNetworksUpdate() { | 4199 void NetworkLibraryImplCros::RequestRememberedNetworksUpdate() { |
4071 VLOG(1) << "RequestRememberedNetworksUpdate"; | 4200 VLOG(1) << "RequestRememberedNetworksUpdate"; |
4072 // Delete all remembered networks. We delete them because | 4201 // Delete all remembered networks. We delete them because |
4073 // RequestNetworkProfile is asynchronous and may invoke | 4202 // RequestNetworkProfileProperties is asynchronous and may invoke |
4074 // UpdateRememberedServiceList multiple times (once per profile). | 4203 // UpdateRememberedServiceList multiple times (once per profile). |
4075 // We can do this safely because we do not save any local state for | 4204 // We can do this safely because we do not save any local state for |
4076 // remembered networks. This list updates infrequently. | 4205 // remembered networks. This list updates infrequently. |
4077 DeleteRememberedNetworks(); | 4206 DeleteRememberedNetworks(); |
4078 // Request remembered networks from each profile. Later entries will | 4207 // Request remembered networks from each profile. Later entries will |
4079 // override earlier entries, so default/local entries will override | 4208 // override earlier entries, so default/local entries will override |
4080 // user entries (as desired). | 4209 // user entries (as desired). |
4081 for (NetworkProfileList::iterator iter = profile_list_.begin(); | 4210 for (NetworkProfileList::iterator iter = profile_list_.begin(); |
4082 iter != profile_list_.end(); ++iter) { | 4211 iter != profile_list_.end(); ++iter) { |
4083 NetworkProfile& profile = *iter; | 4212 NetworkProfile& profile = *iter; |
4084 VLOG(1) << " Requesting Profile: " << profile.path; | 4213 VLOG(1) << " Requesting Profile: " << profile.path; |
4085 chromeos::RequestNetworkProfile( | 4214 chromeos::RequestNetworkProfileProperties( |
4086 profile.path.c_str(), &ProfileUpdate, this); | 4215 profile.path.c_str(), &ProfileUpdate, this); |
4087 } | 4216 } |
4088 } | 4217 } |
4089 | 4218 |
4090 // static | 4219 // static |
4091 void NetworkLibraryImplCros::ProfileUpdate( | 4220 void NetworkLibraryImplCros::ProfileUpdate( |
4092 void* object, const char* profile_path, const Value* info) { | 4221 void* object, const char* profile_path, GHashTable* ghash) { |
4093 NetworkLibraryImplCros* networklib = | 4222 NetworkLibraryImplCros* networklib = |
4094 static_cast<NetworkLibraryImplCros*>(object); | 4223 static_cast<NetworkLibraryImplCros*>(object); |
4095 DCHECK(networklib); | 4224 DCHECK(networklib); |
4096 if (!info) { | 4225 if (!ghash) { |
4097 LOG(ERROR) << "Error retrieving profile: " << profile_path; | 4226 LOG(ERROR) << "Error retrieving profile: " << profile_path; |
4098 return; | 4227 return; |
4099 } | 4228 } |
4100 VLOG(1) << "Received ProfileUpdate for: " << profile_path; | 4229 VLOG(1) << "Received ProfileUpdate for: " << profile_path; |
4101 DCHECK_EQ(info->GetType(), Value::TYPE_DICTIONARY); | 4230 scoped_ptr<DictionaryValue> dict(ConvertGHashTable(ghash)); |
4102 const DictionaryValue* dict = static_cast<const DictionaryValue*>(info); | |
4103 ListValue* entries(NULL); | 4231 ListValue* entries(NULL); |
4104 dict->GetList(kEntriesProperty, &entries); | 4232 dict->GetList(kEntriesProperty, &entries); |
4105 DCHECK(entries); | 4233 DCHECK(entries); |
4106 networklib->UpdateRememberedServiceList(profile_path, entries); | 4234 networklib->UpdateRememberedServiceList(profile_path, entries); |
4107 } | 4235 } |
4108 | 4236 |
4109 void NetworkLibraryImplCros::UpdateRememberedServiceList( | 4237 void NetworkLibraryImplCros::UpdateRememberedServiceList( |
4110 const char* profile_path, const ListValue* profile_entries) { | 4238 const char* profile_path, const ListValue* profile_entries) { |
4111 DCHECK(profile_path); | 4239 DCHECK(profile_path); |
4112 VLOG(1) << "UpdateRememberedServiceList for path: " << profile_path; | 4240 VLOG(1) << "UpdateRememberedServiceList for path: " << profile_path; |
(...skipping 14 matching lines...) Expand all Loading... | |
4127 std::string service_path; | 4255 std::string service_path; |
4128 (*iter2)->GetAsString(&service_path); | 4256 (*iter2)->GetAsString(&service_path); |
4129 if (service_path.empty()) { | 4257 if (service_path.empty()) { |
4130 LOG(WARNING) << "Empty service path in profile."; | 4258 LOG(WARNING) << "Empty service path in profile."; |
4131 continue; | 4259 continue; |
4132 } | 4260 } |
4133 VLOG(1) << " Remembered service: " << service_path; | 4261 VLOG(1) << " Remembered service: " << service_path; |
4134 // Add service to profile list. | 4262 // Add service to profile list. |
4135 profile.services.insert(service_path); | 4263 profile.services.insert(service_path); |
4136 // Request update for remembered network. | 4264 // Request update for remembered network. |
4137 chromeos::RequestNetworkProfileEntry(profile_path, | 4265 chromeos::RequestNetworkProfileEntryProperties( |
4138 service_path.c_str(), | 4266 profile_path, |
4139 &RememberedNetworkServiceUpdate, | 4267 service_path.c_str(), |
4140 this); | 4268 &RememberedNetworkServiceUpdate, |
4269 this); | |
4141 } | 4270 } |
4142 } | 4271 } |
4143 | 4272 |
4144 // static | 4273 // static |
4145 void NetworkLibraryImplCros::RememberedNetworkServiceUpdate( | 4274 void NetworkLibraryImplCros::RememberedNetworkServiceUpdate( |
4146 void* object, const char* service_path, const Value* info) { | 4275 void* object, const char* service_path, GHashTable* ghash) { |
4147 NetworkLibraryImplCros* networklib = | 4276 NetworkLibraryImplCros* networklib = |
4148 static_cast<NetworkLibraryImplCros*>(object); | 4277 static_cast<NetworkLibraryImplCros*>(object); |
4149 DCHECK(networklib); | 4278 DCHECK(networklib); |
4150 if (service_path) { | 4279 if (service_path) { |
4151 if (!info) { | 4280 if (!ghash) { |
4152 // Remembered network no longer exists. | 4281 // Remembered network no longer exists. |
4153 networklib->DeleteRememberedNetwork(std::string(service_path)); | 4282 networklib->DeleteRememberedNetwork(std::string(service_path)); |
4154 } else { | 4283 } else { |
4155 DCHECK_EQ(info->GetType(), Value::TYPE_DICTIONARY); | 4284 scoped_ptr<DictionaryValue> dict(ConvertGHashTable(ghash)); |
4156 const DictionaryValue* dict = static_cast<const DictionaryValue*>(info); | 4285 networklib->ParseRememberedNetwork( |
4157 networklib->ParseRememberedNetwork(std::string(service_path), *dict); | 4286 std::string(service_path), *(dict.get())); |
4158 } | 4287 } |
4159 } | 4288 } |
4160 } | 4289 } |
4161 | 4290 |
4162 // Returns NULL if |service_path| refers to a network that is not a | 4291 // Returns NULL if |service_path| refers to a network that is not a |
4163 // remembered type. Called from RememberedNetworkServiceUpdate. | 4292 // remembered type. Called from RememberedNetworkServiceUpdate. |
4164 Network* NetworkLibraryImplCros::ParseRememberedNetwork( | 4293 Network* NetworkLibraryImplCros::ParseRememberedNetwork( |
4165 const std::string& service_path, const DictionaryValue& info) { | 4294 const std::string& service_path, const DictionaryValue& info) { |
4166 Network* remembered; | 4295 Network* remembered; |
4167 NetworkMap::iterator found = remembered_network_map_.find(service_path); | 4296 NetworkMap::iterator found = remembered_network_map_.find(service_path); |
(...skipping 22 matching lines...) Expand all Loading... | |
4190 | 4319 |
4191 if (remembered->type() == TYPE_VPN) { | 4320 if (remembered->type() == TYPE_VPN) { |
4192 // VPNs are only stored in profiles. If we don't have a network for it, | 4321 // VPNs are only stored in profiles. If we don't have a network for it, |
4193 // request one. | 4322 // request one. |
4194 if (!FindNetworkFromRemembered(remembered)) { | 4323 if (!FindNetworkFromRemembered(remembered)) { |
4195 VirtualNetwork* vpn = static_cast<VirtualNetwork*>(remembered); | 4324 VirtualNetwork* vpn = static_cast<VirtualNetwork*>(remembered); |
4196 std::string provider_type = ProviderTypeToString(vpn->provider_type()); | 4325 std::string provider_type = ProviderTypeToString(vpn->provider_type()); |
4197 VLOG(1) << "Requesting VPN: " << vpn->name() | 4326 VLOG(1) << "Requesting VPN: " << vpn->name() |
4198 << " Server: " << vpn->server_hostname() | 4327 << " Server: " << vpn->server_hostname() |
4199 << " Type: " << provider_type; | 4328 << " Type: " << provider_type; |
4200 chromeos::RequestVirtualNetwork(vpn->name().c_str(), | 4329 chromeos::RequestVirtualNetworkProperties( |
4201 vpn->server_hostname().c_str(), | 4330 vpn->name().c_str(), |
4202 provider_type.c_str(), | 4331 vpn->server_hostname().c_str(), |
4203 NetworkServiceUpdate, | 4332 provider_type.c_str(), |
4204 this); | 4333 NetworkServiceUpdate, |
4334 this); | |
4205 } | 4335 } |
4206 } | 4336 } |
4207 | 4337 |
4208 return remembered; | 4338 return remembered; |
4209 } | 4339 } |
4210 | 4340 |
4211 //////////////////////////////////////////////////////////////////////////// | 4341 //////////////////////////////////////////////////////////////////////////// |
4212 // NetworkDevice list management functions. | 4342 // NetworkDevice list management functions. |
4213 | 4343 |
4214 // Update device list, and request associated device updates. | 4344 // Update device list, and request associated device updates. |
4215 // |devices| represents a complete list of devices. | 4345 // |devices| represents a complete list of devices. |
4216 void NetworkLibraryImplCros::UpdateNetworkDeviceList(const ListValue* devices) { | 4346 void NetworkLibraryImplCros::UpdateNetworkDeviceList(const ListValue* devices) { |
4217 NetworkDeviceMap old_device_map = device_map_; | 4347 NetworkDeviceMap old_device_map = device_map_; |
4218 device_map_.clear(); | 4348 device_map_.clear(); |
4219 VLOG(2) << "Updating Device List."; | 4349 VLOG(2) << "Updating Device List."; |
4220 for (ListValue::const_iterator iter = devices->begin(); | 4350 for (ListValue::const_iterator iter = devices->begin(); |
4221 iter != devices->end(); ++iter) { | 4351 iter != devices->end(); ++iter) { |
4222 std::string device_path; | 4352 std::string device_path; |
4223 (*iter)->GetAsString(&device_path); | 4353 (*iter)->GetAsString(&device_path); |
4224 if (!device_path.empty()) { | 4354 if (!device_path.empty()) { |
4225 NetworkDeviceMap::iterator found = old_device_map.find(device_path); | 4355 NetworkDeviceMap::iterator found = old_device_map.find(device_path); |
4226 if (found != old_device_map.end()) { | 4356 if (found != old_device_map.end()) { |
4227 VLOG(2) << " Adding existing device: " << device_path; | 4357 VLOG(2) << " Adding existing device: " << device_path; |
4228 CHECK(found->second) << "Attempted to add NULL device pointer"; | 4358 CHECK(found->second) << "Attempted to add NULL device pointer"; |
4229 device_map_[device_path] = found->second; | 4359 device_map_[device_path] = found->second; |
4230 old_device_map.erase(found); | 4360 old_device_map.erase(found); |
4231 } | 4361 } |
4232 chromeos::RequestNetworkDeviceInfo(device_path.c_str(), | 4362 chromeos::RequestNetworkDeviceProperties(device_path.c_str(), |
4233 &NetworkDeviceUpdate, | 4363 &NetworkDeviceUpdate, |
4234 this); | 4364 this); |
4235 } | 4365 } |
4236 } | 4366 } |
4237 // Delete any old devices that no longer exist. | 4367 // Delete any old devices that no longer exist. |
4238 for (NetworkDeviceMap::iterator iter = old_device_map.begin(); | 4368 for (NetworkDeviceMap::iterator iter = old_device_map.begin(); |
4239 iter != old_device_map.end(); ++iter) { | 4369 iter != old_device_map.end(); ++iter) { |
4240 DeleteDeviceFromDeviceObserversMap(iter->first); | 4370 DeleteDeviceFromDeviceObserversMap(iter->first); |
4241 // Delete device. | 4371 // Delete device. |
4242 delete iter->second; | 4372 delete iter->second; |
4243 } | 4373 } |
4244 } | 4374 } |
4245 | 4375 |
4246 // static | 4376 // static |
4247 void NetworkLibraryImplCros::NetworkDeviceUpdate( | 4377 void NetworkLibraryImplCros::NetworkDeviceUpdate( |
4248 void* object, const char* device_path, const Value* info) { | 4378 void* object, const char* device_path, GHashTable* ghash) { |
4249 NetworkLibraryImplCros* networklib = | 4379 NetworkLibraryImplCros* networklib = |
4250 static_cast<NetworkLibraryImplCros*>(object); | 4380 static_cast<NetworkLibraryImplCros*>(object); |
4251 DCHECK(networklib); | 4381 DCHECK(networklib); |
4252 if (device_path) { | 4382 if (device_path) { |
4253 if (!info) { | 4383 if (!ghash) { |
4254 // device no longer exists. | 4384 // device no longer exists. |
4255 networklib->DeleteDevice(std::string(device_path)); | 4385 networklib->DeleteDevice(std::string(device_path)); |
4256 } else { | 4386 } else { |
4257 DCHECK_EQ(info->GetType(), Value::TYPE_DICTIONARY); | 4387 scoped_ptr<DictionaryValue> dict(ConvertGHashTable(ghash)); |
4258 const DictionaryValue* dict = static_cast<const DictionaryValue*>(info); | 4388 networklib->ParseNetworkDevice(std::string(device_path), *(dict.get())); |
4259 networklib->ParseNetworkDevice(std::string(device_path), *dict); | |
4260 } | 4389 } |
4261 } | 4390 } |
4262 } | 4391 } |
4263 | 4392 |
4264 void NetworkLibraryImplCros::ParseNetworkDevice(const std::string& device_path, | 4393 void NetworkLibraryImplCros::ParseNetworkDevice(const std::string& device_path, |
4265 const DictionaryValue& info) { | 4394 const DictionaryValue& info) { |
4266 NetworkDeviceMap::iterator found = device_map_.find(device_path); | 4395 NetworkDeviceMap::iterator found = device_map_.find(device_path); |
4267 NetworkDevice* device; | 4396 NetworkDevice* device; |
4268 if (found != device_map_.end()) { | 4397 if (found != device_map_.end()) { |
4269 device = found->second; | 4398 device = found->second; |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4652 return network_library; | 4781 return network_library; |
4653 } | 4782 } |
4654 | 4783 |
4655 ///////////////////////////////////////////////////////////////////////////// | 4784 ///////////////////////////////////////////////////////////////////////////// |
4656 | 4785 |
4657 } // namespace chromeos | 4786 } // namespace chromeos |
4658 | 4787 |
4659 // Allows InvokeLater without adding refcounting. This class is a Singleton and | 4788 // Allows InvokeLater without adding refcounting. This class is a Singleton and |
4660 // won't be deleted until its last InvokeLater is run. | 4789 // won't be deleted until its last InvokeLater is run. |
4661 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::NetworkLibraryImplBase); | 4790 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::NetworkLibraryImplBase); |
OLD | NEW |