Commit 5909898a authored by stevenjb@google.com's avatar stevenjb@google.com

Use new GValue chromeos_network calls instead of base::Value

BUG=chromium-os:19576
TEST=Requires updated libcros (166). Ensure tests pass. Thoroughly test Network UI.

Review URL: http://codereview.chromium.org/7765009

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@98737 0039d316-1c4b-4281-b951-d872f2087c98
parent a1d0282c
...@@ -5,6 +5,9 @@ ...@@ -5,6 +5,9 @@
#include "chrome/browser/chromeos/cros/network_library.h" #include "chrome/browser/chromeos/cros/network_library.h"
#include <algorithm> #include <algorithm>
#include <dbus/dbus-glib.h>
#include <dbus/dbus-gtype-specialized.h>
#include <glib-object.h>
#include <map> #include <map>
#include <set> #include <set>
...@@ -69,7 +72,7 @@ ...@@ -69,7 +72,7 @@
// the "Services" message which list all visible networks. The handler // the "Services" message which list all visible networks. The handler
// rebuilds the network lists without destroying existing Network structures, // rebuilds the network lists without destroying existing Network structures,
// then requests neccessary updates to be fetched asynchronously from // then requests neccessary updates to be fetched asynchronously from
// libcros (RequestNetworkServiceInfo). // libcros (RequestNetworkServiceProperties).
// //
// TODO(stevenjb): Document cellular data plan handlers. // TODO(stevenjb): Document cellular data plan handlers.
// //
...@@ -114,17 +117,17 @@ const char* kAlwaysInRoamingOperators[] = { ...@@ -114,17 +117,17 @@ const char* kAlwaysInRoamingOperators[] = {
// Safe string constructor since we can't rely on non NULL pointers // Safe string constructor since we can't rely on non NULL pointers
// for string values from libcros. // for string values from libcros.
static std::string SafeString(const char* s) { std::string SafeString(const char* s) {
return s ? std::string(s) : std::string(); return s ? std::string(s) : std::string();
} }
// Erase the memory used by a string, then clear it. // Erase the memory used by a string, then clear it.
static void WipeString(std::string* str) { void WipeString(std::string* str) {
str->assign(str->size(), '\0'); str->assign(str->size(), '\0');
str->clear(); str->clear();
} }
static bool EnsureCrosLoaded() { bool EnsureCrosLoaded() {
if (!CrosLibrary::Get()->EnsureLoaded() || if (!CrosLibrary::Get()->EnsureLoaded() ||
!CrosLibrary::Get()->GetNetworkLibrary()->IsCros()) { !CrosLibrary::Get()->GetNetworkLibrary()->IsCros()) {
return false; return false;
...@@ -135,7 +138,7 @@ static bool EnsureCrosLoaded() { ...@@ -135,7 +138,7 @@ static bool EnsureCrosLoaded() {
} }
} }
static void ValidateUTF8(const std::string& str, std::string* output) { void ValidateUTF8(const std::string& str, std::string* output) {
output->clear(); output->clear();
for (int32 index = 0; index < static_cast<int32>(str.size()); ++index) { for (int32 index = 0; index < static_cast<int32>(str.size()); ++index) {
...@@ -150,6 +153,136 @@ static void ValidateUTF8(const std::string& str, std::string* output) { ...@@ -150,6 +153,136 @@ static void ValidateUTF8(const std::string& str, std::string* output) {
} }
} }
////////////////////////////////////////////////////////////////////////////////
// glib
Value* ConvertGlibValue(const GValue* gvalue);
void AppendListElement(const GValue* gvalue, gpointer user_data) {
ListValue* list = static_cast<ListValue*>(user_data);
Value* value = ConvertGlibValue(gvalue);
list->Append(value);
}
void AppendDictionaryElement(const GValue* keyvalue,
const GValue* gvalue,
gpointer user_data) {
DictionaryValue* dict = static_cast<DictionaryValue*>(user_data);
std::string key(g_value_get_string(keyvalue));
Value* value = ConvertGlibValue(gvalue);
dict->SetWithoutPathExpansion(key, value);
}
Value* ConvertGlibValue(const GValue* gvalue) {
if (G_VALUE_HOLDS_STRING(gvalue)) {
return Value::CreateStringValue(g_value_get_string(gvalue));
} else if (G_VALUE_HOLDS_BOOLEAN(gvalue)) {
return Value::CreateBooleanValue(
static_cast<bool>(g_value_get_boolean(gvalue)));
} else if (G_VALUE_HOLDS_INT(gvalue)) {
return Value::CreateIntegerValue(g_value_get_int(gvalue));
} else if (G_VALUE_HOLDS_UINT(gvalue)) {
return Value::CreateIntegerValue(
static_cast<int>(g_value_get_uint(gvalue)));
} else if (G_VALUE_HOLDS_UCHAR(gvalue)) {
return Value::CreateIntegerValue(
static_cast<int>(g_value_get_uchar(gvalue)));
} else if (G_VALUE_HOLDS(gvalue, DBUS_TYPE_G_OBJECT_PATH)) {
const char* path = static_cast<const char*>(g_value_get_boxed(gvalue));
return Value::CreateStringValue(path);
} else if (G_VALUE_HOLDS(gvalue, G_TYPE_STRV)) {
ListValue* list = new ListValue();
for (GStrv strv = static_cast<GStrv>(g_value_get_boxed(gvalue));
*strv != NULL; ++strv) {
list->Append(Value::CreateStringValue(*strv));
}
return list;
} else if (dbus_g_type_is_collection(G_VALUE_TYPE(gvalue))) {
ListValue* list = new ListValue();
dbus_g_type_collection_value_iterate(gvalue, AppendListElement, list);
return list;
} else if (dbus_g_type_is_map(G_VALUE_TYPE(gvalue))) {
DictionaryValue* dict = new DictionaryValue();
dbus_g_type_map_value_iterate(gvalue, AppendDictionaryElement, dict);
return dict;
} else if (G_VALUE_HOLDS(gvalue, G_TYPE_VALUE)) {
const GValue* bvalue = static_cast<GValue*>(g_value_get_boxed(gvalue));
return ConvertGlibValue(bvalue);
} else {
LOG(ERROR) << "Unrecognized Glib value type: " << G_VALUE_TYPE(gvalue);
return Value::CreateNullValue();
}
}
DictionaryValue* ConvertGHashTable(GHashTable* ghash) {
DictionaryValue* dict = new DictionaryValue();
GHashTableIter iter;
gpointer gkey, gvalue;
g_hash_table_iter_init(&iter, ghash);
while (g_hash_table_iter_next(&iter, &gkey, &gvalue)) {
std::string key(static_cast<char*>(gkey));
Value* value = ConvertGlibValue(static_cast<GValue*>(gvalue));
dict->SetWithoutPathExpansion(key, value);
}
return dict;
}
GValue* ConvertBoolToGValue(bool b) {
GValue* gvalue = new GValue();
g_value_init(gvalue, G_TYPE_BOOLEAN);
g_value_set_boolean(gvalue, b);
return gvalue;
}
GValue* ConvertIntToGValue(int i) {
// Converting to a 32-bit signed int type in particular, since
// that's what flimflam expects in its DBus API
GValue* gvalue = new GValue();
g_value_init(gvalue, G_TYPE_INT);
g_value_set_int(gvalue, i);
return gvalue;
}
GValue* ConvertStringToGValue(const std::string& s) {
GValue* gvalue = new GValue();
g_value_init(gvalue, G_TYPE_STRING);
g_value_set_string(gvalue, s.c_str());
return gvalue;
}
GValue* ConvertValueToGValue(const Value* value) {
switch (value->GetType()) {
case Value::TYPE_BOOLEAN: {
bool out;
if (value->GetAsBoolean(&out))
return ConvertBoolToGValue(out);
break;
}
case Value::TYPE_INTEGER: {
int out;
if (value->GetAsInteger(&out))
return ConvertIntToGValue(out);
break;
}
case Value::TYPE_STRING: {
std::string out;
if (value->GetAsString(&out))
return ConvertStringToGValue(out);
break;
}
case Value::TYPE_NULL:
case Value::TYPE_DOUBLE:
case Value::TYPE_BINARY:
case Value::TYPE_DICTIONARY:
case Value::TYPE_LIST:
// Other Value types shouldn't be passed through this mechanism.
NOTREACHED() << "Unconverted Value of type: " << value->GetType();
return NULL;
}
NOTREACHED() << "Value conversion failed, type: " << value->GetType();
return NULL;
}
} // namespace } // namespace
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
...@@ -263,12 +396,14 @@ bool Network::RequiresUserProfile() const { ...@@ -263,12 +396,14 @@ bool Network::RequiresUserProfile() const {
void Network::CopyCredentialsFromRemembered(Network* remembered) { void Network::CopyCredentialsFromRemembered(Network* remembered) {
} }
void Network::SetValueProperty(const char* prop, Value* val) { void Network::SetValueProperty(const char* prop, Value* value) {
DCHECK(prop); DCHECK(prop);
DCHECK(val); DCHECK(value);
if (!EnsureCrosLoaded()) if (!EnsureCrosLoaded())
return; return;
chromeos::SetNetworkServiceProperty(service_path_.c_str(), prop, val); scoped_ptr<GValue> gvalue(ConvertValueToGValue(value));
chromeos::SetNetworkServicePropertyGValue(
service_path_.c_str(), prop, gvalue.get());
} }
void Network::ClearProperty(const char* prop) { void Network::ClearProperty(const char* prop) {
...@@ -2987,12 +3122,12 @@ class NetworkLibraryImplCros : public NetworkLibraryImplBase { ...@@ -2987,12 +3122,12 @@ class NetworkLibraryImplCros : public NetworkLibraryImplBase {
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// Calbacks. // Calbacks.
static void NetworkStatusChangedHandler( static void NetworkStatusChangedHandler(
void* object, const char* path, const char* key, const Value* value); void* object, const char* path, const char* key, const GValue* value);
void UpdateNetworkStatus( void UpdateNetworkStatus(
const std::string& path, const std::string& key, const Value& value); const std::string& path, const std::string& key, const Value& value);
static void NetworkDevicePropertyChangedHandler( static void NetworkDevicePropertyChangedHandler(
void* object, const char* path, const char* key, const Value* value); void* object, const char* path, const char* key, const GValue* gvalue);
void UpdateNetworkDeviceStatus( void UpdateNetworkDeviceStatus(
const std::string& path, const std::string& key, const Value& value); const std::string& path, const std::string& key, const Value& value);
...@@ -3012,27 +3147,27 @@ class NetworkLibraryImplCros : public NetworkLibraryImplBase { ...@@ -3012,27 +3147,27 @@ class NetworkLibraryImplCros : public NetworkLibraryImplBase {
const char* error_message); const char* error_message);
static void WifiServiceUpdateAndConnect( static void WifiServiceUpdateAndConnect(
void* object, const char* service_path, const Value* info); void* object, const char* service_path, GHashTable* ghash);
static void VPNServiceUpdateAndConnect( static void VPNServiceUpdateAndConnect(
void* object, const char* service_path, const Value* info); void* object, const char* service_path, GHashTable* ghash);
static void NetworkManagerStatusChangedHandler( static void NetworkManagerStatusChangedHandler(
void* object, const char* path, const char* key, const Value* value); void* object, const char* path, const char* key, const GValue* value);
static void NetworkManagerUpdate( static void NetworkManagerUpdate(
void* object, const char* manager_path, const Value* info); void* object, const char* manager_path, GHashTable* ghash);
static void DataPlanUpdateHandler(void* object, static void DataPlanUpdateHandler(void* object,
const char* modem_service_path, const char* modem_service_path,
const CellularDataPlanList* dataplan); const CellularDataPlanList* dataplan);
static void NetworkServiceUpdate( static void NetworkServiceUpdate(
void* object, const char* service_path, const Value* info); void* object, const char* service_path, GHashTable* ghash);
static void RememberedNetworkServiceUpdate( static void RememberedNetworkServiceUpdate(
void* object, const char* service_path, const Value* info); void* object, const char* service_path, GHashTable* ghash);
static void ProfileUpdate( static void ProfileUpdate(
void* object, const char* profile_path, const Value* info); void* object, const char* profile_path, GHashTable* ghash);
static void NetworkDeviceUpdate( static void NetworkDeviceUpdate(
void* object, const char* device_path, const Value* info); void* object, const char* device_path, GHashTable* ghash);
private: private:
// This processes all Manager update messages. // This processes all Manager update messages.
...@@ -3069,11 +3204,11 @@ class NetworkLibraryImplCros : public NetworkLibraryImplBase { ...@@ -3069,11 +3204,11 @@ class NetworkLibraryImplCros : public NetworkLibraryImplBase {
NetworkLibrary* cros, const NetworkDevice* device) OVERRIDE {} NetworkLibrary* cros, const NetworkDevice* device) OVERRIDE {}
}; };
typedef std::map<std::string, chromeos::PropertyChangeMonitor> typedef std::map<std::string, chromeos::NetworkPropertiesMonitor>
PropertyChangeMonitorMap; NetworkPropertiesMonitorMap;
// For monitoring network manager status changes. // For monitoring network manager status changes.
PropertyChangeMonitor network_manager_monitor_; NetworkPropertiesMonitor network_manager_monitor_;
// For monitoring data plan changes to the connected cellular network. // For monitoring data plan changes to the connected cellular network.
DataPlanUpdateMonitor data_plan_monitor_; DataPlanUpdateMonitor data_plan_monitor_;
...@@ -3082,10 +3217,10 @@ class NetworkLibraryImplCros : public NetworkLibraryImplBase { ...@@ -3082,10 +3217,10 @@ class NetworkLibraryImplCros : public NetworkLibraryImplBase {
scoped_ptr<NetworkLibraryDeviceObserver> network_device_observer_; scoped_ptr<NetworkLibraryDeviceObserver> network_device_observer_;
// Map of monitored networks. // Map of monitored networks.
PropertyChangeMonitorMap montitored_networks_; NetworkPropertiesMonitorMap montitored_networks_;
// Map of monitored devices. // Map of monitored devices.
PropertyChangeMonitorMap montitored_devices_; NetworkPropertiesMonitorMap montitored_devices_;
DISALLOW_COPY_AND_ASSIGN(NetworkLibraryImplCros); DISALLOW_COPY_AND_ASSIGN(NetworkLibraryImplCros);
}; };
...@@ -3100,16 +3235,18 @@ NetworkLibraryImplCros::NetworkLibraryImplCros() ...@@ -3100,16 +3235,18 @@ NetworkLibraryImplCros::NetworkLibraryImplCros()
NetworkLibraryImplCros::~NetworkLibraryImplCros() { NetworkLibraryImplCros::~NetworkLibraryImplCros() {
if (network_manager_monitor_) if (network_manager_monitor_)
chromeos::DisconnectPropertyChangeMonitor(network_manager_monitor_); chromeos::DisconnectNetworkPropertiesMonitor(network_manager_monitor_);
if (data_plan_monitor_) if (data_plan_monitor_)
chromeos::DisconnectDataPlanUpdateMonitor(data_plan_monitor_); chromeos::DisconnectDataPlanUpdateMonitor(data_plan_monitor_);
for (PropertyChangeMonitorMap::iterator iter = montitored_networks_.begin(); for (NetworkPropertiesMonitorMap::iterator iter =
montitored_networks_.begin();
iter != montitored_networks_.end(); ++iter) { iter != montitored_networks_.end(); ++iter) {
chromeos::DisconnectPropertyChangeMonitor(iter->second); chromeos::DisconnectNetworkPropertiesMonitor(iter->second);
} }
for (PropertyChangeMonitorMap::iterator iter = montitored_devices_.begin(); for (NetworkPropertiesMonitorMap::iterator iter =
montitored_devices_.begin();
iter != montitored_devices_.end(); ++iter) { iter != montitored_devices_.end(); ++iter) {
chromeos::DisconnectPropertyChangeMonitor(iter->second); chromeos::DisconnectNetworkPropertiesMonitor(iter->second);
} }
} }
...@@ -3117,10 +3254,10 @@ void NetworkLibraryImplCros::Init() { ...@@ -3117,10 +3254,10 @@ void NetworkLibraryImplCros::Init() {
// First, get the currently available networks. This data is cached // First, get the currently available networks. This data is cached
// on the connman side, so the call should be quick. // on the connman side, so the call should be quick.
VLOG(1) << "Requesting initial network manager info from libcros."; VLOG(1) << "Requesting initial network manager info from libcros.";
chromeos::RequestNetworkManagerInfo(&NetworkManagerUpdate, this); chromeos::RequestNetworkManagerProperties(&NetworkManagerUpdate, this);
network_manager_monitor_ = network_manager_monitor_ =
chromeos::MonitorNetworkManager(&NetworkManagerStatusChangedHandler, chromeos::MonitorNetworkManagerProperties(
this); &NetworkManagerStatusChangedHandler, this);
data_plan_monitor_ = data_plan_monitor_ =
chromeos::MonitorCellularDataPlan(&DataPlanUpdateHandler, this); chromeos::MonitorCellularDataPlan(&DataPlanUpdateHandler, this);
// Always have at least one device obsever so that device updates are // Always have at least one device obsever so that device updates are
...@@ -3134,20 +3271,19 @@ void NetworkLibraryImplCros::Init() { ...@@ -3134,20 +3271,19 @@ void NetworkLibraryImplCros::Init() {
void NetworkLibraryImplCros::MonitorNetworkStart( void NetworkLibraryImplCros::MonitorNetworkStart(
const std::string& service_path) { const std::string& service_path) {
if (montitored_networks_.find(service_path) == montitored_networks_.end()) { if (montitored_networks_.find(service_path) == montitored_networks_.end()) {
chromeos::PropertyChangeMonitor monitor = chromeos::NetworkPropertiesMonitor monitor =
chromeos::MonitorNetworkService(&NetworkStatusChangedHandler, chromeos::MonitorNetworkServiceProperties(
service_path.c_str(), &NetworkStatusChangedHandler, service_path.c_str(), this);
this);
montitored_networks_[service_path] = monitor; montitored_networks_[service_path] = monitor;
} }
} }
void NetworkLibraryImplCros::MonitorNetworkStop( void NetworkLibraryImplCros::MonitorNetworkStop(
const std::string& service_path) { const std::string& service_path) {
PropertyChangeMonitorMap::iterator iter = NetworkPropertiesMonitorMap::iterator iter =
montitored_networks_.find(service_path); montitored_networks_.find(service_path);
if (iter != montitored_networks_.end()) { if (iter != montitored_networks_.end()) {
chromeos::DisconnectPropertyChangeMonitor(iter->second); chromeos::DisconnectNetworkPropertiesMonitor(iter->second);
montitored_networks_.erase(iter); montitored_networks_.erase(iter);
} }
} }
...@@ -3155,32 +3291,32 @@ void NetworkLibraryImplCros::MonitorNetworkStop( ...@@ -3155,32 +3291,32 @@ void NetworkLibraryImplCros::MonitorNetworkStop(
void NetworkLibraryImplCros::MonitorNetworkDeviceStart( void NetworkLibraryImplCros::MonitorNetworkDeviceStart(
const std::string& device_path) { const std::string& device_path) {
if (montitored_devices_.find(device_path) == montitored_devices_.end()) { if (montitored_devices_.find(device_path) == montitored_devices_.end()) {
chromeos::PropertyChangeMonitor monitor = chromeos::NetworkPropertiesMonitor monitor =
chromeos::MonitorNetworkDevice(&NetworkDevicePropertyChangedHandler, chromeos::MonitorNetworkDeviceProperties(
device_path.c_str(), &NetworkDevicePropertyChangedHandler, device_path.c_str(), this);
this);
montitored_devices_[device_path] = monitor; montitored_devices_[device_path] = monitor;
} }
} }
void NetworkLibraryImplCros::MonitorNetworkDeviceStop( void NetworkLibraryImplCros::MonitorNetworkDeviceStop(
const std::string& device_path) { const std::string& device_path) {
PropertyChangeMonitorMap::iterator iter = NetworkPropertiesMonitorMap::iterator iter =
montitored_devices_.find(device_path); montitored_devices_.find(device_path);
if (iter != montitored_devices_.end()) { if (iter != montitored_devices_.end()) {
chromeos::DisconnectPropertyChangeMonitor(iter->second); chromeos::DisconnectNetworkPropertiesMonitor(iter->second);
montitored_devices_.erase(iter); montitored_devices_.erase(iter);
} }
} }
// static callback // static callback
void NetworkLibraryImplCros::NetworkStatusChangedHandler( void NetworkLibraryImplCros::NetworkStatusChangedHandler(
void* object, const char* path, const char* key, const Value* value) { void* object, const char* path, const char* key, const GValue* gvalue) {
NetworkLibraryImplCros* networklib = NetworkLibraryImplCros* networklib =
static_cast<NetworkLibraryImplCros*>(object); static_cast<NetworkLibraryImplCros*>(object);
DCHECK(networklib); DCHECK(networklib);
if (key == NULL || value == NULL || path == NULL || object == NULL) if (key == NULL || gvalue == NULL || path == NULL || object == NULL)
return; return;
scoped_ptr<Value> value(ConvertGlibValue(gvalue));
networklib->UpdateNetworkStatus(std::string(path), std::string(key), *value); networklib->UpdateNetworkStatus(std::string(path), std::string(key), *value);
} }
...@@ -3206,12 +3342,13 @@ void NetworkLibraryImplCros::UpdateNetworkStatus( ...@@ -3206,12 +3342,13 @@ void NetworkLibraryImplCros::UpdateNetworkStatus(
// static callback // static callback
void NetworkLibraryImplCros::NetworkDevicePropertyChangedHandler( void NetworkLibraryImplCros::NetworkDevicePropertyChangedHandler(
void* object, const char* path, const char* key, const Value* value) { void* object, const char* path, const char* key, const GValue* gvalue) {
NetworkLibraryImplCros* networklib = NetworkLibraryImplCros* networklib =
static_cast<NetworkLibraryImplCros*>(object); static_cast<NetworkLibraryImplCros*>(object);
DCHECK(networklib); DCHECK(networklib);
if (key == NULL || value == NULL || path == NULL || object == NULL) if (key == NULL || gvalue == NULL || path == NULL || object == NULL)
return; return;
scoped_ptr<Value> value(ConvertGlibValue(gvalue));
networklib->UpdateNetworkDeviceStatus(std::string(path), networklib->UpdateNetworkDeviceStatus(std::string(path),
std::string(key), std::string(key),
*value); *value);
...@@ -3246,7 +3383,7 @@ void NetworkLibraryImplCros::UpdateNetworkDeviceStatus( ...@@ -3246,7 +3383,7 @@ void NetworkLibraryImplCros::UpdateNetworkDeviceStatus(
NotifyNetworkDeviceChanged(device, index); NotifyNetworkDeviceChanged(device, index);
// If a device's power state changes, new properties may become defined. // If a device's power state changes, new properties may become defined.
if (index == PROPERTY_INDEX_POWERED) if (index == PROPERTY_INDEX_POWERED)
chromeos::RequestNetworkDeviceInfo(path.c_str(), chromeos::RequestNetworkDeviceProperties(path.c_str(),
&NetworkDeviceUpdate, &NetworkDeviceUpdate,
this); this);
} }
...@@ -3293,15 +3430,14 @@ void NetworkLibraryImplCros::CallConnectToNetwork(Network* network) { ...@@ -3293,15 +3430,14 @@ void NetworkLibraryImplCros::CallConnectToNetwork(Network* network) {
// static callback // static callback
void NetworkLibraryImplCros::WifiServiceUpdateAndConnect( void NetworkLibraryImplCros::WifiServiceUpdateAndConnect(
void* object, const char* service_path, const Value* info) { void* object, const char* service_path, GHashTable* ghash) {
NetworkLibraryImplCros* networklib = NetworkLibraryImplCros* networklib =
static_cast<NetworkLibraryImplCros*>(object); static_cast<NetworkLibraryImplCros*>(object);
DCHECK(networklib); DCHECK(networklib);
if (service_path && info) { if (service_path && ghash) {
DCHECK_EQ(info->GetType(), Value::TYPE_DICTIONARY); scoped_ptr<DictionaryValue> dict(ConvertGHashTable(ghash));
const DictionaryValue* dict = static_cast<const DictionaryValue*>(info);
Network* network = Network* network =
networklib->ParseNetwork(std::string(service_path), *dict); networklib->ParseNetwork(std::string(service_path), *(dict.get()));
DCHECK_EQ(network->type(), TYPE_WIFI); DCHECK_EQ(network->type(), TYPE_WIFI);
networklib->ConnectToWifiNetworkUsingConnectData( networklib->ConnectToWifiNetworkUsingConnectData(
static_cast<WifiNetwork*>(network)); static_cast<WifiNetwork*>(network));
...@@ -3312,7 +3448,8 @@ void NetworkLibraryImplCros::CallRequestWifiNetworkAndConnect( ...@@ -3312,7 +3448,8 @@ void NetworkLibraryImplCros::CallRequestWifiNetworkAndConnect(
const std::string& ssid, ConnectionSecurity security) { const std::string& ssid, ConnectionSecurity security) {
// Asynchronously request service properties and call // Asynchronously request service properties and call
// WifiServiceUpdateAndConnect. // WifiServiceUpdateAndConnect.
chromeos::RequestHiddenWifiNetwork(ssid.c_str(), chromeos::RequestHiddenWifiNetworkProperties(
ssid.c_str(),
SecurityToString(security), SecurityToString(security),
WifiServiceUpdateAndConnect, WifiServiceUpdateAndConnect,
this); this);
...@@ -3320,16 +3457,15 @@ void NetworkLibraryImplCros::CallRequestWifiNetworkAndConnect( ...@@ -3320,16 +3457,15 @@ void NetworkLibraryImplCros::CallRequestWifiNetworkAndConnect(
// static callback // static callback
void NetworkLibraryImplCros::VPNServiceUpdateAndConnect( void NetworkLibraryImplCros::VPNServiceUpdateAndConnect(
void* object, const char* service_path, const Value* info) { void* object, const char* service_path, GHashTable* ghash) {
NetworkLibraryImplCros* networklib = NetworkLibraryImplCros* networklib =
static_cast<NetworkLibraryImplCros*>(object); static_cast<NetworkLibraryImplCros*>(object);
DCHECK(networklib); DCHECK(networklib);
if (service_path && info) { if (service_path && ghash) {
VLOG(1) << "Connecting to new VPN Service: " << service_path; VLOG(1) << "Connecting to new VPN Service: " << service_path;
DCHECK_EQ(info->GetType(), Value::TYPE_DICTIONARY); scoped_ptr<DictionaryValue> dict(ConvertGHashTable(ghash));
const DictionaryValue* dict = static_cast<const DictionaryValue*>(info);
Network* network = Network* network =
networklib->ParseNetwork(std::string(service_path), *dict); networklib->ParseNetwork(std::string(service_path), *(dict.get()));
DCHECK_EQ(network->type(), TYPE_VPN); DCHECK_EQ(network->type(), TYPE_VPN);
networklib->ConnectToVirtualNetworkUsingConnectData( networklib->ConnectToVirtualNetworkUsingConnectData(
static_cast<VirtualNetwork*>(network)); static_cast<VirtualNetwork*>(network));
...@@ -3342,7 +3478,8 @@ void NetworkLibraryImplCros::CallRequestVirtualNetworkAndConnect( ...@@ -3342,7 +3478,8 @@ void NetworkLibraryImplCros::CallRequestVirtualNetworkAndConnect(
const std::string& service_name, const std::string& service_name,
const std::string& server_hostname, const std::string& server_hostname,
ProviderType provider_type) { ProviderType provider_type) {
chromeos::RequestVirtualNetwork(service_name.c_str(), chromeos::RequestVirtualNetworkProperties(
service_name.c_str(),
server_hostname.c_str(), server_hostname.c_str(),
ProviderTypeToString(provider_type), ProviderTypeToString(provider_type),
VPNServiceUpdateAndConnect, VPNServiceUpdateAndConnect,
...@@ -3489,10 +3626,10 @@ void NetworkLibraryImplCros::SetCellularDataRoamingAllowed(bool new_value) { ...@@ -3489,10 +3626,10 @@ void NetworkLibraryImplCros::SetCellularDataRoamingAllowed(bool new_value) {
"w/o cellular device."; "w/o cellular device.";
return; return;
} }
scoped_ptr<Value> value(Value::CreateBooleanValue(new_value)); scoped_ptr<GValue> gvalue(ConvertBoolToGValue(new_value));
chromeos::SetNetworkDeviceProperty(cellular->device_path().c_str(), chromeos::SetNetworkDevicePropertyGValue(cellular->device_path().c_str(),
kCellularAllowRoamingProperty, kCellularAllowRoamingProperty,
value.get()); gvalue.get());
} }
bool NetworkLibraryImplCros::IsCellularAlwaysInRoaming() { bool NetworkLibraryImplCros::IsCellularAlwaysInRoaming() {
...@@ -3519,7 +3656,7 @@ void NetworkLibraryImplCros::RequestNetworkScan() { ...@@ -3519,7 +3656,7 @@ void NetworkLibraryImplCros::RequestNetworkScan() {
cellular_network()->RefreshDataPlansIfNeeded(); cellular_network()->RefreshDataPlansIfNeeded();
// Make sure all Manager info is up to date. This will also update // Make sure all Manager info is up to date. This will also update
// remembered networks and visible services. // remembered networks and visible services.
chromeos::RequestNetworkManagerInfo(&NetworkManagerUpdate, this); chromeos::RequestNetworkManagerProperties(&NetworkManagerUpdate, this);
} }
bool NetworkLibraryImplCros::GetWifiAccessPoints( bool NetworkLibraryImplCros::GetWifiAccessPoints(
...@@ -3650,35 +3787,30 @@ void NetworkLibraryImplCros::SetIPConfig(const NetworkIPConfig& ipconfig) { ...@@ -3650,35 +3787,30 @@ void NetworkLibraryImplCros::SetIPConfig(const NetworkIPConfig& ipconfig) {
if (ipconfig_static) { if (ipconfig_static) {
// Save any changed details. // Save any changed details.
if (ipconfig.address != ipconfig_static->address) { if (ipconfig.address != ipconfig_static->address) {
scoped_ptr<Value> value(Value::CreateStringValue(ipconfig.address)); scoped_ptr<GValue> gvalue(ConvertStringToGValue(ipconfig.address));
chromeos::SetNetworkIPConfigProperty(ipconfig_static->path, chromeos::SetNetworkIPConfigPropertyGValue(
kAddressProperty, ipconfig_static->path, kAddressProperty, gvalue.get());
value.get());
} }
if (ipconfig.netmask != ipconfig_static->netmask) { if (ipconfig.netmask != ipconfig_static->netmask) {
int32 prefixlen = ipconfig.GetPrefixLength(); int prefixlen = ipconfig.GetPrefixLength();
if (prefixlen == -1) { if (prefixlen == -1) {
VLOG(1) << "IP config prefixlen is invalid for netmask " VLOG(1) << "IP config prefixlen is invalid for netmask "
<< ipconfig.netmask; << ipconfig.netmask;
} else { } else {
scoped_ptr<Value> value(Value::CreateIntegerValue(prefixlen)); scoped_ptr<GValue> gvalue(ConvertIntToGValue(prefixlen));
chromeos::SetNetworkIPConfigProperty(ipconfig_static->path, chromeos::SetNetworkIPConfigPropertyGValue(
kPrefixlenProperty, ipconfig_static->path, kPrefixlenProperty, gvalue.get());
value.get());
} }
} }
if (ipconfig.gateway != ipconfig_static->gateway) { if (ipconfig.gateway != ipconfig_static->gateway) {
scoped_ptr<Value> value(Value::CreateStringValue(ipconfig.gateway)); scoped_ptr<GValue> gvalue(ConvertStringToGValue(ipconfig.gateway));
chromeos::SetNetworkIPConfigProperty(ipconfig_static->path, chromeos::SetNetworkIPConfigPropertyGValue(
kGatewayProperty, ipconfig_static->path, kGatewayProperty, gvalue.get());
value.get());
} }
if (ipconfig.name_servers != ipconfig_static->name_servers) { if (ipconfig.name_servers != ipconfig_static->name_servers) {
scoped_ptr<Value> value( scoped_ptr<GValue> gvalue(ConvertStringToGValue(ipconfig.name_servers));
Value::CreateStringValue(ipconfig.name_servers)); chromeos::SetNetworkIPConfigPropertyGValue(
chromeos::SetNetworkIPConfigProperty(ipconfig_static->path, ipconfig_static->path, kNameServersProperty, gvalue.get());
kNameServersProperty,
value.get());
} }
// Remove dhcp ip config if there is one. // Remove dhcp ip config if there is one.
if (ipconfig_dhcp) if (ipconfig_dhcp)
...@@ -3697,11 +3829,12 @@ void NetworkLibraryImplCros::SetIPConfig(const NetworkIPConfig& ipconfig) { ...@@ -3697,11 +3829,12 @@ void NetworkLibraryImplCros::SetIPConfig(const NetworkIPConfig& ipconfig) {
// static // static
void NetworkLibraryImplCros::NetworkManagerStatusChangedHandler( void NetworkLibraryImplCros::NetworkManagerStatusChangedHandler(
void* object, const char* path, const char* key, const Value* value) { void* object, const char* path, const char* key, const GValue* gvalue) {
NetworkLibraryImplCros* networklib = NetworkLibraryImplCros* networklib =
static_cast<NetworkLibraryImplCros*>(object); static_cast<NetworkLibraryImplCros*>(object);
DCHECK(networklib); DCHECK(networklib);
networklib->NetworkManagerStatusChanged(key, value); scoped_ptr<Value> value(ConvertGlibValue(gvalue));
networklib->NetworkManagerStatusChanged(key, value.get());
} }
// This processes all Manager update messages. // This processes all Manager update messages.
...@@ -3797,18 +3930,17 @@ void NetworkLibraryImplCros::NetworkManagerStatusChanged( ...@@ -3797,18 +3930,17 @@ void NetworkLibraryImplCros::NetworkManagerStatusChanged(
// static // static
void NetworkLibraryImplCros::NetworkManagerUpdate( void NetworkLibraryImplCros::NetworkManagerUpdate(
void* object, const char* manager_path, const Value* info) { void* object, const char* manager_path, GHashTable* ghash) {
NetworkLibraryImplCros* networklib = NetworkLibraryImplCros* networklib =
static_cast<NetworkLibraryImplCros*>(object); static_cast<NetworkLibraryImplCros*>(object);
DCHECK(networklib); DCHECK(networklib);
if (!info) { if (!ghash) {
LOG(ERROR) << "Error retrieving manager properties: " << manager_path; LOG(ERROR) << "Error retrieving manager properties: " << manager_path;
return; return;
} }
VLOG(1) << "Received NetworkManagerUpdate."; VLOG(1) << "Received NetworkManagerUpdate.";
DCHECK_EQ(info->GetType(), Value::TYPE_DICTIONARY); scoped_ptr<DictionaryValue> dict(ConvertGHashTable(ghash));
const DictionaryValue* dict = static_cast<const DictionaryValue*>(info); networklib->ParseNetworkManager(*(dict.get()));
networklib->ParseNetworkManager(*dict);
} }
void NetworkLibraryImplCros::ParseNetworkManager(const DictionaryValue& dict) { void NetworkLibraryImplCros::ParseNetworkManager(const DictionaryValue& dict) {
...@@ -3921,7 +4053,7 @@ void NetworkLibraryImplCros::UpdateNetworkServiceList( ...@@ -3921,7 +4053,7 @@ void NetworkLibraryImplCros::UpdateNetworkServiceList(
// Use update_request map to store network priority. // Use update_request map to store network priority.
network_update_requests_[service_path] = network_priority_order++; network_update_requests_[service_path] = network_priority_order++;
wifi_scanning_ = true; wifi_scanning_ = true;
chromeos::RequestNetworkServiceInfo(service_path.c_str(), chromeos::RequestNetworkServiceProperties(service_path.c_str(),
&NetworkServiceUpdate, &NetworkServiceUpdate,
this); this);
} }
...@@ -3966,7 +4098,7 @@ void NetworkLibraryImplCros::UpdateWatchedNetworkServiceList( ...@@ -3966,7 +4098,7 @@ void NetworkLibraryImplCros::UpdateWatchedNetworkServiceList(
(*iter)->GetAsString(&service_path); (*iter)->GetAsString(&service_path);
if (!service_path.empty()) { if (!service_path.empty()) {
VLOG(1) << "Watched Service: " << service_path; VLOG(1) << "Watched Service: " << service_path;
chromeos::RequestNetworkServiceInfo(service_path.c_str(), chromeos::RequestNetworkServiceProperties(service_path.c_str(),
&NetworkServiceUpdate, &NetworkServiceUpdate,
this); this);
} }
...@@ -3975,16 +4107,15 @@ void NetworkLibraryImplCros::UpdateWatchedNetworkServiceList( ...@@ -3975,16 +4107,15 @@ void NetworkLibraryImplCros::UpdateWatchedNetworkServiceList(
// static // static
void NetworkLibraryImplCros::NetworkServiceUpdate( void NetworkLibraryImplCros::NetworkServiceUpdate(
void* object, const char* service_path, const Value* info) { void* object, const char* service_path, GHashTable* ghash) {
NetworkLibraryImplCros* networklib = NetworkLibraryImplCros* networklib =
static_cast<NetworkLibraryImplCros*>(object); static_cast<NetworkLibraryImplCros*>(object);
DCHECK(networklib); DCHECK(networklib);
if (service_path) { if (service_path) {
if (!info) if (!ghash)
return; // Network no longer in visible list, ignore. return; // Network no longer in visible list, ignore.
DCHECK_EQ(info->GetType(), Value::TYPE_DICTIONARY); scoped_ptr<DictionaryValue> dict(ConvertGHashTable(ghash));
const DictionaryValue* dict = static_cast<const DictionaryValue*>(info); networklib->ParseNetwork(std::string(service_path), *(dict.get()));
networklib->ParseNetwork(std::string(service_path), *dict);
} }
} }
...@@ -4077,7 +4208,7 @@ void NetworkLibraryImplCros::UpdateRememberedNetworks( ...@@ -4077,7 +4208,7 @@ void NetworkLibraryImplCros::UpdateRememberedNetworks(
void NetworkLibraryImplCros::RequestRememberedNetworksUpdate() { void NetworkLibraryImplCros::RequestRememberedNetworksUpdate() {
VLOG(1) << "RequestRememberedNetworksUpdate"; VLOG(1) << "RequestRememberedNetworksUpdate";
// Delete all remembered networks. We delete them because // Delete all remembered networks. We delete them because
// RequestNetworkProfile is asynchronous and may invoke // RequestNetworkProfileProperties is asynchronous and may invoke
// UpdateRememberedServiceList multiple times (once per profile). // UpdateRememberedServiceList multiple times (once per profile).
// We can do this safely because we do not save any local state for // We can do this safely because we do not save any local state for
// remembered networks. This list updates infrequently. // remembered networks. This list updates infrequently.
...@@ -4089,24 +4220,23 @@ void NetworkLibraryImplCros::RequestRememberedNetworksUpdate() { ...@@ -4089,24 +4220,23 @@ void NetworkLibraryImplCros::RequestRememberedNetworksUpdate() {
iter != profile_list_.end(); ++iter) { iter != profile_list_.end(); ++iter) {
NetworkProfile& profile = *iter; NetworkProfile& profile = *iter;
VLOG(1) << " Requesting Profile: " << profile.path; VLOG(1) << " Requesting Profile: " << profile.path;
chromeos::RequestNetworkProfile( chromeos::RequestNetworkProfileProperties(
profile.path.c_str(), &ProfileUpdate, this); profile.path.c_str(), &ProfileUpdate, this);
} }
} }
// static // static
void NetworkLibraryImplCros::ProfileUpdate( void NetworkLibraryImplCros::ProfileUpdate(
void* object, const char* profile_path, const Value* info) { void* object, const char* profile_path, GHashTable* ghash) {
NetworkLibraryImplCros* networklib = NetworkLibraryImplCros* networklib =
static_cast<NetworkLibraryImplCros*>(object); static_cast<NetworkLibraryImplCros*>(object);
DCHECK(networklib); DCHECK(networklib);
if (!info) { if (!ghash) {
LOG(ERROR) << "Error retrieving profile: " << profile_path; LOG(ERROR) << "Error retrieving profile: " << profile_path;
return; return;
} }
VLOG(1) << "Received ProfileUpdate for: " << profile_path; VLOG(1) << "Received ProfileUpdate for: " << profile_path;
DCHECK_EQ(info->GetType(), Value::TYPE_DICTIONARY); scoped_ptr<DictionaryValue> dict(ConvertGHashTable(ghash));
const DictionaryValue* dict = static_cast<const DictionaryValue*>(info);
ListValue* entries(NULL); ListValue* entries(NULL);
dict->GetList(kEntriesProperty, &entries); dict->GetList(kEntriesProperty, &entries);
DCHECK(entries); DCHECK(entries);
...@@ -4141,7 +4271,8 @@ void NetworkLibraryImplCros::UpdateRememberedServiceList( ...@@ -4141,7 +4271,8 @@ void NetworkLibraryImplCros::UpdateRememberedServiceList(
// Add service to profile list. // Add service to profile list.
profile.services.insert(service_path); profile.services.insert(service_path);
// Request update for remembered network. // Request update for remembered network.
chromeos::RequestNetworkProfileEntry(profile_path, chromeos::RequestNetworkProfileEntryProperties(
profile_path,
service_path.c_str(), service_path.c_str(),
&RememberedNetworkServiceUpdate, &RememberedNetworkServiceUpdate,
this); this);
...@@ -4150,18 +4281,18 @@ void NetworkLibraryImplCros::UpdateRememberedServiceList( ...@@ -4150,18 +4281,18 @@ void NetworkLibraryImplCros::UpdateRememberedServiceList(
// static // static
void NetworkLibraryImplCros::RememberedNetworkServiceUpdate( void NetworkLibraryImplCros::RememberedNetworkServiceUpdate(
void* object, const char* service_path, const Value* info) { void* object, const char* service_path, GHashTable* ghash) {
NetworkLibraryImplCros* networklib = NetworkLibraryImplCros* networklib =
static_cast<NetworkLibraryImplCros*>(object); static_cast<NetworkLibraryImplCros*>(object);
DCHECK(networklib); DCHECK(networklib);
if (service_path) { if (service_path) {
if (!info) { if (!ghash) {
// Remembered network no longer exists. // Remembered network no longer exists.
networklib->DeleteRememberedNetwork(std::string(service_path)); networklib->DeleteRememberedNetwork(std::string(service_path));
} else { } else {
DCHECK_EQ(info->GetType(), Value::TYPE_DICTIONARY); scoped_ptr<DictionaryValue> dict(ConvertGHashTable(ghash));
const DictionaryValue* dict = static_cast<const DictionaryValue*>(info); networklib->ParseRememberedNetwork(
networklib->ParseRememberedNetwork(std::string(service_path), *dict); std::string(service_path), *(dict.get()));
} }
} }
} }
...@@ -4204,7 +4335,8 @@ Network* NetworkLibraryImplCros::ParseRememberedNetwork( ...@@ -4204,7 +4335,8 @@ Network* NetworkLibraryImplCros::ParseRememberedNetwork(
VLOG(1) << "Requesting VPN: " << vpn->name() VLOG(1) << "Requesting VPN: " << vpn->name()
<< " Server: " << vpn->server_hostname() << " Server: " << vpn->server_hostname()
<< " Type: " << provider_type; << " Type: " << provider_type;
chromeos::RequestVirtualNetwork(vpn->name().c_str(), chromeos::RequestVirtualNetworkProperties(
vpn->name().c_str(),
vpn->server_hostname().c_str(), vpn->server_hostname().c_str(),
provider_type.c_str(), provider_type.c_str(),
NetworkServiceUpdate, NetworkServiceUpdate,
...@@ -4236,7 +4368,7 @@ void NetworkLibraryImplCros::UpdateNetworkDeviceList(const ListValue* devices) { ...@@ -4236,7 +4368,7 @@ void NetworkLibraryImplCros::UpdateNetworkDeviceList(const ListValue* devices) {
device_map_[device_path] = found->second; device_map_[device_path] = found->second;
old_device_map.erase(found); old_device_map.erase(found);
} }
chromeos::RequestNetworkDeviceInfo(device_path.c_str(), chromeos::RequestNetworkDeviceProperties(device_path.c_str(),
&NetworkDeviceUpdate, &NetworkDeviceUpdate,
this); this);
} }
...@@ -4252,18 +4384,17 @@ void NetworkLibraryImplCros::UpdateNetworkDeviceList(const ListValue* devices) { ...@@ -4252,18 +4384,17 @@ void NetworkLibraryImplCros::UpdateNetworkDeviceList(const ListValue* devices) {
// static // static
void NetworkLibraryImplCros::NetworkDeviceUpdate( void NetworkLibraryImplCros::NetworkDeviceUpdate(
void* object, const char* device_path, const Value* info) { void* object, const char* device_path, GHashTable* ghash) {
NetworkLibraryImplCros* networklib = NetworkLibraryImplCros* networklib =
static_cast<NetworkLibraryImplCros*>(object); static_cast<NetworkLibraryImplCros*>(object);
DCHECK(networklib); DCHECK(networklib);
if (device_path) { if (device_path) {
if (!info) { if (!ghash) {
// device no longer exists. // device no longer exists.
networklib->DeleteDevice(std::string(device_path)); networklib->DeleteDevice(std::string(device_path));
} else { } else {
DCHECK_EQ(info->GetType(), Value::TYPE_DICTIONARY); scoped_ptr<DictionaryValue> dict(ConvertGHashTable(ghash));
const DictionaryValue* dict = static_cast<const DictionaryValue*>(info); networklib->ParseNetworkDevice(std::string(device_path), *(dict.get()));
networklib->ParseNetworkDevice(std::string(device_path), *dict);
} }
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment