Index: chrome/browser/extensions/api/networking_private/networking_private_api_chromeos.cc |
diff --git a/chrome/browser/extensions/api/networking_private/networking_private_api_chromeos.cc b/chrome/browser/extensions/api/networking_private/networking_private_api_chromeos.cc |
index 6275beaca3e8657ec9a1d8f8e37a4a8193c803fd..8da9206fec406910939cd4e47381309b19de86e7 100644 |
--- a/chrome/browser/extensions/api/networking_private/networking_private_api_chromeos.cc |
+++ b/chrome/browser/extensions/api/networking_private/networking_private_api_chromeos.cc |
@@ -15,11 +15,13 @@ |
#include "chrome/common/extensions/api/networking_private.h" |
#include "chromeos/dbus/dbus_thread_manager.h" |
#include "chromeos/dbus/shill_manager_client.h" |
+#include "chromeos/network/favorite_state.h" |
#include "chromeos/network/managed_network_configuration_handler.h" |
#include "chromeos/network/network_connection_handler.h" |
#include "chromeos/network/network_device_handler.h" |
#include "chromeos/network/network_state.h" |
#include "chromeos/network/network_state_handler.h" |
+#include "chromeos/network/network_util.h" |
#include "chromeos/network/onc/onc_signature.h" |
#include "chromeos/network/onc/onc_translator.h" |
#include "chromeos/network/onc/onc_utils.h" |
@@ -30,6 +32,7 @@ |
namespace api = extensions::api::networking_private; |
using chromeos::DBusThreadManager; |
+using chromeos::FavoriteState; |
using chromeos::ManagedNetworkConfigurationHandler; |
using chromeos::NetworkHandler; |
using chromeos::NetworkPortalDetector; |
@@ -65,6 +68,20 @@ std::string GetUserIdHash(Profile* profile) { |
profile_helper()->GetUserIdHashFromProfile(profile); |
} |
+bool GetServicePathFromGuid(const std::string& guid, |
+ std::string* service_path, |
+ std::string* error) { |
+ const FavoriteState* network = |
+ NetworkHandler::Get()->network_state_handler()->GetFavoriteStateFromGuid( |
+ guid); |
+ if (!network) { |
+ *error = "Error.InvalidNetworkGuid"; |
+ return false; |
+ } |
+ *service_path = network->path(); |
+ return true; |
+} |
+ |
} // namespace |
//////////////////////////////////////////////////////////////////////////////// |
@@ -78,9 +95,12 @@ bool NetworkingPrivateGetPropertiesFunction::RunAsync() { |
scoped_ptr<api::GetProperties::Params> params = |
api::GetProperties::Params::Create(*args_); |
EXTENSION_FUNCTION_VALIDATE(params); |
+ std::string service_path; |
+ if (!GetServicePathFromGuid(params->network_guid, &service_path, &error_)) |
+ return false; |
NetworkHandler::Get()->managed_network_configuration_handler()->GetProperties( |
- params->network_guid, // service path |
+ service_path, |
base::Bind(&NetworkingPrivateGetPropertiesFunction::GetPropertiesSuccess, |
this), |
base::Bind(&NetworkingPrivateGetPropertiesFunction::GetPropertiesFailed, |
@@ -91,10 +111,7 @@ bool NetworkingPrivateGetPropertiesFunction::RunAsync() { |
void NetworkingPrivateGetPropertiesFunction::GetPropertiesSuccess( |
const std::string& service_path, |
const base::DictionaryValue& dictionary) { |
- base::DictionaryValue* network_properties = dictionary.DeepCopy(); |
- network_properties->SetStringWithoutPathExpansion(onc::network_config::kGUID, |
- service_path); |
- SetResult(network_properties); |
+ SetResult(dictionary.DeepCopy()); |
SendResponse(true); |
} |
@@ -116,13 +133,16 @@ bool NetworkingPrivateGetManagedPropertiesFunction::RunAsync() { |
scoped_ptr<api::GetManagedProperties::Params> params = |
api::GetManagedProperties::Params::Create(*args_); |
EXTENSION_FUNCTION_VALIDATE(params); |
+ std::string service_path; |
+ if (!GetServicePathFromGuid(params->network_guid, &service_path, &error_)) |
+ return false; |
std::string user_id_hash; |
GetUserIdHash(GetProfile()); |
NetworkHandler::Get()->managed_network_configuration_handler()-> |
GetManagedProperties( |
user_id_hash, |
- params->network_guid, // service path |
+ service_path, |
base::Bind(&NetworkingPrivateGetManagedPropertiesFunction::Success, |
this), |
base::Bind(&NetworkingPrivateGetManagedPropertiesFunction::Failure, |
@@ -133,10 +153,7 @@ bool NetworkingPrivateGetManagedPropertiesFunction::RunAsync() { |
void NetworkingPrivateGetManagedPropertiesFunction::Success( |
const std::string& service_path, |
const base::DictionaryValue& dictionary) { |
- base::DictionaryValue* network_properties = dictionary.DeepCopy(); |
- network_properties->SetStringWithoutPathExpansion(onc::network_config::kGUID, |
- service_path); |
- SetResult(network_properties); |
+ SetResult(dictionary.DeepCopy()); |
SendResponse(true); |
} |
@@ -158,13 +175,14 @@ bool NetworkingPrivateGetStateFunction::RunAsync() { |
scoped_ptr<api::GetState::Params> params = |
api::GetState::Params::Create(*args_); |
EXTENSION_FUNCTION_VALIDATE(params); |
- // The |network_guid| parameter is storing the service path. |
- std::string service_path = params->network_guid; |
+ std::string service_path; |
+ if (!GetServicePathFromGuid(params->network_guid, &service_path, &error_)) |
+ return false; |
const NetworkState* state = NetworkHandler::Get()->network_state_handler()-> |
GetNetworkState(service_path); |
if (!state) { |
- error_ = "Error.InvalidParameter"; |
+ error_ = "Error.NetworkUnavailable"; |
return false; |
} |
@@ -190,12 +208,15 @@ bool NetworkingPrivateSetPropertiesFunction::RunAsync() { |
scoped_ptr<api::SetProperties::Params> params = |
api::SetProperties::Params::Create(*args_); |
EXTENSION_FUNCTION_VALIDATE(params); |
+ std::string service_path; |
+ if (!GetServicePathFromGuid(params->network_guid, &service_path, &error_)) |
+ return false; |
scoped_ptr<base::DictionaryValue> properties_dict( |
params->properties.ToValue()); |
NetworkHandler::Get()->managed_network_configuration_handler()->SetProperties( |
- params->network_guid, // service path |
+ service_path, |
*properties_dict, |
base::Bind(&NetworkingPrivateSetPropertiesFunction::ResultCallback, |
this), |
@@ -269,30 +290,12 @@ bool NetworkingPrivateGetVisibleNetworksFunction::RunAsync() { |
scoped_ptr<api::GetVisibleNetworks::Params> params = |
api::GetVisibleNetworks::Params::Create(*args_); |
EXTENSION_FUNCTION_VALIDATE(params); |
- NetworkTypePattern type = chromeos::onc::NetworkTypePatternFromOncType( |
+ NetworkTypePattern pattern = chromeos::onc::NetworkTypePatternFromOncType( |
api::GetVisibleNetworks::Params::ToString(params->type)); |
- NetworkStateHandler::NetworkStateList network_states; |
- NetworkHandler::Get()->network_state_handler()->GetNetworkListByType( |
- type, &network_states); |
- |
- base::ListValue* network_properties_list = new base::ListValue; |
- for (NetworkStateHandler::NetworkStateList::iterator it = |
- network_states.begin(); |
- it != network_states.end(); ++it) { |
- base::DictionaryValue shill_dictionary; |
- (*it)->GetStateProperties(&shill_dictionary); |
- |
- scoped_ptr<base::DictionaryValue> onc_network_part = |
- chromeos::onc::TranslateShillServiceToONCPart( |
- shill_dictionary, &chromeos::onc::kNetworkWithStateSignature); |
- // TODO(stevenjb): Fix this to always use GUID: crbug.com/284827 |
- onc_network_part->SetStringWithoutPathExpansion( |
- onc::network_config::kGUID, (*it)->path()); |
- network_properties_list->Append(onc_network_part.release()); |
- } |
- |
- SetResult(network_properties_list); |
+ scoped_ptr<base::ListValue> network_properties_list = |
+ chromeos::network_util::TranslateNetworkListToONC(pattern); |
+ SetResult(network_properties_list.release()); |
SendResponse(true); |
return true; |
} |
@@ -433,10 +436,13 @@ bool NetworkingPrivateStartConnectFunction::RunAsync() { |
scoped_ptr<api::StartConnect::Params> params = |
api::StartConnect::Params::Create(*args_); |
EXTENSION_FUNCTION_VALIDATE(params); |
+ std::string service_path; |
+ if (!GetServicePathFromGuid(params->network_guid, &service_path, &error_)) |
+ return false; |
const bool check_error_state = false; |
NetworkHandler::Get()->network_connection_handler()->ConnectToNetwork( |
- params->network_guid, // service path |
+ service_path, |
base::Bind( |
&NetworkingPrivateStartConnectFunction::ConnectionStartSuccess, |
this), |
@@ -469,9 +475,12 @@ bool NetworkingPrivateStartDisconnectFunction::RunAsync() { |
scoped_ptr<api::StartDisconnect::Params> params = |
api::StartDisconnect::Params::Create(*args_); |
EXTENSION_FUNCTION_VALIDATE(params); |
+ std::string service_path; |
+ if (!GetServicePathFromGuid(params->network_guid, &service_path, &error_)) |
+ return false; |
NetworkHandler::Get()->network_connection_handler()->DisconnectNetwork( |
- params->network_guid, // service path |
+ service_path, |
base::Bind( |
&NetworkingPrivateStartDisconnectFunction::DisconnectionStartSuccess, |
this), |
@@ -530,15 +539,18 @@ bool NetworkingPrivateVerifyAndEncryptCredentialsFunction::RunAsync() { |
scoped_ptr<api::VerifyAndEncryptCredentials::Params> params = |
api::VerifyAndEncryptCredentials::Params::Create(*args_); |
EXTENSION_FUNCTION_VALIDATE(params); |
- ShillManagerClient* shill_manager_client = |
- DBusThreadManager::Get()->GetShillManagerClient(); |
+ std::string service_path; |
+ if (!GetServicePathFromGuid(params->network_guid, &service_path, &error_)) |
+ return false; |
ShillManagerClient::VerificationProperties verification_properties = |
ConvertVerificationProperties(params->properties); |
+ ShillManagerClient* shill_manager_client = |
+ DBusThreadManager::Get()->GetShillManagerClient(); |
shill_manager_client->VerifyAndEncryptCredentials( |
verification_properties, |
- params->guid, |
+ service_path, |
base::Bind( |
&NetworkingPrivateVerifyAndEncryptCredentialsFunction::ResultCallback, |
this), |
@@ -688,6 +700,9 @@ bool NetworkingPrivateGetCaptivePortalStatusFunction::RunAsync() { |
scoped_ptr<api::GetCaptivePortalStatus::Params> params = |
api::GetCaptivePortalStatus::Params::Create(*args_); |
EXTENSION_FUNCTION_VALIDATE(params); |
+ std::string service_path; |
+ if (!GetServicePathFromGuid(params->network_guid, &service_path, &error_)) |
+ return false; |
NetworkPortalDetector* detector = NetworkPortalDetector::Get(); |
if (!detector) { |
@@ -696,7 +711,7 @@ bool NetworkingPrivateGetCaptivePortalStatusFunction::RunAsync() { |
} |
NetworkPortalDetector::CaptivePortalState state = |
- detector->GetCaptivePortalState(params->network_path); |
+ detector->GetCaptivePortalState(service_path); |
SetResult(new base::StringValue( |
NetworkPortalDetector::CaptivePortalStatusString(state.status))); |