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

Unified Diff: chrome/browser/extensions/api/networking_private/networking_private_api.cc

Issue 378103002: Add NetworkingPrivateDelegate class (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix ServiceClient Created 6 years, 5 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/extensions/api/networking_private/networking_private_api.cc
diff --git a/chrome/browser/extensions/api/networking_private/networking_private_api.cc b/chrome/browser/extensions/api/networking_private/networking_private_api.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f4b3a347b9648120047a7c4cd11de668b05a36eb
--- /dev/null
+++ b/chrome/browser/extensions/api/networking_private/networking_private_api.cc
@@ -0,0 +1,597 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
mef 2014/07/10 15:09:11 2014?
stevenjb 2014/07/10 18:04:20 Done.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/extensions/api/networking_private/networking_private_api.h"
+
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "base/callback.h"
+#include "chrome/browser/extensions/api/networking_private/networking_private_delegate.h"
+#include "chrome/common/extensions/api/networking_private.h"
+#include "extensions/browser/extension_function_registry.h"
+
+namespace {
+
+const int kDefaultNetworkListLimit = 1000;
+
+extensions::NetworkingPrivateDelegate* GetDelegate(
+ content::BrowserContext* browser_context) {
+ return extensions::NetworkingPrivateDelegate::GetForBrowserContext(
+ browser_context);
+}
+
+} // namespace
+
+namespace private_api = extensions::api::networking_private;
+
+namespace extensions {
+
+namespace networking_private {
+
+// static
+const char kErrorInvalidNetworkGuid[] = "Error.InvalidNetworkGuid";
+const char kErrorNetworkUnavailable[] = "Error.NetworkUnavailable";
+const char kErrorNotReady[] = "Error.NotReady";
+const char kErrorNotSupported[] = "Error.NotSupported";
+
+} // namespace networking_private
+
+////////////////////////////////////////////////////////////////////////////////
+// NetworkingPrivateGetPropertiesFunction
+
+NetworkingPrivateGetPropertiesFunction::
+ ~NetworkingPrivateGetPropertiesFunction() {
+}
+
+bool NetworkingPrivateGetPropertiesFunction::RunAsync() {
+ scoped_ptr<private_api::GetProperties::Params> params =
+ private_api::GetProperties::Params::Create(*args_);
+ EXTENSION_FUNCTION_VALIDATE(params);
+
+ GetDelegate(browser_context())->GetProperties(
+ params->network_guid,
+ base::Bind(&NetworkingPrivateGetPropertiesFunction::Success, this),
+ base::Bind(&NetworkingPrivateGetPropertiesFunction::Failure, this));
+ return true;
+}
+
+void NetworkingPrivateGetPropertiesFunction::Success(
+ scoped_ptr<base::DictionaryValue> result) {
+ SetResult(result.release());
+ SendResponse(true);
+}
+
+void NetworkingPrivateGetPropertiesFunction::Failure(const std::string& error) {
+ error_ = error;
+ SendResponse(false);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// NetworkingPrivateGetManagedPropertiesFunction
+
+NetworkingPrivateGetManagedPropertiesFunction::
+ ~NetworkingPrivateGetManagedPropertiesFunction() {
+}
+
+bool NetworkingPrivateGetManagedPropertiesFunction::RunAsync() {
+ scoped_ptr<private_api::GetManagedProperties::Params> params =
+ private_api::GetManagedProperties::Params::Create(*args_);
+ EXTENSION_FUNCTION_VALIDATE(params);
+
+ GetDelegate(browser_context())->GetManagedProperties(
+ params->network_guid,
+ base::Bind(&NetworkingPrivateGetManagedPropertiesFunction::Success, this),
+ base::Bind(&NetworkingPrivateGetManagedPropertiesFunction::Failure,
+ this));
+ return true;
+}
+
+void NetworkingPrivateGetManagedPropertiesFunction::Success(
+ scoped_ptr<base::DictionaryValue> result) {
+ SetResult(result.release());
+ SendResponse(true);
+}
+
+void NetworkingPrivateGetManagedPropertiesFunction::Failure(
+ const std::string& error) {
+ error_ = error;
+ SendResponse(false);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// NetworkingPrivateGetStateFunction
+
+NetworkingPrivateGetStateFunction::~NetworkingPrivateGetStateFunction() {
+}
+
+bool NetworkingPrivateGetStateFunction::RunAsync() {
+ scoped_ptr<private_api::GetState::Params> params =
+ private_api::GetState::Params::Create(*args_);
+ EXTENSION_FUNCTION_VALIDATE(params);
+
+ GetDelegate(browser_context())->GetState(
+ params->network_guid,
+ base::Bind(&NetworkingPrivateGetStateFunction::Success, this),
+ base::Bind(&NetworkingPrivateGetStateFunction::Failure, this));
+ return true;
+}
+
+void NetworkingPrivateGetStateFunction::Success(
+ scoped_ptr<base::DictionaryValue> result) {
+ SetResult(result.release());
+ SendResponse(true);
+}
+
+void NetworkingPrivateGetStateFunction::Failure(const std::string& error) {
+ error_ = error;
+ SendResponse(false);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// NetworkingPrivateSetPropertiesFunction
+
+NetworkingPrivateSetPropertiesFunction::
+ ~NetworkingPrivateSetPropertiesFunction() {
+}
+
+bool NetworkingPrivateSetPropertiesFunction::RunAsync() {
+ scoped_ptr<private_api::SetProperties::Params> params =
+ private_api::SetProperties::Params::Create(*args_);
+ EXTENSION_FUNCTION_VALIDATE(params);
+
+ scoped_ptr<base::DictionaryValue> properties_dict(
+ params->properties.ToValue());
+
+ GetDelegate(browser_context())->SetProperties(
+ params->network_guid,
+ properties_dict.Pass(),
+ base::Bind(&NetworkingPrivateSetPropertiesFunction::Success, this),
+ base::Bind(&NetworkingPrivateSetPropertiesFunction::Failure, this));
+ return true;
+}
+
+void NetworkingPrivateSetPropertiesFunction::Success() {
+ SendResponse(true);
+}
+
+void NetworkingPrivateSetPropertiesFunction::Failure(const std::string& error) {
+ error_ = error;
+ SendResponse(false);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// NetworkingPrivateCreateNetworkFunction
+
+NetworkingPrivateCreateNetworkFunction::
+ ~NetworkingPrivateCreateNetworkFunction() {
+}
+
+bool NetworkingPrivateCreateNetworkFunction::RunAsync() {
+ scoped_ptr<private_api::CreateNetwork::Params> params =
+ private_api::CreateNetwork::Params::Create(*args_);
+ EXTENSION_FUNCTION_VALIDATE(params);
+
+ scoped_ptr<base::DictionaryValue> properties_dict(
+ params->properties.ToValue());
+
+ GetDelegate(browser_context())->CreateNetwork(
+ params->shared,
+ properties_dict.Pass(),
+ base::Bind(&NetworkingPrivateCreateNetworkFunction::Success, this),
+ base::Bind(&NetworkingPrivateCreateNetworkFunction::Failure, this));
+ return true;
+}
+
+void NetworkingPrivateCreateNetworkFunction::Success(const std::string& guid) {
+ results_ = private_api::CreateNetwork::Results::Create(guid);
+ SendResponse(true);
+}
+
+void NetworkingPrivateCreateNetworkFunction::Failure(const std::string& error) {
+ error_ = error;
+ SendResponse(false);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// NetworkingPrivateGetNetworksFunction
+
+NetworkingPrivateGetNetworksFunction::~NetworkingPrivateGetNetworksFunction() {
+}
+
+bool NetworkingPrivateGetNetworksFunction::RunAsync() {
+ scoped_ptr<private_api::GetNetworks::Params> params =
+ private_api::GetNetworks::Params::Create(*args_);
+ EXTENSION_FUNCTION_VALIDATE(params);
+
+ std::string network_type = private_api::ToString(params->filter.network_type);
+ const bool configured_only =
+ params->filter.configured ? *params->filter.configured : false;
+ const bool visible_only =
+ params->filter.visible ? *params->filter.visible : false;
+ const int limit =
+ params->filter.limit ? *params->filter.limit : kDefaultNetworkListLimit;
+
+ GetDelegate(browser_context())->GetNetworks(
+ network_type,
+ configured_only,
+ visible_only,
+ limit,
+ base::Bind(&NetworkingPrivateGetNetworksFunction::Success, this),
+ base::Bind(&NetworkingPrivateGetNetworksFunction::Failure, this));
+ return true;
+}
+
+void NetworkingPrivateGetNetworksFunction::Success(
+ scoped_ptr<base::ListValue> network_list) {
+ SetResult(network_list.release());
+ SendResponse(true);
+}
+
+void NetworkingPrivateGetNetworksFunction::Failure(const std::string& error) {
+ error_ = error;
+ SendResponse(false);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// NetworkingPrivateGetVisibleNetworksFunction
+
+NetworkingPrivateGetVisibleNetworksFunction::
+ ~NetworkingPrivateGetVisibleNetworksFunction() {
+}
+
+bool NetworkingPrivateGetVisibleNetworksFunction::RunAsync() {
+ scoped_ptr<private_api::GetVisibleNetworks::Params> params =
+ private_api::GetVisibleNetworks::Params::Create(*args_);
+ EXTENSION_FUNCTION_VALIDATE(params);
+
+ std::string network_type = private_api::ToString(params->network_type);
+ const bool configured_only = false;
+ const bool visible_only = true;
+
+ GetDelegate(browser_context())->GetNetworks(
+ network_type,
+ configured_only,
+ visible_only,
+ kDefaultNetworkListLimit,
+ base::Bind(&NetworkingPrivateGetVisibleNetworksFunction::Success, this),
+ base::Bind(&NetworkingPrivateGetVisibleNetworksFunction::Failure, this));
+ return true;
+}
+
+void NetworkingPrivateGetVisibleNetworksFunction::Success(
+ scoped_ptr<base::ListValue> network_properties_list) {
+ SetResult(network_properties_list.release());
+ SendResponse(true);
+}
+
+void NetworkingPrivateGetVisibleNetworksFunction::Failure(
+ const std::string& error) {
+ error_ = error;
+ SendResponse(false);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// NetworkingPrivateGetEnabledNetworkTypesFunction
+
+NetworkingPrivateGetEnabledNetworkTypesFunction::
+ ~NetworkingPrivateGetEnabledNetworkTypesFunction() {
+}
+
+bool NetworkingPrivateGetEnabledNetworkTypesFunction::RunSync() {
+ scoped_ptr<base::ListValue> enabled_networks_list(
+ GetDelegate(browser_context())->GetEnabledNetworkTypes());
+ if (enabled_networks_list) {
+ SetResult(enabled_networks_list.release());
+ return true;
+ }
+ return false;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// NetworkingPrivateEnableNetworkTypeFunction
+
+NetworkingPrivateEnableNetworkTypeFunction::
+ ~NetworkingPrivateEnableNetworkTypeFunction() {
+}
+
+bool NetworkingPrivateEnableNetworkTypeFunction::RunSync() {
+ scoped_ptr<private_api::EnableNetworkType::Params> params =
+ private_api::EnableNetworkType::Params::Create(*args_);
+ EXTENSION_FUNCTION_VALIDATE(params);
+
+ return GetDelegate(browser_context())->EnableNetworkType(
+ private_api::ToString(params->network_type));
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// NetworkingPrivateDisableNetworkTypeFunction
+
+NetworkingPrivateDisableNetworkTypeFunction::
+ ~NetworkingPrivateDisableNetworkTypeFunction() {
+}
+
+bool NetworkingPrivateDisableNetworkTypeFunction::RunSync() {
+ scoped_ptr<private_api::DisableNetworkType::Params> params =
+ private_api::DisableNetworkType::Params::Create(*args_);
+
+ return GetDelegate(browser_context())->DisableNetworkType(
+ private_api::ToString(params->network_type));
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// NetworkingPrivateRequestNetworkScanFunction
+
+NetworkingPrivateRequestNetworkScanFunction::
+ ~NetworkingPrivateRequestNetworkScanFunction() {
+}
+
+bool NetworkingPrivateRequestNetworkScanFunction::RunSync() {
+ return GetDelegate(browser_context())->RequestScan();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// NetworkingPrivateStartConnectFunction
+
+NetworkingPrivateStartConnectFunction::
+ ~NetworkingPrivateStartConnectFunction() {
+}
+
+bool NetworkingPrivateStartConnectFunction::RunAsync() {
+ scoped_ptr<private_api::StartConnect::Params> params =
+ private_api::StartConnect::Params::Create(*args_);
+ EXTENSION_FUNCTION_VALIDATE(params);
+
+ GetDelegate(browser_context())->StartConnect(
+ params->network_guid,
+ base::Bind(&NetworkingPrivateStartConnectFunction::Success, this),
+ base::Bind(&NetworkingPrivateStartConnectFunction::Failure, this));
+ return true;
+}
+
+void NetworkingPrivateStartConnectFunction::Success() {
+ SendResponse(true);
+}
+
+void NetworkingPrivateStartConnectFunction::Failure(const std::string& error) {
+ error_ = error;
+ SendResponse(false);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// NetworkingPrivateStartDisconnectFunction
+
+NetworkingPrivateStartDisconnectFunction::
+ ~NetworkingPrivateStartDisconnectFunction() {
+}
+
+bool NetworkingPrivateStartDisconnectFunction::RunAsync() {
+ scoped_ptr<private_api::StartDisconnect::Params> params =
+ private_api::StartDisconnect::Params::Create(*args_);
+ EXTENSION_FUNCTION_VALIDATE(params);
+
+ GetDelegate(browser_context())->StartDisconnect(
+ params->network_guid,
+ base::Bind(&NetworkingPrivateStartDisconnectFunction::Success, this),
+ base::Bind(&NetworkingPrivateStartDisconnectFunction::Failure, this));
+ return true;
+}
+
+void NetworkingPrivateStartDisconnectFunction::Success() {
+ SendResponse(true);
+}
+
+void NetworkingPrivateStartDisconnectFunction::Failure(
+ const std::string& error) {
+ error_ = error;
+ SendResponse(false);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// NetworkingPrivateVerifyDestinationFunction
+
+NetworkingPrivateVerifyDestinationFunction::
+ ~NetworkingPrivateVerifyDestinationFunction() {
+}
+
+bool NetworkingPrivateVerifyDestinationFunction::RunAsync() {
+ scoped_ptr<private_api::VerifyDestination::Params> params =
+ private_api::VerifyDestination::Params::Create(*args_);
+ EXTENSION_FUNCTION_VALIDATE(params);
+
+ scoped_ptr<base::DictionaryValue> verification_properties =
+ params->properties.ToValue();
+
+ GetDelegate(browser_context())->VerifyDestination(
+ verification_properties.Pass(),
+ base::Bind(&NetworkingPrivateVerifyDestinationFunction::Success, this),
+ base::Bind(&NetworkingPrivateVerifyDestinationFunction::Failure, this));
+ return true;
+}
+
+void NetworkingPrivateVerifyDestinationFunction::Success(bool result) {
+ results_ = private_api::VerifyDestination::Results::Create(result);
+ SendResponse(true);
+}
+
+void NetworkingPrivateVerifyDestinationFunction::Failure(
+ const std::string& error) {
+ error_ = error;
+ SendResponse(false);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// NetworkingPrivateVerifyAndEncryptCredentialsFunction
+
+NetworkingPrivateVerifyAndEncryptCredentialsFunction::
+ ~NetworkingPrivateVerifyAndEncryptCredentialsFunction() {
+}
+
+bool NetworkingPrivateVerifyAndEncryptCredentialsFunction::RunAsync() {
+ scoped_ptr<private_api::VerifyAndEncryptCredentials::Params> params =
+ private_api::VerifyAndEncryptCredentials::Params::Create(*args_);
+ EXTENSION_FUNCTION_VALIDATE(params);
+
+ scoped_ptr<base::DictionaryValue> verification_properties =
+ params->properties.ToValue();
+
+ GetDelegate(browser_context())->VerifyAndEncryptCredentials(
+ params->network_guid,
+ verification_properties.Pass(),
+ base::Bind(&NetworkingPrivateVerifyAndEncryptCredentialsFunction::Success,
+ this),
+ base::Bind(&NetworkingPrivateVerifyAndEncryptCredentialsFunction::Failure,
+ this));
+ return true;
+}
+
+void NetworkingPrivateVerifyAndEncryptCredentialsFunction::Success(
+ const std::string& result) {
+ results_ = private_api::VerifyAndEncryptCredentials::Results::Create(result);
+ SendResponse(true);
+}
+
+void NetworkingPrivateVerifyAndEncryptCredentialsFunction::Failure(
+ const std::string& error) {
+ error_ = error;
+ SendResponse(false);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// NetworkingPrivateVerifyAndEncryptDataFunction
+
+NetworkingPrivateVerifyAndEncryptDataFunction::
+ ~NetworkingPrivateVerifyAndEncryptDataFunction() {
+}
+
+bool NetworkingPrivateVerifyAndEncryptDataFunction::RunAsync() {
+ scoped_ptr<private_api::VerifyAndEncryptData::Params> params =
+ private_api::VerifyAndEncryptData::Params::Create(*args_);
+ EXTENSION_FUNCTION_VALIDATE(params);
+
+ scoped_ptr<base::DictionaryValue> verification_properties =
+ params->properties.ToValue();
+
+ GetDelegate(browser_context())->VerifyAndEncryptData(
+ verification_properties.Pass(),
+ params->data,
+ base::Bind(&NetworkingPrivateVerifyAndEncryptDataFunction::Success, this),
+ base::Bind(&NetworkingPrivateVerifyAndEncryptDataFunction::Failure,
+ this));
+ return true;
+}
+
+void NetworkingPrivateVerifyAndEncryptDataFunction::Success(
+ const std::string& result) {
+ results_ = private_api::VerifyAndEncryptData::Results::Create(result);
+ SendResponse(true);
+}
+
+void NetworkingPrivateVerifyAndEncryptDataFunction::Failure(
+ const std::string& error) {
+ error_ = error;
+ SendResponse(false);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// NetworkingPrivateSetWifiTDLSEnabledStateFunction
+
+NetworkingPrivateSetWifiTDLSEnabledStateFunction::
+ ~NetworkingPrivateSetWifiTDLSEnabledStateFunction() {
+}
+
+bool NetworkingPrivateSetWifiTDLSEnabledStateFunction::RunAsync() {
+ scoped_ptr<private_api::SetWifiTDLSEnabledState::Params> params =
+ private_api::SetWifiTDLSEnabledState::Params::Create(*args_);
+ EXTENSION_FUNCTION_VALIDATE(params);
+
+ GetDelegate(browser_context())->SetWifiTDLSEnabledState(
+ params->ip_or_mac_address,
+ params->enabled,
+ base::Bind(&NetworkingPrivateSetWifiTDLSEnabledStateFunction::Success,
+ this),
+ base::Bind(&NetworkingPrivateSetWifiTDLSEnabledStateFunction::Failure,
+ this));
+
+ return true;
+}
+
+void NetworkingPrivateSetWifiTDLSEnabledStateFunction::Success(
+ const std::string& result) {
+ results_ = private_api::SetWifiTDLSEnabledState::Results::Create(result);
+ SendResponse(true);
+}
+
+void NetworkingPrivateSetWifiTDLSEnabledStateFunction::Failure(
+ const std::string& error) {
+ error_ = error;
+ SendResponse(false);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// NetworkingPrivateGetWifiTDLSStatusFunction
+
+NetworkingPrivateGetWifiTDLSStatusFunction::
+ ~NetworkingPrivateGetWifiTDLSStatusFunction() {
+}
+
+bool NetworkingPrivateGetWifiTDLSStatusFunction::RunAsync() {
+ scoped_ptr<private_api::GetWifiTDLSStatus::Params> params =
+ private_api::GetWifiTDLSStatus::Params::Create(*args_);
+ EXTENSION_FUNCTION_VALIDATE(params);
+
+ GetDelegate(browser_context())->GetWifiTDLSStatus(
+ params->ip_or_mac_address,
+ base::Bind(&NetworkingPrivateGetWifiTDLSStatusFunction::Success, this),
+ base::Bind(&NetworkingPrivateGetWifiTDLSStatusFunction::Failure, this));
+
+ return true;
+}
+
+void NetworkingPrivateGetWifiTDLSStatusFunction::Success(
+ const std::string& result) {
+ results_ = private_api::GetWifiTDLSStatus::Results::Create(result);
+ SendResponse(true);
+}
+
+void NetworkingPrivateGetWifiTDLSStatusFunction::Failure(
+ const std::string& error) {
+ error_ = error;
+ SendResponse(false);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// NetworkingPrivateGetCaptivePortalStatusFunction
+
+NetworkingPrivateGetCaptivePortalStatusFunction::
+ ~NetworkingPrivateGetCaptivePortalStatusFunction() {
+}
+
+bool NetworkingPrivateGetCaptivePortalStatusFunction::RunAsync() {
+ scoped_ptr<private_api::GetCaptivePortalStatus::Params> params =
+ private_api::GetCaptivePortalStatus::Params::Create(*args_);
+ EXTENSION_FUNCTION_VALIDATE(params);
+
+ GetDelegate(browser_context())->GetCaptivePortalStatus(
+ params->network_guid,
+ base::Bind(&NetworkingPrivateGetCaptivePortalStatusFunction::Success,
+ this),
+ base::Bind(&NetworkingPrivateGetCaptivePortalStatusFunction::Failure,
+ this));
+ return true;
+}
+
+void NetworkingPrivateGetCaptivePortalStatusFunction::Success(
+ const std::string& result) {
+ results_ = private_api::GetCaptivePortalStatus::Results::Create(
+ private_api::ParseCaptivePortalStatus(result));
+ SendResponse(true);
+}
+
+void NetworkingPrivateGetCaptivePortalStatusFunction::Failure(
+ const std::string& error) {
+ error_ = error;
+ SendResponse(false);
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698