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

Unified Diff: chrome/browser/chromeos/extensions/networking_private_api.cc

Issue 12211103: Adding a new ManagedNetworkConfigurationHandler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleaned up, ready for review. Created 7 years, 10 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 side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698