Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(576)

Side by Side Diff: chrome/browser/chromeos/cros/network_library.cc

Issue 7765009: Use new GValue chromeos_network calls instead of base::Value (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments. Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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) {
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) {
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));
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
satorux1 2011/08/29 19:52:47 Not fault of this change, but use of base::Value f
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 case Value::TYPE_NULL:
274 case Value::TYPE_DOUBLE:
275 case Value::TYPE_BINARY:
276 case Value::TYPE_DICTIONARY:
277 case Value::TYPE_LIST:
278 // Other Value types shouldn't be passed through this mechanism.
279 NOTREACHED() << "Unconverted Value of type: " << value->GetType();
280 return NULL;
281 }
282 NOTREACHED() << "Value conversion failed, type: " << value->GetType();
283 return NULL;
284 }
285
153 } // namespace 286 } // namespace
154 287
155 //////////////////////////////////////////////////////////////////////////////// 288 ////////////////////////////////////////////////////////////////////////////////
156 // FoundCellularNetwork 289 // FoundCellularNetwork
157 290
158 FoundCellularNetwork::FoundCellularNetwork() {} 291 FoundCellularNetwork::FoundCellularNetwork() {}
159 292
160 FoundCellularNetwork::~FoundCellularNetwork() {} 293 FoundCellularNetwork::~FoundCellularNetwork() {}
161 294
162 //////////////////////////////////////////////////////////////////////////////// 295 ////////////////////////////////////////////////////////////////////////////////
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 unique_id_ = name_; 389 unique_id_ = name_;
257 } 390 }
258 391
259 bool Network::RequiresUserProfile() const { 392 bool Network::RequiresUserProfile() const {
260 return false; 393 return false;
261 } 394 }
262 395
263 void Network::CopyCredentialsFromRemembered(Network* remembered) { 396 void Network::CopyCredentialsFromRemembered(Network* remembered) {
264 } 397 }
265 398
266 void Network::SetValueProperty(const char* prop, Value* val) { 399 void Network::SetValueProperty(const char* prop, Value* value) {
267 DCHECK(prop); 400 DCHECK(prop);
268 DCHECK(val); 401 DCHECK(value);
269 if (!EnsureCrosLoaded()) 402 if (!EnsureCrosLoaded())
270 return; 403 return;
271 chromeos::SetNetworkServiceProperty(service_path_.c_str(), prop, val); 404 scoped_ptr<GValue> gvalue(ConvertValueToGValue(value));
405 chromeos::SetNetworkServicePropertyGValue(
406 service_path_.c_str(), prop, gvalue.get());
272 } 407 }
273 408
274 void Network::ClearProperty(const char* prop) { 409 void Network::ClearProperty(const char* prop) {
275 DCHECK(prop); 410 DCHECK(prop);
276 if (!EnsureCrosLoaded()) 411 if (!EnsureCrosLoaded())
277 return; 412 return;
278 chromeos::ClearNetworkServiceProperty(service_path_.c_str(), prop); 413 chromeos::ClearNetworkServiceProperty(service_path_.c_str(), prop);
279 } 414 }
280 415
281 void Network::SetStringProperty( 416 void Network::SetStringProperty(
(...skipping 2698 matching lines...) Expand 10 before | Expand all | Expand 10 after
2980 3115
2981 virtual NetworkIPConfigVector GetIPConfigs( 3116 virtual NetworkIPConfigVector GetIPConfigs(
2982 const std::string& device_path, 3117 const std::string& device_path,
2983 std::string* hardware_address, 3118 std::string* hardware_address,
2984 HardwareAddressFormat format) OVERRIDE; 3119 HardwareAddressFormat format) OVERRIDE;
2985 virtual void SetIPConfig(const NetworkIPConfig& ipconfig) OVERRIDE; 3120 virtual void SetIPConfig(const NetworkIPConfig& ipconfig) OVERRIDE;
2986 3121
2987 ////////////////////////////////////////////////////////////////////////////// 3122 //////////////////////////////////////////////////////////////////////////////
2988 // Calbacks. 3123 // Calbacks.
2989 static void NetworkStatusChangedHandler( 3124 static void NetworkStatusChangedHandler(
2990 void* object, const char* path, const char* key, const Value* value); 3125 void* object, const char* path, const char* key, const GValue* value);
2991 void UpdateNetworkStatus( 3126 void UpdateNetworkStatus(
2992 const std::string& path, const std::string& key, const Value& value); 3127 const std::string& path, const std::string& key, const Value& value);
2993 3128
2994 static void NetworkDevicePropertyChangedHandler( 3129 static void NetworkDevicePropertyChangedHandler(
2995 void* object, const char* path, const char* key, const Value* value); 3130 void* object, const char* path, const char* key, const GValue* gvalue);
2996 void UpdateNetworkDeviceStatus( 3131 void UpdateNetworkDeviceStatus(
2997 const std::string& path, const std::string& key, const Value& value); 3132 const std::string& path, const std::string& key, const Value& value);
2998 3133
2999 static void PinOperationCallback(void* object, 3134 static void PinOperationCallback(void* object,
3000 const char* path, 3135 const char* path,
3001 NetworkMethodErrorType error, 3136 NetworkMethodErrorType error,
3002 const char* error_message); 3137 const char* error_message);
3003 3138
3004 static void CellularRegisterCallback(void* object, 3139 static void CellularRegisterCallback(void* object,
3005 const char* path, 3140 const char* path,
3006 NetworkMethodErrorType error, 3141 NetworkMethodErrorType error,
3007 const char* error_message); 3142 const char* error_message);
3008 3143
3009 static void NetworkConnectCallback(void* object, 3144 static void NetworkConnectCallback(void* object,
3010 const char* service_path, 3145 const char* service_path,
3011 NetworkMethodErrorType error, 3146 NetworkMethodErrorType error,
3012 const char* error_message); 3147 const char* error_message);
3013 3148
3014 static void WifiServiceUpdateAndConnect( 3149 static void WifiServiceUpdateAndConnect(
3015 void* object, const char* service_path, const Value* info); 3150 void* object, const char* service_path, GHashTable* ghash);
3016 static void VPNServiceUpdateAndConnect( 3151 static void VPNServiceUpdateAndConnect(
3017 void* object, const char* service_path, const Value* info); 3152 void* object, const char* service_path, GHashTable* ghash);
3018 3153
3019 static void NetworkManagerStatusChangedHandler( 3154 static void NetworkManagerStatusChangedHandler(
3020 void* object, const char* path, const char* key, const Value* value); 3155 void* object, const char* path, const char* key, const GValue* value);
3021 static void NetworkManagerUpdate( 3156 static void NetworkManagerUpdate(
3022 void* object, const char* manager_path, const Value* info); 3157 void* object, const char* manager_path, GHashTable* ghash);
3023 3158
3024 static void DataPlanUpdateHandler(void* object, 3159 static void DataPlanUpdateHandler(void* object,
3025 const char* modem_service_path, 3160 const char* modem_service_path,
3026 const CellularDataPlanList* dataplan); 3161 const CellularDataPlanList* dataplan);
3027 3162
3028 static void NetworkServiceUpdate( 3163 static void NetworkServiceUpdate(
3029 void* object, const char* service_path, const Value* info); 3164 void* object, const char* service_path, GHashTable* ghash);
3030 static void RememberedNetworkServiceUpdate( 3165 static void RememberedNetworkServiceUpdate(
3031 void* object, const char* service_path, const Value* info); 3166 void* object, const char* service_path, GHashTable* ghash);
3032 static void ProfileUpdate( 3167 static void ProfileUpdate(
3033 void* object, const char* profile_path, const Value* info); 3168 void* object, const char* profile_path, GHashTable* ghash);
3034 static void NetworkDeviceUpdate( 3169 static void NetworkDeviceUpdate(
3035 void* object, const char* device_path, const Value* info); 3170 void* object, const char* device_path, GHashTable* ghash);
3036 3171
3037 private: 3172 private:
3038 // This processes all Manager update messages. 3173 // This processes all Manager update messages.
3039 void NetworkManagerStatusChanged(const char* key, const Value* value); 3174 void NetworkManagerStatusChanged(const char* key, const Value* value);
3040 void ParseNetworkManager(const DictionaryValue& dict); 3175 void ParseNetworkManager(const DictionaryValue& dict);
3041 void UpdateTechnologies(const ListValue* technologies, int* bitfieldp); 3176 void UpdateTechnologies(const ListValue* technologies, int* bitfieldp);
3042 void UpdateAvailableTechnologies(const ListValue* technologies); 3177 void UpdateAvailableTechnologies(const ListValue* technologies);
3043 void UpdateEnabledTechnologies(const ListValue* technologies); 3178 void UpdateEnabledTechnologies(const ListValue* technologies);
3044 void UpdateConnectedTechnologies(const ListValue* technologies); 3179 void UpdateConnectedTechnologies(const ListValue* technologies);
3045 3180
(...skipping 16 matching lines...) Expand all
3062 const DictionaryValue& info); 3197 const DictionaryValue& info);
3063 3198
3064 // Empty device observer to ensure that device property updates are received. 3199 // Empty device observer to ensure that device property updates are received.
3065 class NetworkLibraryDeviceObserver : public NetworkDeviceObserver { 3200 class NetworkLibraryDeviceObserver : public NetworkDeviceObserver {
3066 public: 3201 public:
3067 virtual ~NetworkLibraryDeviceObserver() {} 3202 virtual ~NetworkLibraryDeviceObserver() {}
3068 virtual void OnNetworkDeviceChanged( 3203 virtual void OnNetworkDeviceChanged(
3069 NetworkLibrary* cros, const NetworkDevice* device) OVERRIDE {} 3204 NetworkLibrary* cros, const NetworkDevice* device) OVERRIDE {}
3070 }; 3205 };
3071 3206
3072 typedef std::map<std::string, chromeos::PropertyChangeMonitor> 3207 typedef std::map<std::string, chromeos::NetworkPropertiesMonitor>
3073 PropertyChangeMonitorMap; 3208 NetworkPropertiesMonitorMap;
3074 3209
3075 // For monitoring network manager status changes. 3210 // For monitoring network manager status changes.
3076 PropertyChangeMonitor network_manager_monitor_; 3211 NetworkPropertiesMonitor network_manager_monitor_;
3077 3212
3078 // For monitoring data plan changes to the connected cellular network. 3213 // For monitoring data plan changes to the connected cellular network.
3079 DataPlanUpdateMonitor data_plan_monitor_; 3214 DataPlanUpdateMonitor data_plan_monitor_;
3080 3215
3081 // Network device observer. 3216 // Network device observer.
3082 scoped_ptr<NetworkLibraryDeviceObserver> network_device_observer_; 3217 scoped_ptr<NetworkLibraryDeviceObserver> network_device_observer_;
3083 3218
3084 // Map of monitored networks. 3219 // Map of monitored networks.
3085 PropertyChangeMonitorMap montitored_networks_; 3220 NetworkPropertiesMonitorMap montitored_networks_;
3086 3221
3087 // Map of monitored devices. 3222 // Map of monitored devices.
3088 PropertyChangeMonitorMap montitored_devices_; 3223 NetworkPropertiesMonitorMap montitored_devices_;
3089 3224
3090 DISALLOW_COPY_AND_ASSIGN(NetworkLibraryImplCros); 3225 DISALLOW_COPY_AND_ASSIGN(NetworkLibraryImplCros);
3091 }; 3226 };
3092 3227
3093 //////////////////////////////////////////////////////////////////////////// 3228 ////////////////////////////////////////////////////////////////////////////
3094 3229
3095 NetworkLibraryImplCros::NetworkLibraryImplCros() 3230 NetworkLibraryImplCros::NetworkLibraryImplCros()
3096 : NetworkLibraryImplBase(), 3231 : NetworkLibraryImplBase(),
3097 network_manager_monitor_(NULL), 3232 network_manager_monitor_(NULL),
3098 data_plan_monitor_(NULL) { 3233 data_plan_monitor_(NULL) {
3099 } 3234 }
3100 3235
3101 NetworkLibraryImplCros::~NetworkLibraryImplCros() { 3236 NetworkLibraryImplCros::~NetworkLibraryImplCros() {
3102 if (network_manager_monitor_) 3237 if (network_manager_monitor_)
3103 chromeos::DisconnectPropertyChangeMonitor(network_manager_monitor_); 3238 chromeos::DisconnectNetworkPropertiesMonitor(network_manager_monitor_);
3104 if (data_plan_monitor_) 3239 if (data_plan_monitor_)
3105 chromeos::DisconnectDataPlanUpdateMonitor(data_plan_monitor_); 3240 chromeos::DisconnectDataPlanUpdateMonitor(data_plan_monitor_);
3106 for (PropertyChangeMonitorMap::iterator iter = montitored_networks_.begin(); 3241 for (NetworkPropertiesMonitorMap::iterator iter =
3242 montitored_networks_.begin();
3107 iter != montitored_networks_.end(); ++iter) { 3243 iter != montitored_networks_.end(); ++iter) {
3108 chromeos::DisconnectPropertyChangeMonitor(iter->second); 3244 chromeos::DisconnectNetworkPropertiesMonitor(iter->second);
3109 } 3245 }
3110 for (PropertyChangeMonitorMap::iterator iter = montitored_devices_.begin(); 3246 for (NetworkPropertiesMonitorMap::iterator iter =
3247 montitored_devices_.begin();
3111 iter != montitored_devices_.end(); ++iter) { 3248 iter != montitored_devices_.end(); ++iter) {
3112 chromeos::DisconnectPropertyChangeMonitor(iter->second); 3249 chromeos::DisconnectNetworkPropertiesMonitor(iter->second);
3113 } 3250 }
3114 } 3251 }
3115 3252
3116 void NetworkLibraryImplCros::Init() { 3253 void NetworkLibraryImplCros::Init() {
3117 // First, get the currently available networks. This data is cached 3254 // First, get the currently available networks. This data is cached
3118 // on the connman side, so the call should be quick. 3255 // on the connman side, so the call should be quick.
3119 VLOG(1) << "Requesting initial network manager info from libcros."; 3256 VLOG(1) << "Requesting initial network manager info from libcros.";
3120 chromeos::RequestNetworkManagerInfo(&NetworkManagerUpdate, this); 3257 chromeos::RequestNetworkManagerProperties(&NetworkManagerUpdate, this);
3121 network_manager_monitor_ = 3258 network_manager_monitor_ =
3122 chromeos::MonitorNetworkManager(&NetworkManagerStatusChangedHandler, 3259 chromeos::MonitorNetworkManagerProperties(
3123 this); 3260 &NetworkManagerStatusChangedHandler, this);
3124 data_plan_monitor_ = 3261 data_plan_monitor_ =
3125 chromeos::MonitorCellularDataPlan(&DataPlanUpdateHandler, this); 3262 chromeos::MonitorCellularDataPlan(&DataPlanUpdateHandler, this);
3126 // Always have at least one device obsever so that device updates are 3263 // Always have at least one device obsever so that device updates are
3127 // always received. 3264 // always received.
3128 network_device_observer_.reset(new NetworkLibraryDeviceObserver()); 3265 network_device_observer_.reset(new NetworkLibraryDeviceObserver());
3129 } 3266 }
3130 3267
3131 ////////////////////////////////////////////////////////////////////////////// 3268 //////////////////////////////////////////////////////////////////////////////
3132 // NetworkLibraryImplBase implementation. 3269 // NetworkLibraryImplBase implementation.
3133 3270
3134 void NetworkLibraryImplCros::MonitorNetworkStart( 3271 void NetworkLibraryImplCros::MonitorNetworkStart(
3135 const std::string& service_path) { 3272 const std::string& service_path) {
3136 if (montitored_networks_.find(service_path) == montitored_networks_.end()) { 3273 if (montitored_networks_.find(service_path) == montitored_networks_.end()) {
3137 chromeos::PropertyChangeMonitor monitor = 3274 chromeos::NetworkPropertiesMonitor monitor =
3138 chromeos::MonitorNetworkService(&NetworkStatusChangedHandler, 3275 chromeos::MonitorNetworkServiceProperties(
3139 service_path.c_str(), 3276 &NetworkStatusChangedHandler, service_path.c_str(), this);
3140 this);
3141 montitored_networks_[service_path] = monitor; 3277 montitored_networks_[service_path] = monitor;
3142 } 3278 }
3143 } 3279 }
3144 3280
3145 void NetworkLibraryImplCros::MonitorNetworkStop( 3281 void NetworkLibraryImplCros::MonitorNetworkStop(
3146 const std::string& service_path) { 3282 const std::string& service_path) {
3147 PropertyChangeMonitorMap::iterator iter = 3283 NetworkPropertiesMonitorMap::iterator iter =
3148 montitored_networks_.find(service_path); 3284 montitored_networks_.find(service_path);
3149 if (iter != montitored_networks_.end()) { 3285 if (iter != montitored_networks_.end()) {
3150 chromeos::DisconnectPropertyChangeMonitor(iter->second); 3286 chromeos::DisconnectNetworkPropertiesMonitor(iter->second);
3151 montitored_networks_.erase(iter); 3287 montitored_networks_.erase(iter);
3152 } 3288 }
3153 } 3289 }
3154 3290
3155 void NetworkLibraryImplCros::MonitorNetworkDeviceStart( 3291 void NetworkLibraryImplCros::MonitorNetworkDeviceStart(
3156 const std::string& device_path) { 3292 const std::string& device_path) {
3157 if (montitored_devices_.find(device_path) == montitored_devices_.end()) { 3293 if (montitored_devices_.find(device_path) == montitored_devices_.end()) {
3158 chromeos::PropertyChangeMonitor monitor = 3294 chromeos::NetworkPropertiesMonitor monitor =
3159 chromeos::MonitorNetworkDevice(&NetworkDevicePropertyChangedHandler, 3295 chromeos::MonitorNetworkDeviceProperties(
3160 device_path.c_str(), 3296 &NetworkDevicePropertyChangedHandler, device_path.c_str(), this);
3161 this);
3162 montitored_devices_[device_path] = monitor; 3297 montitored_devices_[device_path] = monitor;
3163 } 3298 }
3164 } 3299 }
3165 3300
3166 void NetworkLibraryImplCros::MonitorNetworkDeviceStop( 3301 void NetworkLibraryImplCros::MonitorNetworkDeviceStop(
3167 const std::string& device_path) { 3302 const std::string& device_path) {
3168 PropertyChangeMonitorMap::iterator iter = 3303 NetworkPropertiesMonitorMap::iterator iter =
3169 montitored_devices_.find(device_path); 3304 montitored_devices_.find(device_path);
3170 if (iter != montitored_devices_.end()) { 3305 if (iter != montitored_devices_.end()) {
3171 chromeos::DisconnectPropertyChangeMonitor(iter->second); 3306 chromeos::DisconnectNetworkPropertiesMonitor(iter->second);
3172 montitored_devices_.erase(iter); 3307 montitored_devices_.erase(iter);
3173 } 3308 }
3174 } 3309 }
3175 3310
3176 // static callback 3311 // static callback
3177 void NetworkLibraryImplCros::NetworkStatusChangedHandler( 3312 void NetworkLibraryImplCros::NetworkStatusChangedHandler(
3178 void* object, const char* path, const char* key, const Value* value) { 3313 void* object, const char* path, const char* key, const GValue* gvalue) {
3179 NetworkLibraryImplCros* networklib = 3314 NetworkLibraryImplCros* networklib =
3180 static_cast<NetworkLibraryImplCros*>(object); 3315 static_cast<NetworkLibraryImplCros*>(object);
3181 DCHECK(networklib); 3316 DCHECK(networklib);
3182 if (key == NULL || value == NULL || path == NULL || object == NULL) 3317 if (key == NULL || gvalue == NULL || path == NULL || object == NULL)
3183 return; 3318 return;
3319 scoped_ptr<Value> value(ConvertGlibValue(gvalue));
3184 networklib->UpdateNetworkStatus(std::string(path), std::string(key), *value); 3320 networklib->UpdateNetworkStatus(std::string(path), std::string(key), *value);
3185 } 3321 }
3186 3322
3187 void NetworkLibraryImplCros::UpdateNetworkStatus( 3323 void NetworkLibraryImplCros::UpdateNetworkStatus(
3188 const std::string& path, const std::string& key, const Value& value) { 3324 const std::string& path, const std::string& key, const Value& value) {
3189 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3325 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3190 Network* network = FindNetworkByPath(path); 3326 Network* network = FindNetworkByPath(path);
3191 if (network) { 3327 if (network) {
3192 VLOG(2) << "UpdateNetworkStatus: " << network->name() << "." << key; 3328 VLOG(2) << "UpdateNetworkStatus: " << network->name() << "." << key;
3193 bool prev_connected = network->connected(); 3329 bool prev_connected = network->connected();
3194 if (!network->UpdateStatus(key, value, NULL)) { 3330 if (!network->UpdateStatus(key, value, NULL)) {
3195 LOG(WARNING) << "UpdateNetworkStatus: Error updating: " 3331 LOG(WARNING) << "UpdateNetworkStatus: Error updating: "
3196 << path << "." << key; 3332 << path << "." << key;
3197 } 3333 }
3198 // If we just connected, this may have been added to remembered list. 3334 // If we just connected, this may have been added to remembered list.
3199 if (!prev_connected && network->connected()) 3335 if (!prev_connected && network->connected())
3200 RequestRememberedNetworksUpdate(); 3336 RequestRememberedNetworksUpdate();
3201 NotifyNetworkChanged(network); 3337 NotifyNetworkChanged(network);
3202 // Anything observing the manager needs to know about any service change. 3338 // Anything observing the manager needs to know about any service change.
3203 NotifyNetworkManagerChanged(false); // Not forced. 3339 NotifyNetworkManagerChanged(false); // Not forced.
3204 } 3340 }
3205 } 3341 }
3206 3342
3207 // static callback 3343 // static callback
3208 void NetworkLibraryImplCros::NetworkDevicePropertyChangedHandler( 3344 void NetworkLibraryImplCros::NetworkDevicePropertyChangedHandler(
3209 void* object, const char* path, const char* key, const Value* value) { 3345 void* object, const char* path, const char* key, const GValue* gvalue) {
3210 NetworkLibraryImplCros* networklib = 3346 NetworkLibraryImplCros* networklib =
3211 static_cast<NetworkLibraryImplCros*>(object); 3347 static_cast<NetworkLibraryImplCros*>(object);
3212 DCHECK(networklib); 3348 DCHECK(networklib);
3213 if (key == NULL || value == NULL || path == NULL || object == NULL) 3349 if (key == NULL || gvalue == NULL || path == NULL || object == NULL)
3214 return; 3350 return;
3351 scoped_ptr<Value> value(ConvertGlibValue(gvalue));
3215 networklib->UpdateNetworkDeviceStatus(std::string(path), 3352 networklib->UpdateNetworkDeviceStatus(std::string(path),
3216 std::string(key), 3353 std::string(key),
3217 *value); 3354 *value);
3218 } 3355 }
3219 3356
3220 void NetworkLibraryImplCros::UpdateNetworkDeviceStatus( 3357 void NetworkLibraryImplCros::UpdateNetworkDeviceStatus(
3221 const std::string& path, const std::string& key, const Value& value) { 3358 const std::string& path, const std::string& key, const Value& value) {
3222 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3359 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3223 NetworkDevice* device = FindNetworkDeviceByPath(path); 3360 NetworkDevice* device = FindNetworkDeviceByPath(path);
3224 if (device) { 3361 if (device) {
(...skipping 14 matching lines...) Expand all
3239 } 3376 }
3240 } 3377 }
3241 } else { 3378 } else {
3242 VLOG(1) << "UpdateNetworkDeviceStatus: Failed to update: " 3379 VLOG(1) << "UpdateNetworkDeviceStatus: Failed to update: "
3243 << path << "." << key; 3380 << path << "." << key;
3244 } 3381 }
3245 // Notify only observers on device property change. 3382 // Notify only observers on device property change.
3246 NotifyNetworkDeviceChanged(device, index); 3383 NotifyNetworkDeviceChanged(device, index);
3247 // If a device's power state changes, new properties may become defined. 3384 // If a device's power state changes, new properties may become defined.
3248 if (index == PROPERTY_INDEX_POWERED) 3385 if (index == PROPERTY_INDEX_POWERED)
3249 chromeos::RequestNetworkDeviceInfo(path.c_str(), 3386 chromeos::RequestNetworkDeviceProperties(path.c_str(),
3250 &NetworkDeviceUpdate, 3387 &NetworkDeviceUpdate,
3251 this); 3388 this);
3252 } 3389 }
3253 } 3390 }
3254 3391
3255 ///////////////////////////////////////////////////////////////////////////// 3392 /////////////////////////////////////////////////////////////////////////////
3256 // NetworkLibraryImplBase connect implementation. 3393 // NetworkLibraryImplBase connect implementation.
3257 3394
3258 // static callback 3395 // static callback
3259 void NetworkLibraryImplCros::NetworkConnectCallback( 3396 void NetworkLibraryImplCros::NetworkConnectCallback(
3260 void* object, 3397 void* object,
3261 const char* service_path, 3398 const char* service_path,
(...skipping 24 matching lines...) Expand all
3286 } 3423 }
3287 3424
3288 void NetworkLibraryImplCros::CallConnectToNetwork(Network* network) { 3425 void NetworkLibraryImplCros::CallConnectToNetwork(Network* network) {
3289 DCHECK(network); 3426 DCHECK(network);
3290 chromeos::RequestNetworkServiceConnect(network->service_path().c_str(), 3427 chromeos::RequestNetworkServiceConnect(network->service_path().c_str(),
3291 NetworkConnectCallback, this); 3428 NetworkConnectCallback, this);
3292 } 3429 }
3293 3430
3294 // static callback 3431 // static callback
3295 void NetworkLibraryImplCros::WifiServiceUpdateAndConnect( 3432 void NetworkLibraryImplCros::WifiServiceUpdateAndConnect(
3296 void* object, const char* service_path, const Value* info) { 3433 void* object, const char* service_path, GHashTable* ghash) {
3297 NetworkLibraryImplCros* networklib = 3434 NetworkLibraryImplCros* networklib =
3298 static_cast<NetworkLibraryImplCros*>(object); 3435 static_cast<NetworkLibraryImplCros*>(object);
3299 DCHECK(networklib); 3436 DCHECK(networklib);
3300 if (service_path && info) { 3437 if (service_path && ghash) {
3301 DCHECK_EQ(info->GetType(), Value::TYPE_DICTIONARY); 3438 scoped_ptr<DictionaryValue> dict(ConvertGHashTable(ghash));
3302 const DictionaryValue* dict = static_cast<const DictionaryValue*>(info);
3303 Network* network = 3439 Network* network =
3304 networklib->ParseNetwork(std::string(service_path), *dict); 3440 networklib->ParseNetwork(std::string(service_path), *(dict.get()));
3305 DCHECK_EQ(network->type(), TYPE_WIFI); 3441 DCHECK_EQ(network->type(), TYPE_WIFI);
3306 networklib->ConnectToWifiNetworkUsingConnectData( 3442 networklib->ConnectToWifiNetworkUsingConnectData(
3307 static_cast<WifiNetwork*>(network)); 3443 static_cast<WifiNetwork*>(network));
3308 } 3444 }
3309 } 3445 }
3310 3446
3311 void NetworkLibraryImplCros::CallRequestWifiNetworkAndConnect( 3447 void NetworkLibraryImplCros::CallRequestWifiNetworkAndConnect(
3312 const std::string& ssid, ConnectionSecurity security) { 3448 const std::string& ssid, ConnectionSecurity security) {
3313 // Asynchronously request service properties and call 3449 // Asynchronously request service properties and call
3314 // WifiServiceUpdateAndConnect. 3450 // WifiServiceUpdateAndConnect.
3315 chromeos::RequestHiddenWifiNetwork(ssid.c_str(), 3451 chromeos::RequestHiddenWifiNetworkProperties(
3316 SecurityToString(security), 3452 ssid.c_str(),
3317 WifiServiceUpdateAndConnect, 3453 SecurityToString(security),
3318 this); 3454 WifiServiceUpdateAndConnect,
3455 this);
3319 } 3456 }
3320 3457
3321 // static callback 3458 // static callback
3322 void NetworkLibraryImplCros::VPNServiceUpdateAndConnect( 3459 void NetworkLibraryImplCros::VPNServiceUpdateAndConnect(
3323 void* object, const char* service_path, const Value* info) { 3460 void* object, const char* service_path, GHashTable* ghash) {
3324 NetworkLibraryImplCros* networklib = 3461 NetworkLibraryImplCros* networklib =
3325 static_cast<NetworkLibraryImplCros*>(object); 3462 static_cast<NetworkLibraryImplCros*>(object);
3326 DCHECK(networklib); 3463 DCHECK(networklib);
3327 if (service_path && info) { 3464 if (service_path && ghash) {
3328 VLOG(1) << "Connecting to new VPN Service: " << service_path; 3465 VLOG(1) << "Connecting to new VPN Service: " << service_path;
3329 DCHECK_EQ(info->GetType(), Value::TYPE_DICTIONARY); 3466 scoped_ptr<DictionaryValue> dict(ConvertGHashTable(ghash));
3330 const DictionaryValue* dict = static_cast<const DictionaryValue*>(info);
3331 Network* network = 3467 Network* network =
3332 networklib->ParseNetwork(std::string(service_path), *dict); 3468 networklib->ParseNetwork(std::string(service_path), *(dict.get()));
3333 DCHECK_EQ(network->type(), TYPE_VPN); 3469 DCHECK_EQ(network->type(), TYPE_VPN);
3334 networklib->ConnectToVirtualNetworkUsingConnectData( 3470 networklib->ConnectToVirtualNetworkUsingConnectData(
3335 static_cast<VirtualNetwork*>(network)); 3471 static_cast<VirtualNetwork*>(network));
3336 } else { 3472 } else {
3337 LOG(WARNING) << "Unable to create VPN Service: " << service_path; 3473 LOG(WARNING) << "Unable to create VPN Service: " << service_path;
3338 } 3474 }
3339 } 3475 }
3340 3476
3341 void NetworkLibraryImplCros::CallRequestVirtualNetworkAndConnect( 3477 void NetworkLibraryImplCros::CallRequestVirtualNetworkAndConnect(
3342 const std::string& service_name, 3478 const std::string& service_name,
3343 const std::string& server_hostname, 3479 const std::string& server_hostname,
3344 ProviderType provider_type) { 3480 ProviderType provider_type) {
3345 chromeos::RequestVirtualNetwork(service_name.c_str(), 3481 chromeos::RequestVirtualNetworkProperties(
3346 server_hostname.c_str(), 3482 service_name.c_str(),
3347 ProviderTypeToString(provider_type), 3483 server_hostname.c_str(),
3348 VPNServiceUpdateAndConnect, 3484 ProviderTypeToString(provider_type),
3349 this); 3485 VPNServiceUpdateAndConnect,
3486 this);
3350 } 3487 }
3351 3488
3352 void NetworkLibraryImplCros::CallDeleteRememberedNetwork( 3489 void NetworkLibraryImplCros::CallDeleteRememberedNetwork(
3353 const std::string& profile_path, 3490 const std::string& profile_path,
3354 const std::string& service_path) { 3491 const std::string& service_path) {
3355 chromeos::DeleteServiceFromProfile( 3492 chromeos::DeleteServiceFromProfile(
3356 profile_path.c_str(), service_path.c_str()); 3493 profile_path.c_str(), service_path.c_str());
3357 } 3494 }
3358 3495
3359 ////////////////////////////////////////////////////////////////////////////// 3496 //////////////////////////////////////////////////////////////////////////////
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
3482 // but not UI doesn't assume such notification so just ignore result. 3619 // but not UI doesn't assume such notification so just ignore result.
3483 } 3620 }
3484 3621
3485 void NetworkLibraryImplCros::SetCellularDataRoamingAllowed(bool new_value) { 3622 void NetworkLibraryImplCros::SetCellularDataRoamingAllowed(bool new_value) {
3486 const NetworkDevice* cellular = FindCellularDevice(); 3623 const NetworkDevice* cellular = FindCellularDevice();
3487 if (!cellular) { 3624 if (!cellular) {
3488 NOTREACHED() << "Calling SetCellularDataRoamingAllowed method " 3625 NOTREACHED() << "Calling SetCellularDataRoamingAllowed method "
3489 "w/o cellular device."; 3626 "w/o cellular device.";
3490 return; 3627 return;
3491 } 3628 }
3492 scoped_ptr<Value> value(Value::CreateBooleanValue(new_value)); 3629 scoped_ptr<GValue> gvalue(ConvertBoolToGValue(new_value));
3493 chromeos::SetNetworkDeviceProperty(cellular->device_path().c_str(), 3630 chromeos::SetNetworkDevicePropertyGValue(cellular->device_path().c_str(),
3494 kCellularAllowRoamingProperty, 3631 kCellularAllowRoamingProperty,
3495 value.get()); 3632 gvalue.get());
3496 } 3633 }
3497 3634
3498 bool NetworkLibraryImplCros::IsCellularAlwaysInRoaming() { 3635 bool NetworkLibraryImplCros::IsCellularAlwaysInRoaming() {
3499 const NetworkDevice* cellular = FindCellularDevice(); 3636 const NetworkDevice* cellular = FindCellularDevice();
3500 if (!cellular) { 3637 if (!cellular) {
3501 NOTREACHED() << "Calling IsCellularAlwaysInRoaming method " 3638 NOTREACHED() << "Calling IsCellularAlwaysInRoaming method "
3502 "w/o cellular device."; 3639 "w/o cellular device.";
3503 return false; 3640 return false;
3504 } 3641 }
3505 const std::string& home_provider_name = cellular->home_provider_name(); 3642 const std::string& home_provider_name = cellular->home_provider_name();
3506 for (size_t i = 0; i < arraysize(kAlwaysInRoamingOperators); i++) { 3643 for (size_t i = 0; i < arraysize(kAlwaysInRoamingOperators); i++) {
3507 if (home_provider_name == kAlwaysInRoamingOperators[i]) 3644 if (home_provider_name == kAlwaysInRoamingOperators[i])
3508 return true; 3645 return true;
3509 } 3646 }
3510 return false; 3647 return false;
3511 } 3648 }
3512 3649
3513 void NetworkLibraryImplCros::RequestNetworkScan() { 3650 void NetworkLibraryImplCros::RequestNetworkScan() {
3514 if (wifi_enabled()) { 3651 if (wifi_enabled()) {
3515 wifi_scanning_ = true; // Cleared when updates are received. 3652 wifi_scanning_ = true; // Cleared when updates are received.
3516 chromeos::RequestNetworkScan(kTypeWifi); 3653 chromeos::RequestNetworkScan(kTypeWifi);
3517 } 3654 }
3518 if (cellular_network()) 3655 if (cellular_network())
3519 cellular_network()->RefreshDataPlansIfNeeded(); 3656 cellular_network()->RefreshDataPlansIfNeeded();
3520 // Make sure all Manager info is up to date. This will also update 3657 // Make sure all Manager info is up to date. This will also update
3521 // remembered networks and visible services. 3658 // remembered networks and visible services.
3522 chromeos::RequestNetworkManagerInfo(&NetworkManagerUpdate, this); 3659 chromeos::RequestNetworkManagerProperties(&NetworkManagerUpdate, this);
3523 } 3660 }
3524 3661
3525 bool NetworkLibraryImplCros::GetWifiAccessPoints( 3662 bool NetworkLibraryImplCros::GetWifiAccessPoints(
3526 WifiAccessPointVector* result) { 3663 WifiAccessPointVector* result) {
3527 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3664 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3528 DeviceNetworkList* network_list = chromeos::GetDeviceNetworkList(); 3665 DeviceNetworkList* network_list = chromeos::GetDeviceNetworkList();
3529 if (network_list == NULL) 3666 if (network_list == NULL)
3530 return false; 3667 return false;
3531 result->clear(); 3668 result->clear();
3532 result->reserve(network_list->network_size); 3669 result->reserve(network_list->network_size);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
3643 if (ipconfig_status2) { 3780 if (ipconfig_status2) {
3644 for (int i = 0; i < ipconfig_status2->size; ++i) { 3781 for (int i = 0; i < ipconfig_status2->size; ++i) {
3645 if (ipconfig_status2->ips[i].type == chromeos::IPCONFIG_TYPE_IPV4) 3782 if (ipconfig_status2->ips[i].type == chromeos::IPCONFIG_TYPE_IPV4)
3646 ipconfig_static = &ipconfig_status2->ips[i]; 3783 ipconfig_static = &ipconfig_status2->ips[i];
3647 } 3784 }
3648 } 3785 }
3649 } 3786 }
3650 if (ipconfig_static) { 3787 if (ipconfig_static) {
3651 // Save any changed details. 3788 // Save any changed details.
3652 if (ipconfig.address != ipconfig_static->address) { 3789 if (ipconfig.address != ipconfig_static->address) {
3653 scoped_ptr<Value> value(Value::CreateStringValue(ipconfig.address)); 3790 scoped_ptr<GValue> gvalue(ConvertStringToGValue(ipconfig.address));
3654 chromeos::SetNetworkIPConfigProperty(ipconfig_static->path, 3791 chromeos::SetNetworkIPConfigPropertyGValue(
3655 kAddressProperty, 3792 ipconfig_static->path, kAddressProperty, gvalue.get());
3656 value.get());
3657 } 3793 }
3658 if (ipconfig.netmask != ipconfig_static->netmask) { 3794 if (ipconfig.netmask != ipconfig_static->netmask) {
3659 int32 prefixlen = ipconfig.GetPrefixLength(); 3795 int prefixlen = ipconfig.GetPrefixLength();
3660 if (prefixlen == -1) { 3796 if (prefixlen == -1) {
3661 VLOG(1) << "IP config prefixlen is invalid for netmask " 3797 VLOG(1) << "IP config prefixlen is invalid for netmask "
3662 << ipconfig.netmask; 3798 << ipconfig.netmask;
3663 } else { 3799 } else {
3664 scoped_ptr<Value> value(Value::CreateIntegerValue(prefixlen)); 3800 scoped_ptr<GValue> gvalue(ConvertIntToGValue(prefixlen));
3665 chromeos::SetNetworkIPConfigProperty(ipconfig_static->path, 3801 chromeos::SetNetworkIPConfigPropertyGValue(
3666 kPrefixlenProperty, 3802 ipconfig_static->path, kPrefixlenProperty, gvalue.get());
3667 value.get());
3668 } 3803 }
3669 } 3804 }
3670 if (ipconfig.gateway != ipconfig_static->gateway) { 3805 if (ipconfig.gateway != ipconfig_static->gateway) {
3671 scoped_ptr<Value> value(Value::CreateStringValue(ipconfig.gateway)); 3806 scoped_ptr<GValue> gvalue(ConvertStringToGValue(ipconfig.gateway));
3672 chromeos::SetNetworkIPConfigProperty(ipconfig_static->path, 3807 chromeos::SetNetworkIPConfigPropertyGValue(
3673 kGatewayProperty, 3808 ipconfig_static->path, kGatewayProperty, gvalue.get());
3674 value.get());
3675 } 3809 }
3676 if (ipconfig.name_servers != ipconfig_static->name_servers) { 3810 if (ipconfig.name_servers != ipconfig_static->name_servers) {
3677 scoped_ptr<Value> value( 3811 scoped_ptr<GValue> gvalue(ConvertStringToGValue(ipconfig.name_servers));
3678 Value::CreateStringValue(ipconfig.name_servers)); 3812 chromeos::SetNetworkIPConfigPropertyGValue(
3679 chromeos::SetNetworkIPConfigProperty(ipconfig_static->path, 3813 ipconfig_static->path, kNameServersProperty, gvalue.get());
3680 kNameServersProperty,
3681 value.get());
3682 } 3814 }
3683 // Remove dhcp ip config if there is one. 3815 // Remove dhcp ip config if there is one.
3684 if (ipconfig_dhcp) 3816 if (ipconfig_dhcp)
3685 chromeos::RemoveIPConfig(ipconfig_dhcp); 3817 chromeos::RemoveIPConfig(ipconfig_dhcp);
3686 } 3818 }
3687 } 3819 }
3688 3820
3689 if (ipconfig_status) 3821 if (ipconfig_status)
3690 chromeos::FreeIPConfigStatus(ipconfig_status); 3822 chromeos::FreeIPConfigStatus(ipconfig_status);
3691 if (ipconfig_status2) 3823 if (ipconfig_status2)
3692 chromeos::FreeIPConfigStatus(ipconfig_status2); 3824 chromeos::FreeIPConfigStatus(ipconfig_status2);
3693 } 3825 }
3694 3826
3695 ///////////////////////////////////////////////////////////////////////////// 3827 /////////////////////////////////////////////////////////////////////////////
3696 // Network Manager functions. 3828 // Network Manager functions.
3697 3829
3698 // static 3830 // static
3699 void NetworkLibraryImplCros::NetworkManagerStatusChangedHandler( 3831 void NetworkLibraryImplCros::NetworkManagerStatusChangedHandler(
3700 void* object, const char* path, const char* key, const Value* value) { 3832 void* object, const char* path, const char* key, const GValue* gvalue) {
3701 NetworkLibraryImplCros* networklib = 3833 NetworkLibraryImplCros* networklib =
3702 static_cast<NetworkLibraryImplCros*>(object); 3834 static_cast<NetworkLibraryImplCros*>(object);
3703 DCHECK(networklib); 3835 DCHECK(networklib);
3704 networklib->NetworkManagerStatusChanged(key, value); 3836 scoped_ptr<Value> value(ConvertGlibValue(gvalue));
3837 networklib->NetworkManagerStatusChanged(key, value.get());
3705 } 3838 }
3706 3839
3707 // This processes all Manager update messages. 3840 // This processes all Manager update messages.
3708 void NetworkLibraryImplCros::NetworkManagerStatusChanged( 3841 void NetworkLibraryImplCros::NetworkManagerStatusChanged(
3709 const char* key, const Value* value) { 3842 const char* key, const Value* value) {
3710 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3843 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3711 base::TimeTicks start = base::TimeTicks::Now(); 3844 base::TimeTicks start = base::TimeTicks::Now();
3712 if (!key) 3845 if (!key)
3713 return; 3846 return;
3714 VLOG(1) << "NetworkManagerStatusChanged: KEY=" << key; 3847 VLOG(1) << "NetworkManagerStatusChanged: KEY=" << key;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
3790 break; 3923 break;
3791 } 3924 }
3792 base::TimeDelta delta = base::TimeTicks::Now() - start; 3925 base::TimeDelta delta = base::TimeTicks::Now() - start;
3793 VLOG(2) << "NetworkManagerStatusChanged: time: " 3926 VLOG(2) << "NetworkManagerStatusChanged: time: "
3794 << delta.InMilliseconds() << " ms."; 3927 << delta.InMilliseconds() << " ms.";
3795 HISTOGRAM_TIMES("CROS_NETWORK_UPDATE", delta); 3928 HISTOGRAM_TIMES("CROS_NETWORK_UPDATE", delta);
3796 } 3929 }
3797 3930
3798 // static 3931 // static
3799 void NetworkLibraryImplCros::NetworkManagerUpdate( 3932 void NetworkLibraryImplCros::NetworkManagerUpdate(
3800 void* object, const char* manager_path, const Value* info) { 3933 void* object, const char* manager_path, GHashTable* ghash) {
3801 NetworkLibraryImplCros* networklib = 3934 NetworkLibraryImplCros* networklib =
3802 static_cast<NetworkLibraryImplCros*>(object); 3935 static_cast<NetworkLibraryImplCros*>(object);
3803 DCHECK(networklib); 3936 DCHECK(networklib);
3804 if (!info) { 3937 if (!ghash) {
3805 LOG(ERROR) << "Error retrieving manager properties: " << manager_path; 3938 LOG(ERROR) << "Error retrieving manager properties: " << manager_path;
3806 return; 3939 return;
3807 } 3940 }
3808 VLOG(1) << "Received NetworkManagerUpdate."; 3941 VLOG(1) << "Received NetworkManagerUpdate.";
3809 DCHECK_EQ(info->GetType(), Value::TYPE_DICTIONARY); 3942 scoped_ptr<DictionaryValue> dict(ConvertGHashTable(ghash));
3810 const DictionaryValue* dict = static_cast<const DictionaryValue*>(info); 3943 networklib->ParseNetworkManager(*(dict.get()));
3811 networklib->ParseNetworkManager(*dict);
3812 } 3944 }
3813 3945
3814 void NetworkLibraryImplCros::ParseNetworkManager(const DictionaryValue& dict) { 3946 void NetworkLibraryImplCros::ParseNetworkManager(const DictionaryValue& dict) {
3815 for (DictionaryValue::key_iterator iter = dict.begin_keys(); 3947 for (DictionaryValue::key_iterator iter = dict.begin_keys();
3816 iter != dict.end_keys(); ++iter) { 3948 iter != dict.end_keys(); ++iter) {
3817 const std::string& key = *iter; 3949 const std::string& key = *iter;
3818 Value* value; 3950 Value* value;
3819 bool res = dict.GetWithoutPathExpansion(key, &value); 3951 bool res = dict.GetWithoutPathExpansion(key, &value);
3820 CHECK(res); 3952 CHECK(res);
3821 NetworkManagerStatusChanged(key.c_str(), value); 3953 NetworkManagerStatusChanged(key.c_str(), value);
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
3914 AddNetwork(found->second); 4046 AddNetwork(found->second);
3915 old_network_map.erase(found); 4047 old_network_map.erase(found);
3916 } 4048 }
3917 // Always request network updates. 4049 // Always request network updates.
3918 // TODO(stevenjb): Investigate why we are missing updates then 4050 // TODO(stevenjb): Investigate why we are missing updates then
3919 // rely on watched network updates and only request updates here for 4051 // rely on watched network updates and only request updates here for
3920 // new networks. 4052 // new networks.
3921 // Use update_request map to store network priority. 4053 // Use update_request map to store network priority.
3922 network_update_requests_[service_path] = network_priority_order++; 4054 network_update_requests_[service_path] = network_priority_order++;
3923 wifi_scanning_ = true; 4055 wifi_scanning_ = true;
3924 chromeos::RequestNetworkServiceInfo(service_path.c_str(), 4056 chromeos::RequestNetworkServiceProperties(service_path.c_str(),
3925 &NetworkServiceUpdate, 4057 &NetworkServiceUpdate,
3926 this); 4058 this);
3927 } 4059 }
3928 } 4060 }
3929 // Iterate through list of remaining networks that are no longer in the 4061 // Iterate through list of remaining networks that are no longer in the
3930 // list and delete them or update their status and re-add them to the list. 4062 // list and delete them or update their status and re-add them to the list.
3931 for (NetworkMap::iterator iter = old_network_map.begin(); 4063 for (NetworkMap::iterator iter = old_network_map.begin();
3932 iter != old_network_map.end(); ++iter) { 4064 iter != old_network_map.end(); ++iter) {
3933 Network* network = iter->second; 4065 Network* network = iter->second;
3934 VLOG(2) << "Delete Network: " << network->name() 4066 VLOG(2) << "Delete Network: " << network->name()
3935 << " State = " << network->GetStateString() 4067 << " State = " << network->GetStateString()
3936 << " connecting = " << network->connecting() 4068 << " connecting = " << network->connecting()
(...skipping 22 matching lines...) Expand all
3959 // Existing networks will be updated. There should not be any new networks 4091 // Existing networks will be updated. There should not be any new networks
3960 // in this list, but if there are they will be added appropriately. 4092 // in this list, but if there are they will be added appropriately.
3961 void NetworkLibraryImplCros::UpdateWatchedNetworkServiceList( 4093 void NetworkLibraryImplCros::UpdateWatchedNetworkServiceList(
3962 const ListValue* services) { 4094 const ListValue* services) {
3963 for (ListValue::const_iterator iter = services->begin(); 4095 for (ListValue::const_iterator iter = services->begin();
3964 iter != services->end(); ++iter) { 4096 iter != services->end(); ++iter) {
3965 std::string service_path; 4097 std::string service_path;
3966 (*iter)->GetAsString(&service_path); 4098 (*iter)->GetAsString(&service_path);
3967 if (!service_path.empty()) { 4099 if (!service_path.empty()) {
3968 VLOG(1) << "Watched Service: " << service_path; 4100 VLOG(1) << "Watched Service: " << service_path;
3969 chromeos::RequestNetworkServiceInfo(service_path.c_str(), 4101 chromeos::RequestNetworkServiceProperties(service_path.c_str(),
3970 &NetworkServiceUpdate, 4102 &NetworkServiceUpdate,
3971 this); 4103 this);
3972 } 4104 }
3973 } 4105 }
3974 } 4106 }
3975 4107
3976 // static 4108 // static
3977 void NetworkLibraryImplCros::NetworkServiceUpdate( 4109 void NetworkLibraryImplCros::NetworkServiceUpdate(
3978 void* object, const char* service_path, const Value* info) { 4110 void* object, const char* service_path, GHashTable* ghash) {
3979 NetworkLibraryImplCros* networklib = 4111 NetworkLibraryImplCros* networklib =
3980 static_cast<NetworkLibraryImplCros*>(object); 4112 static_cast<NetworkLibraryImplCros*>(object);
3981 DCHECK(networklib); 4113 DCHECK(networklib);
3982 if (service_path) { 4114 if (service_path) {
3983 if (!info) 4115 if (!ghash)
3984 return; // Network no longer in visible list, ignore. 4116 return; // Network no longer in visible list, ignore.
3985 DCHECK_EQ(info->GetType(), Value::TYPE_DICTIONARY); 4117 scoped_ptr<DictionaryValue> dict(ConvertGHashTable(ghash));
3986 const DictionaryValue* dict = static_cast<const DictionaryValue*>(info); 4118 networklib->ParseNetwork(std::string(service_path), *(dict.get()));
3987 networklib->ParseNetwork(std::string(service_path), *dict);
3988 } 4119 }
3989 } 4120 }
3990 4121
3991 // Called from NetworkServiceUpdate and WifiServiceUpdateAndConnect. 4122 // Called from NetworkServiceUpdate and WifiServiceUpdateAndConnect.
3992 Network* NetworkLibraryImplCros::ParseNetwork( 4123 Network* NetworkLibraryImplCros::ParseNetwork(
3993 const std::string& service_path, const DictionaryValue& info) { 4124 const std::string& service_path, const DictionaryValue& info) {
3994 Network* network = FindNetworkByPath(service_path); 4125 Network* network = FindNetworkByPath(service_path);
3995 if (!network) { 4126 if (!network) {
3996 NativeNetworkParser parser; 4127 NativeNetworkParser parser;
3997 network = parser.CreateNetworkFromInfo(service_path, info); 4128 network = parser.CreateNetworkFromInfo(service_path, info);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
4070 network->SetProfilePath(profile_path); 4201 network->SetProfilePath(profile_path);
4071 } 4202 }
4072 user_networks_.clear(); 4203 user_networks_.clear();
4073 } 4204 }
4074 } 4205 }
4075 } 4206 }
4076 4207
4077 void NetworkLibraryImplCros::RequestRememberedNetworksUpdate() { 4208 void NetworkLibraryImplCros::RequestRememberedNetworksUpdate() {
4078 VLOG(1) << "RequestRememberedNetworksUpdate"; 4209 VLOG(1) << "RequestRememberedNetworksUpdate";
4079 // Delete all remembered networks. We delete them because 4210 // Delete all remembered networks. We delete them because
4080 // RequestNetworkProfile is asynchronous and may invoke 4211 // RequestNetworkProfileProperties is asynchronous and may invoke
4081 // UpdateRememberedServiceList multiple times (once per profile). 4212 // UpdateRememberedServiceList multiple times (once per profile).
4082 // We can do this safely because we do not save any local state for 4213 // We can do this safely because we do not save any local state for
4083 // remembered networks. This list updates infrequently. 4214 // remembered networks. This list updates infrequently.
4084 DeleteRememberedNetworks(); 4215 DeleteRememberedNetworks();
4085 // Request remembered networks from each profile. Later entries will 4216 // Request remembered networks from each profile. Later entries will
4086 // override earlier entries, so default/local entries will override 4217 // override earlier entries, so default/local entries will override
4087 // user entries (as desired). 4218 // user entries (as desired).
4088 for (NetworkProfileList::iterator iter = profile_list_.begin(); 4219 for (NetworkProfileList::iterator iter = profile_list_.begin();
4089 iter != profile_list_.end(); ++iter) { 4220 iter != profile_list_.end(); ++iter) {
4090 NetworkProfile& profile = *iter; 4221 NetworkProfile& profile = *iter;
4091 VLOG(1) << " Requesting Profile: " << profile.path; 4222 VLOG(1) << " Requesting Profile: " << profile.path;
4092 chromeos::RequestNetworkProfile( 4223 chromeos::RequestNetworkProfileProperties(
4093 profile.path.c_str(), &ProfileUpdate, this); 4224 profile.path.c_str(), &ProfileUpdate, this);
4094 } 4225 }
4095 } 4226 }
4096 4227
4097 // static 4228 // static
4098 void NetworkLibraryImplCros::ProfileUpdate( 4229 void NetworkLibraryImplCros::ProfileUpdate(
4099 void* object, const char* profile_path, const Value* info) { 4230 void* object, const char* profile_path, GHashTable* ghash) {
4100 NetworkLibraryImplCros* networklib = 4231 NetworkLibraryImplCros* networklib =
4101 static_cast<NetworkLibraryImplCros*>(object); 4232 static_cast<NetworkLibraryImplCros*>(object);
4102 DCHECK(networklib); 4233 DCHECK(networklib);
4103 if (!info) { 4234 if (!ghash) {
4104 LOG(ERROR) << "Error retrieving profile: " << profile_path; 4235 LOG(ERROR) << "Error retrieving profile: " << profile_path;
4105 return; 4236 return;
4106 } 4237 }
4107 VLOG(1) << "Received ProfileUpdate for: " << profile_path; 4238 VLOG(1) << "Received ProfileUpdate for: " << profile_path;
4108 DCHECK_EQ(info->GetType(), Value::TYPE_DICTIONARY); 4239 scoped_ptr<DictionaryValue> dict(ConvertGHashTable(ghash));
4109 const DictionaryValue* dict = static_cast<const DictionaryValue*>(info);
4110 ListValue* entries(NULL); 4240 ListValue* entries(NULL);
4111 dict->GetList(kEntriesProperty, &entries); 4241 dict->GetList(kEntriesProperty, &entries);
4112 DCHECK(entries); 4242 DCHECK(entries);
4113 networklib->UpdateRememberedServiceList(profile_path, entries); 4243 networklib->UpdateRememberedServiceList(profile_path, entries);
4114 } 4244 }
4115 4245
4116 void NetworkLibraryImplCros::UpdateRememberedServiceList( 4246 void NetworkLibraryImplCros::UpdateRememberedServiceList(
4117 const char* profile_path, const ListValue* profile_entries) { 4247 const char* profile_path, const ListValue* profile_entries) {
4118 DCHECK(profile_path); 4248 DCHECK(profile_path);
4119 VLOG(1) << "UpdateRememberedServiceList for path: " << profile_path; 4249 VLOG(1) << "UpdateRememberedServiceList for path: " << profile_path;
(...skipping 14 matching lines...) Expand all
4134 std::string service_path; 4264 std::string service_path;
4135 (*iter2)->GetAsString(&service_path); 4265 (*iter2)->GetAsString(&service_path);
4136 if (service_path.empty()) { 4266 if (service_path.empty()) {
4137 LOG(WARNING) << "Empty service path in profile."; 4267 LOG(WARNING) << "Empty service path in profile.";
4138 continue; 4268 continue;
4139 } 4269 }
4140 VLOG(1) << " Remembered service: " << service_path; 4270 VLOG(1) << " Remembered service: " << service_path;
4141 // Add service to profile list. 4271 // Add service to profile list.
4142 profile.services.insert(service_path); 4272 profile.services.insert(service_path);
4143 // Request update for remembered network. 4273 // Request update for remembered network.
4144 chromeos::RequestNetworkProfileEntry(profile_path, 4274 chromeos::RequestNetworkProfileEntryProperties(
4145 service_path.c_str(), 4275 profile_path,
4146 &RememberedNetworkServiceUpdate, 4276 service_path.c_str(),
4147 this); 4277 &RememberedNetworkServiceUpdate,
4278 this);
4148 } 4279 }
4149 } 4280 }
4150 4281
4151 // static 4282 // static
4152 void NetworkLibraryImplCros::RememberedNetworkServiceUpdate( 4283 void NetworkLibraryImplCros::RememberedNetworkServiceUpdate(
4153 void* object, const char* service_path, const Value* info) { 4284 void* object, const char* service_path, GHashTable* ghash) {
4154 NetworkLibraryImplCros* networklib = 4285 NetworkLibraryImplCros* networklib =
4155 static_cast<NetworkLibraryImplCros*>(object); 4286 static_cast<NetworkLibraryImplCros*>(object);
4156 DCHECK(networklib); 4287 DCHECK(networklib);
4157 if (service_path) { 4288 if (service_path) {
4158 if (!info) { 4289 if (!ghash) {
4159 // Remembered network no longer exists. 4290 // Remembered network no longer exists.
4160 networklib->DeleteRememberedNetwork(std::string(service_path)); 4291 networklib->DeleteRememberedNetwork(std::string(service_path));
4161 } else { 4292 } else {
4162 DCHECK_EQ(info->GetType(), Value::TYPE_DICTIONARY); 4293 scoped_ptr<DictionaryValue> dict(ConvertGHashTable(ghash));
4163 const DictionaryValue* dict = static_cast<const DictionaryValue*>(info); 4294 networklib->ParseRememberedNetwork(
4164 networklib->ParseRememberedNetwork(std::string(service_path), *dict); 4295 std::string(service_path), *(dict.get()));
4165 } 4296 }
4166 } 4297 }
4167 } 4298 }
4168 4299
4169 // Returns NULL if |service_path| refers to a network that is not a 4300 // Returns NULL if |service_path| refers to a network that is not a
4170 // remembered type. Called from RememberedNetworkServiceUpdate. 4301 // remembered type. Called from RememberedNetworkServiceUpdate.
4171 Network* NetworkLibraryImplCros::ParseRememberedNetwork( 4302 Network* NetworkLibraryImplCros::ParseRememberedNetwork(
4172 const std::string& service_path, const DictionaryValue& info) { 4303 const std::string& service_path, const DictionaryValue& info) {
4173 Network* remembered; 4304 Network* remembered;
4174 NetworkMap::iterator found = remembered_network_map_.find(service_path); 4305 NetworkMap::iterator found = remembered_network_map_.find(service_path);
(...skipping 22 matching lines...) Expand all
4197 4328
4198 if (remembered->type() == TYPE_VPN) { 4329 if (remembered->type() == TYPE_VPN) {
4199 // VPNs are only stored in profiles. If we don't have a network for it, 4330 // VPNs are only stored in profiles. If we don't have a network for it,
4200 // request one. 4331 // request one.
4201 if (!FindNetworkFromRemembered(remembered)) { 4332 if (!FindNetworkFromRemembered(remembered)) {
4202 VirtualNetwork* vpn = static_cast<VirtualNetwork*>(remembered); 4333 VirtualNetwork* vpn = static_cast<VirtualNetwork*>(remembered);
4203 std::string provider_type = ProviderTypeToString(vpn->provider_type()); 4334 std::string provider_type = ProviderTypeToString(vpn->provider_type());
4204 VLOG(1) << "Requesting VPN: " << vpn->name() 4335 VLOG(1) << "Requesting VPN: " << vpn->name()
4205 << " Server: " << vpn->server_hostname() 4336 << " Server: " << vpn->server_hostname()
4206 << " Type: " << provider_type; 4337 << " Type: " << provider_type;
4207 chromeos::RequestVirtualNetwork(vpn->name().c_str(), 4338 chromeos::RequestVirtualNetworkProperties(
4208 vpn->server_hostname().c_str(), 4339 vpn->name().c_str(),
4209 provider_type.c_str(), 4340 vpn->server_hostname().c_str(),
4210 NetworkServiceUpdate, 4341 provider_type.c_str(),
4211 this); 4342 NetworkServiceUpdate,
4343 this);
4212 } 4344 }
4213 } 4345 }
4214 4346
4215 return remembered; 4347 return remembered;
4216 } 4348 }
4217 4349
4218 //////////////////////////////////////////////////////////////////////////// 4350 ////////////////////////////////////////////////////////////////////////////
4219 // NetworkDevice list management functions. 4351 // NetworkDevice list management functions.
4220 4352
4221 // Update device list, and request associated device updates. 4353 // Update device list, and request associated device updates.
4222 // |devices| represents a complete list of devices. 4354 // |devices| represents a complete list of devices.
4223 void NetworkLibraryImplCros::UpdateNetworkDeviceList(const ListValue* devices) { 4355 void NetworkLibraryImplCros::UpdateNetworkDeviceList(const ListValue* devices) {
4224 NetworkDeviceMap old_device_map = device_map_; 4356 NetworkDeviceMap old_device_map = device_map_;
4225 device_map_.clear(); 4357 device_map_.clear();
4226 VLOG(2) << "Updating Device List."; 4358 VLOG(2) << "Updating Device List.";
4227 for (ListValue::const_iterator iter = devices->begin(); 4359 for (ListValue::const_iterator iter = devices->begin();
4228 iter != devices->end(); ++iter) { 4360 iter != devices->end(); ++iter) {
4229 std::string device_path; 4361 std::string device_path;
4230 (*iter)->GetAsString(&device_path); 4362 (*iter)->GetAsString(&device_path);
4231 if (!device_path.empty()) { 4363 if (!device_path.empty()) {
4232 NetworkDeviceMap::iterator found = old_device_map.find(device_path); 4364 NetworkDeviceMap::iterator found = old_device_map.find(device_path);
4233 if (found != old_device_map.end()) { 4365 if (found != old_device_map.end()) {
4234 VLOG(2) << " Adding existing device: " << device_path; 4366 VLOG(2) << " Adding existing device: " << device_path;
4235 CHECK(found->second) << "Attempted to add NULL device pointer"; 4367 CHECK(found->second) << "Attempted to add NULL device pointer";
4236 device_map_[device_path] = found->second; 4368 device_map_[device_path] = found->second;
4237 old_device_map.erase(found); 4369 old_device_map.erase(found);
4238 } 4370 }
4239 chromeos::RequestNetworkDeviceInfo(device_path.c_str(), 4371 chromeos::RequestNetworkDeviceProperties(device_path.c_str(),
4240 &NetworkDeviceUpdate, 4372 &NetworkDeviceUpdate,
4241 this); 4373 this);
4242 } 4374 }
4243 } 4375 }
4244 // Delete any old devices that no longer exist. 4376 // Delete any old devices that no longer exist.
4245 for (NetworkDeviceMap::iterator iter = old_device_map.begin(); 4377 for (NetworkDeviceMap::iterator iter = old_device_map.begin();
4246 iter != old_device_map.end(); ++iter) { 4378 iter != old_device_map.end(); ++iter) {
4247 DeleteDeviceFromDeviceObserversMap(iter->first); 4379 DeleteDeviceFromDeviceObserversMap(iter->first);
4248 // Delete device. 4380 // Delete device.
4249 delete iter->second; 4381 delete iter->second;
4250 } 4382 }
4251 } 4383 }
4252 4384
4253 // static 4385 // static
4254 void NetworkLibraryImplCros::NetworkDeviceUpdate( 4386 void NetworkLibraryImplCros::NetworkDeviceUpdate(
4255 void* object, const char* device_path, const Value* info) { 4387 void* object, const char* device_path, GHashTable* ghash) {
4256 NetworkLibraryImplCros* networklib = 4388 NetworkLibraryImplCros* networklib =
4257 static_cast<NetworkLibraryImplCros*>(object); 4389 static_cast<NetworkLibraryImplCros*>(object);
4258 DCHECK(networklib); 4390 DCHECK(networklib);
4259 if (device_path) { 4391 if (device_path) {
4260 if (!info) { 4392 if (!ghash) {
4261 // device no longer exists. 4393 // device no longer exists.
4262 networklib->DeleteDevice(std::string(device_path)); 4394 networklib->DeleteDevice(std::string(device_path));
4263 } else { 4395 } else {
4264 DCHECK_EQ(info->GetType(), Value::TYPE_DICTIONARY); 4396 scoped_ptr<DictionaryValue> dict(ConvertGHashTable(ghash));
4265 const DictionaryValue* dict = static_cast<const DictionaryValue*>(info); 4397 networklib->ParseNetworkDevice(std::string(device_path), *(dict.get()));
4266 networklib->ParseNetworkDevice(std::string(device_path), *dict);
4267 } 4398 }
4268 } 4399 }
4269 } 4400 }
4270 4401
4271 void NetworkLibraryImplCros::ParseNetworkDevice(const std::string& device_path, 4402 void NetworkLibraryImplCros::ParseNetworkDevice(const std::string& device_path,
4272 const DictionaryValue& info) { 4403 const DictionaryValue& info) {
4273 NetworkDeviceMap::iterator found = device_map_.find(device_path); 4404 NetworkDeviceMap::iterator found = device_map_.find(device_path);
4274 NetworkDevice* device; 4405 NetworkDevice* device;
4275 if (found != device_map_.end()) { 4406 if (found != device_map_.end()) {
4276 device = found->second; 4407 device = found->second;
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
4659 return network_library; 4790 return network_library;
4660 } 4791 }
4661 4792
4662 ///////////////////////////////////////////////////////////////////////////// 4793 /////////////////////////////////////////////////////////////////////////////
4663 4794
4664 } // namespace chromeos 4795 } // namespace chromeos
4665 4796
4666 // Allows InvokeLater without adding refcounting. This class is a Singleton and 4797 // Allows InvokeLater without adding refcounting. This class is a Singleton and
4667 // won't be deleted until its last InvokeLater is run. 4798 // won't be deleted until its last InvokeLater is run.
4668 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::NetworkLibraryImplBase); 4799 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::NetworkLibraryImplBase);
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698