diff options
author | mef@chromium.org <mef@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-27 01:06:47 +0000 |
---|---|---|
committer | mef@chromium.org <mef@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-27 01:06:47 +0000 |
commit | a57ffbd55dd68110cecb02aff756a7e5c6d16d44 (patch) | |
tree | 193c9f7f45edcb76f7e2c00f7a6398cd07b02084 | |
parent | 166a865e356b1841a1e3bf3b32bc5aaf13215f6e (diff) | |
download | chromium_src-a57ffbd55dd68110cecb02aff756a7e5c6d16d44.zip chromium_src-a57ffbd55dd68110cecb02aff756a7e5c6d16d44.tar.gz chromium_src-a57ffbd55dd68110cecb02aff756a7e5c6d16d44.tar.bz2 |
Move GetVisibleNetworks network type filtering to WiFiService interface.
Fix incorrect naming process_client => service_client, service_path => network_guid.
BUG=267667
Review URL: https://codereview.chromium.org/88653002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@237460 0039d316-1c4b-4281-b951-d872f2087c98
7 files changed, 59 insertions, 69 deletions
diff --git a/chrome/browser/extensions/api/networking_private/networking_private_api_nonchromeos.cc b/chrome/browser/extensions/api/networking_private/networking_private_api_nonchromeos.cc index f2930bd..c0ee74d 100644 --- a/chrome/browser/extensions/api/networking_private/networking_private_api_nonchromeos.cc +++ b/chrome/browser/extensions/api/networking_private/networking_private_api_nonchromeos.cc @@ -35,10 +35,10 @@ bool NetworkingPrivateGetPropertiesFunction::RunImpl() { api::GetProperties::Params::Create(*args_); EXTENSION_FUNCTION_VALIDATE(params); - NetworkingPrivateServiceClient* process_client = + NetworkingPrivateServiceClient* service_client = NetworkingPrivateServiceClientFactory::GetForProfile(GetProfile()); - process_client->GetProperties( + service_client->GetProperties( params->network_guid, base::Bind(&NetworkingPrivateGetPropertiesFunction::GetPropertiesSuccess, this), @@ -171,10 +171,10 @@ bool NetworkingPrivateSetPropertiesFunction::RunImpl() { scoped_ptr<base::DictionaryValue> properties_dict( params->properties.ToValue()); - NetworkingPrivateServiceClient* process_client = + NetworkingPrivateServiceClient* service_client = NetworkingPrivateServiceClientFactory::GetForProfile(GetProfile()); - process_client->SetProperties( + service_client->SetProperties( params->network_guid, *properties_dict, base::Bind(&NetworkingPrivateSetPropertiesFunction::ResultCallback, this), @@ -222,44 +222,20 @@ bool NetworkingPrivateGetVisibleNetworksFunction::RunImpl() { api::GetVisibleNetworks::Params::Create(*args_); EXTENSION_FUNCTION_VALIDATE(params); - NetworkingPrivateServiceClient* process_client = + NetworkingPrivateServiceClient* service_client = NetworkingPrivateServiceClientFactory::GetForProfile(GetProfile()); - process_client->GetVisibleNetworks(base::Bind( - &NetworkingPrivateGetVisibleNetworksFunction::ResultCallback, this)); + service_client->GetVisibleNetworks( + api::GetVisibleNetworks::Params::ToString(params->type), + base::Bind(&NetworkingPrivateGetVisibleNetworksFunction::ResultCallback, + this)); return true; } void NetworkingPrivateGetVisibleNetworksFunction::ResultCallback( const base::ListValue& network_list) { - scoped_ptr<api::GetVisibleNetworks::Params> params = - api::GetVisibleNetworks::Params::Create(*args_); - ListValue* result = new ListValue(); - std::string params_type = - api::GetVisibleNetworks::Params::ToString(params->type); - bool request_all = params->type == api::GetVisibleNetworks::Params::TYPE_ALL; - - // Copy networks of requested type; - for (base::ListValue::const_iterator it = network_list.begin(); - it != network_list.end(); - ++it) { - const base::Value* network_value = *it; - const DictionaryValue* network_dict = NULL; - if (!network_value->GetAsDictionary(&network_dict)) { - LOG(ERROR) << "Value is not a dictionary"; - continue; - } - if (!request_all) { - std::string network_type; - network_dict->GetString(onc::network_config::kType, &network_type); - if (network_type != params_type) - continue; - } - result->Append(network_value->DeepCopy()); - } - - SetResult(result); + SetResult(network_list.DeepCopy()); SendResponse(true); } @@ -272,11 +248,7 @@ NetworkingPrivateGetEnabledNetworkTypesFunction:: bool NetworkingPrivateGetEnabledNetworkTypesFunction::RunImpl() { base::ListValue* network_list = new base::ListValue; - - network_list->Append(new base::StringValue("Ethernet")); - network_list->Append(new base::StringValue("WiFi")); - network_list->Append(new base::StringValue("Cellular")); - + network_list->Append(new base::StringValue(onc::network_type::kWiFi)); SetResult(network_list); return true; } @@ -317,9 +289,9 @@ NetworkingPrivateRequestNetworkScanFunction:: } bool NetworkingPrivateRequestNetworkScanFunction::RunImpl() { - NetworkingPrivateServiceClient* process_client = + NetworkingPrivateServiceClient* service_client = NetworkingPrivateServiceClientFactory::GetForProfile(GetProfile()); - process_client->RequestNetworkScan(); + service_client->RequestNetworkScan(); return true; } @@ -334,9 +306,9 @@ bool NetworkingPrivateStartConnectFunction::RunImpl() { scoped_ptr<api::StartConnect::Params> params = api::StartConnect::Params::Create(*args_); EXTENSION_FUNCTION_VALIDATE(params); - NetworkingPrivateServiceClient* process_client = + NetworkingPrivateServiceClient* service_client = NetworkingPrivateServiceClientFactory::GetForProfile(GetProfile()); - process_client->StartConnect( + service_client->StartConnect( params->network_guid, base::Bind(&NetworkingPrivateStartConnectFunction::ConnectionStartSuccess, this), @@ -367,9 +339,9 @@ bool NetworkingPrivateStartDisconnectFunction::RunImpl() { scoped_ptr<api::StartDisconnect::Params> params = api::StartDisconnect::Params::Create(*args_); EXTENSION_FUNCTION_VALIDATE(params); - NetworkingPrivateServiceClient* process_client = + NetworkingPrivateServiceClient* service_client = NetworkingPrivateServiceClientFactory::GetForProfile(GetProfile()); - process_client->StartDisconnect( + service_client->StartDisconnect( params->network_guid, base::Bind( &NetworkingPrivateStartDisconnectFunction::DisconnectionStartSuccess, @@ -401,9 +373,9 @@ bool NetworkingPrivateVerifyDestinationFunction::RunImpl() { scoped_ptr<api::VerifyDestination::Params> params = api::VerifyDestination::Params::Create(*args_); EXTENSION_FUNCTION_VALIDATE(params); - NetworkingPrivateServiceClient* process_client = + NetworkingPrivateServiceClient* service_client = NetworkingPrivateServiceClientFactory::GetForProfile(GetProfile()); - process_client->VerifyDestination( + service_client->VerifyDestination( args_.Pass(), base::Bind( &NetworkingPrivateVerifyDestinationFunction::ResultCallback, @@ -452,9 +424,9 @@ bool NetworkingPrivateVerifyAndEncryptDataFunction::RunImpl() { scoped_ptr<api::VerifyAndEncryptData::Params> params = api::VerifyAndEncryptData::Params::Create(*args_); EXTENSION_FUNCTION_VALIDATE(params); - NetworkingPrivateServiceClient* process_client = + NetworkingPrivateServiceClient* service_client = NetworkingPrivateServiceClientFactory::GetForProfile(GetProfile()); - process_client->VerifyAndEncryptData( + service_client->VerifyAndEncryptData( args_.Pass(), base::Bind( &NetworkingPrivateVerifyAndEncryptDataFunction::ResultCallback, diff --git a/chrome/browser/extensions/api/networking_private/networking_private_service_client.cc b/chrome/browser/extensions/api/networking_private/networking_private_service_client.cc index 7f7f30c..96f2699 100644 --- a/chrome/browser/extensions/api/networking_private/networking_private_service_client.cc +++ b/chrome/browser/extensions/api/networking_private/networking_private_service_client.cc @@ -205,6 +205,7 @@ void NetworkingPrivateServiceClient::GetProperties( } void NetworkingPrivateServiceClient::GetVisibleNetworks( + const std::string& network_type, const ListResultCallback& callback) { ServiceCallbacks* service_callbacks = AddServiceCallbacks(); service_callbacks->get_visible_networks_callback = callback; @@ -215,6 +216,7 @@ void NetworkingPrivateServiceClient::GetVisibleNetworks( FROM_HERE, base::Bind(&WiFiService::GetVisibleNetworks, base::Unretained(wifi_service_.get()), + network_type, networks), base::Bind(&NetworkingPrivateServiceClient::AfterGetVisibleNetworks, weak_factory_.GetWeakPtr(), diff --git a/chrome/browser/extensions/api/networking_private/networking_private_service_client.h b/chrome/browser/extensions/api/networking_private/networking_private_service_client.h index 3e0ced6..cd77e80 100644 --- a/chrome/browser/extensions/api/networking_private/networking_private_service_client.h +++ b/chrome/browser/extensions/api/networking_private/networking_private_service_client.h @@ -111,27 +111,27 @@ class NetworkingPrivateServiceClient : public BrowserContextKeyedService { // BrowserContextKeyedServices method override. virtual void Shutdown() OVERRIDE; - // Gets the properties of the network with id |service_path|. See note on + // Gets the properties of the network with id |network_guid|. See note on // |callback| and |error_callback|, in class description above. - void GetProperties(const std::string& service_path, + void GetProperties(const std::string& network_guid, const DictionaryResultCallback& callback, const ErrorCallback& error_callback); - // Start connect to the network with id |service_path|. See note on + // Start connect to the network with id |network_guid|. See note on // |callback| and |error_callback|, in class description above. - void StartConnect(const std::string& service_path, + void StartConnect(const std::string& network_guid, const base::Closure& callback, const ErrorCallback& error_callback); - // Start disconnect from the network with id |service_path|. See note on + // Start disconnect from the network with id |network_guid|. See note on // |callback| and |error_callback|, in class description above. - void StartDisconnect(const std::string& service_path, + void StartDisconnect(const std::string& network_guid, const base::Closure& callback, const ErrorCallback& error_callback); - // Sets the |properties| of the network with id |service_path|. See note on + // Sets the |properties| of the network with id |network_guid|. See note on // |callback| and |error_callback|, in class description above. - void SetProperties(const std::string& service_path, + void SetProperties(const std::string& network_guid, const base::DictionaryValue& properties, const base::Closure& callback, const ErrorCallback& error_callback); @@ -139,8 +139,9 @@ class NetworkingPrivateServiceClient : public BrowserContextKeyedService { // Requests network scan. Broadcasts NetworkListChangedEvent upon completion. void RequestNetworkScan(); - // Gets the list of visible networks and calls |callback|. - void GetVisibleNetworks(const ListResultCallback& callback); + // Gets the list of visible networks of |network_type| and calls |callback|. + void GetVisibleNetworks(const std::string& network_type, + const ListResultCallback& callback); // Verify that Chromecast provides valid cryptographically signed properties. void VerifyDestination(scoped_ptr<base::ListValue> args, diff --git a/components/wifi/fake_wifi_service.cc b/components/wifi/fake_wifi_service.cc index e8c2372..a1eac21 100644 --- a/components/wifi/fake_wifi_service.cc +++ b/components/wifi/fake_wifi_service.cc @@ -107,12 +107,17 @@ class FakeWiFiService : public WiFiService { } } - virtual void GetVisibleNetworks(ListValue* network_list) OVERRIDE { + virtual void GetVisibleNetworks(const std::string& network_type, + ListValue* network_list) OVERRIDE { for (WiFiService::NetworkList::const_iterator it = networks_.begin(); it != networks_.end(); ++it) { - scoped_ptr<DictionaryValue> network(it->ToValue(true)); - network_list->Append(network.release()); + if (network_type.empty() || + network_type == onc::network_type::kAllTypes || + it->type == network_type) { + scoped_ptr<DictionaryValue> network(it->ToValue(true)); + network_list->Append(network.release()); + } } } diff --git a/components/wifi/wifi_service.h b/components/wifi/wifi_service.h index a81d1e3..49f8af4 100644 --- a/components/wifi/wifi_service.h +++ b/components/wifi/wifi_service.h @@ -54,8 +54,10 @@ class WIFI_EXPORT WiFiService { scoped_ptr<base::DictionaryValue> properties, std::string* error) = 0; - // Get list of visible networks. Populates |network_list| on success. - virtual void GetVisibleNetworks(ListValue* network_list) = 0; + // Get list of visible networks of |network_type| (one of onc::network_type). + // Populates |network_list| on success. + virtual void GetVisibleNetworks(const std::string& network_type, + ListValue* network_list) = 0; // Request network scan. Send |NetworkListChanged| event on completion. virtual void RequestNetworkScan() = 0; diff --git a/components/wifi/wifi_service_win.cc b/components/wifi/wifi_service_win.cc index 052062d..5f837fc 100644 --- a/components/wifi/wifi_service_win.cc +++ b/components/wifi/wifi_service_win.cc @@ -154,8 +154,10 @@ class WiFiServiceImpl : public WiFiService, base::NonThreadSafe { scoped_ptr<base::DictionaryValue> properties, std::string* error) OVERRIDE; - // Get list of visible networks. Populates |network_list| on success. - virtual void GetVisibleNetworks(ListValue* network_list) OVERRIDE; + // Get list of visible networks of |network_type| (one of onc::network_type). + // Populates |network_list| on success. + virtual void GetVisibleNetworks(const std::string& network_type, + ListValue* network_list) OVERRIDE; // Request network scan. Send |NetworkListChanged| event on completion. virtual void RequestNetworkScan() OVERRIDE; @@ -424,9 +426,15 @@ void WiFiServiceImpl::SetProperties( CheckError(ERROR_CALL_NOT_IMPLEMENTED, kWiFiServiceError, error); } -void WiFiServiceImpl::GetVisibleNetworks(ListValue* network_list) { - DWORD error = EnsureInitialized(); +void WiFiServiceImpl::GetVisibleNetworks(const std::string& network_type, + ListValue* network_list) { + if (!network_type.empty() && + network_type != onc::network_type::kAllTypes && + network_type != onc::network_type::kWiFi) { + return; + } + DWORD error = EnsureInitialized(); if (error == ERROR_SUCCESS) { NetworkList networks; error = GetVisibleNetworkList(&networks); diff --git a/components/wifi/wifi_test.cc b/components/wifi/wifi_test.cc index 8fd0aaf..161eae3 100644 --- a/components/wifi/wifi_test.cc +++ b/components/wifi/wifi_test.cc @@ -112,7 +112,7 @@ bool WiFiTest::ParseCommandLine(int argc, const char* argv[]) { if (parsed_command_line.HasSwitch("list")) { ListValue network_list; - wifi_service->GetVisibleNetworks(&network_list); + wifi_service->GetVisibleNetworks(std::string(), &network_list); std::cout << network_list; return true; } |