Index: chrome/browser/chromeos/extensions/networking_private_api.cc |
diff --git a/chrome/browser/chromeos/extensions/networking_private_api.cc b/chrome/browser/chromeos/extensions/networking_private_api.cc |
index 6c1c5d506289fbd8b3b48faae7439f6078e48fa7..303b2c7e2e5cc0f8d90c370f9cf01f99a56c601b 100644 |
--- a/chrome/browser/chromeos/extensions/networking_private_api.cc |
+++ b/chrome/browser/chromeos/extensions/networking_private_api.cc |
@@ -4,7 +4,10 @@ |
#include "chrome/browser/chromeos/extensions/networking_private_api.h" |
+#include "base/bind.h" |
#include "base/bind_helpers.h" |
+#include "base/callback.h" |
+#include "chrome/browser/chromeos/net/managed_network_configuration_handler.h" |
#include "chrome/browser/extensions/extension_function_registry.h" |
#include "chrome/common/extensions/api/networking_private.h" |
#include "chromeos/dbus/dbus_thread_manager.h" |
@@ -25,17 +28,10 @@ namespace { |
// An error returned when no valid services were found. |
const char kInvalidResponseError[] = "Error.invalidResponse"; |
-// This creates a new ONC dictionary that only contains the information we're |
-// interested in passing on to JavaScript. |
+// Filters from the given ONC dictionary the information we're interested in |
+// before passing it to JavaScript. |
scoped_ptr<api::NetworkProperties> CreateFilteredResult( |
- const base::DictionaryValue& properties) { |
- scoped_ptr<base::DictionaryValue> onc_properties( |
- onc::TranslateShillServiceToONCPart( |
- properties, |
- &onc::kNetworkConfigurationSignature)); |
- |
- // Now we filter it so we only include properties that we care about for this |
- // interface. |
+ const base::DictionaryValue& onc_dictionary) { |
static const char* const desired_fields[] = { |
onc::network_config::kWiFi, |
onc::network_config::kName, |
@@ -47,10 +43,12 @@ scoped_ptr<api::NetworkProperties> CreateFilteredResult( |
scoped_ptr<api::NetworkProperties> filtered_result( |
new api::NetworkProperties); |
for (size_t i = 0; i < arraysize(desired_fields); ++i) { |
- base::Value* value; |
- if (onc_properties->Get(desired_fields[i], &value)) |
- filtered_result->additional_properties.Set(desired_fields[i], |
- value->DeepCopy()); |
+ const base::Value* value; |
+ if (onc_dictionary.GetWithoutPathExpansion(desired_fields[i], &value)) { |
+ filtered_result->additional_properties.SetWithoutPathExpansion( |
+ desired_fields[i], |
+ value->DeepCopy()); |
+ } |
} |
return filtered_result.Pass(); |
@@ -141,8 +139,13 @@ void ResultList::ServicePropertiesCallback( |
DBusMethodCallStatus call_status, |
const base::DictionaryValue& result) { |
if (call_status == DBUS_METHOD_CALL_SUCCESS) { |
+ scoped_ptr<base::DictionaryValue> onc_properties( |
+ onc::TranslateShillServiceToONCPart( |
+ result, |
+ &onc::kNetworkConfigurationSignature)); |
+ |
scoped_ptr<api::NetworkProperties> filtered_result( |
- CreateFilteredResult(result)); |
+ CreateFilteredResult(*onc_properties)); |
std::string onc_type; |
if (filtered_result->additional_properties.GetString( |
@@ -177,24 +180,55 @@ bool NetworkingPrivateGetPropertiesFunction::RunImpl() { |
api::GetProperties::Params::Create(*args_); |
EXTENSION_FUNCTION_VALIDATE(params); |
- // TODO(gspencer): Currently we're using the service path as the |
- // |network_guid|. Eventually this should be using the real GUID. |
- DBusThreadManager::Get()->GetShillServiceClient()->GetProperties( |
- dbus::ObjectPath(params->network_guid), |
- base::Bind(&NetworkingPrivateGetPropertiesFunction::ResultCallback, |
- this)); |
+ if (ManagedNetworkConfigurationHandler::IsInitialized()) { |
+ ManagedNetworkConfigurationHandler::Get()->GetProperties( |
+ params->network_guid, |
+ base::Bind( |
+ &NetworkingPrivateGetPropertiesFunction::GetPropertiesSuccess, |
+ this), |
+ base::Bind(&NetworkingPrivateGetPropertiesFunction::GetPropertiesFailed, |
+ this)); |
+ } else { |
+ // TODO(gspencer): Currently we're using the service path as the |
+ // |network_guid|. Eventually this should be using the real GUID. |
+ DBusThreadManager::Get()->GetShillServiceClient()->GetProperties( |
+ dbus::ObjectPath(params->network_guid), |
+ base::Bind(&NetworkingPrivateGetPropertiesFunction::ResultCallback, |
+ this)); |
+ } |
return true; |
} |
void NetworkingPrivateGetPropertiesFunction::ResultCallback( |
DBusMethodCallStatus call_status, |
const base::DictionaryValue& result) { |
+ scoped_ptr<base::DictionaryValue> onc_properties( |
+ onc::TranslateShillServiceToONCPart( |
+ result, |
+ &onc::kNetworkConfigurationSignature)); |
+ |
scoped_ptr<api::NetworkProperties> filtered_result( |
- CreateFilteredResult(result)); |
+ CreateFilteredResult(*onc_properties)); |
results_ = api::GetProperties::Results::Create(*filtered_result); |
SendResponse(true); |
} |
+void NetworkingPrivateGetPropertiesFunction::GetPropertiesSuccess( |
+ const std::string& service_path, |
+ const base::DictionaryValue& dictionary) { |
+ scoped_ptr<api::NetworkProperties> filtered_result( |
+ CreateFilteredResult(dictionary)); |
+ results_ = api::GetProperties::Results::Create(*filtered_result); |
+ SendResponse(true); |
+} |
+ |
+void NetworkingPrivateGetPropertiesFunction::GetPropertiesFailed( |
+ const std::string& error_name, |
+ scoped_ptr<base::DictionaryValue> error_data) { |
+ error_ = error_name; |
+ SendResponse(false); |
+} |
+ |
//////////////////////////////////////////////////////////////////////////////// |
// NetworkingPrivateGetVisibleNetworksFunction |