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

Unified Diff: chrome/browser/extensions/api/gcd_private/gcd_private_api.cc

Issue 434733003: Added function to get list of networks with prefetched passwords. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Thu 07/31/2014 14:34:51.93 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/gcd_private/gcd_private_api.cc
diff --git a/chrome/browser/extensions/api/gcd_private/gcd_private_api.cc b/chrome/browser/extensions/api/gcd_private/gcd_private_api.cc
index e68c5f8fb9af619849b1625ec7e2c9f924bf7751..b01e6f486a860947a1ebe56c5d34dd62f8298bd6 100644
--- a/chrome/browser/extensions/api/gcd_private/gcd_private_api.cc
+++ b/chrome/browser/extensions/api/gcd_private/gcd_private_api.cc
@@ -136,6 +136,8 @@ class GcdPrivateAPIImpl : public EventRouter::Observer,
void RemoveSession(int session_id);
+ scoped_ptr<base::ListValue> GetPrefetchedSSIDList();
+
private:
typedef std::map<std::string /* id_string */,
linked_ptr<api::gcd_private::GCDDevice> > GCDDeviceMap;
@@ -391,10 +393,7 @@ void GcdPrivateAPIImpl::SendMessage(int session_id,
if (api == kPrivatAPISetup) {
const base::DictionaryValue* wifi = NULL;
- if (input.GetDictionary(kPrivetKeyWifi, &wifi) &&
- !wifi->HasKey(kPrivetKeyPassphrase)) {
- // If the message is a setup message, has a wifi section, try sending the
- // passphrase.
+ if (input.GetDictionary(kPrivetKeyWifi, &wifi)) {
std::string ssid;
if (!wifi->GetString(kPrivetKeySSID, &ssid)) {
@@ -403,16 +402,21 @@ void GcdPrivateAPIImpl::SendMessage(int session_id,
return;
}
- PasswordMap::iterator found = wifi_passwords_.find(ssid);
- if (found == wifi_passwords_.end()) {
- callback.Run(gcd_private::STATUS_WIFIPASSWORDERROR,
- base::DictionaryValue());
- return;
- }
+ if (!wifi->HasKey(kPrivetKeyPassphrase)) {
+ // If the message is a setup message, has a wifi section, try sending
+ // the passphrase.
+
+ PasswordMap::iterator found = wifi_passwords_.find(ssid);
+ if (found == wifi_passwords_.end()) {
+ callback.Run(gcd_private::STATUS_WIFIPASSWORDERROR,
+ base::DictionaryValue());
+ return;
+ }
- input_cloned.reset(input.DeepCopy());
- input_cloned->SetString(kPrivetKeyPassphraseDotted, found->second);
- input_actual = input_cloned.get();
+ input_cloned.reset(input.DeepCopy());
+ input_cloned->SetString(kPrivetKeyPassphraseDotted, found->second);
+ input_actual = input_cloned.get();
+ }
}
}
#endif
@@ -467,6 +471,20 @@ void GcdPrivateAPIImpl::RemoveSession(int session_id) {
sessions_.erase(session_id);
}
+scoped_ptr<base::ListValue> GcdPrivateAPIImpl::GetPrefetchedSSIDList() {
+ scoped_ptr<base::ListValue> retval(new base::ListValue);
+
+#if defined(ENABLE_WIFI_BOOTSTRAPPING)
+ for (PasswordMap::iterator i = wifi_passwords_.begin();
+ i != wifi_passwords_.end();
+ i++) {
+ retval->AppendString(i->first);
+ }
+#endif
+
+ return retval.Pass();
+}
+
GcdPrivateRequest::GcdPrivateRequest(
const std::string& api,
const base::DictionaryValue& input,
@@ -686,9 +704,6 @@ GcdPrivateQueryForNewLocalDevicesFunction::
bool GcdPrivateQueryForNewLocalDevicesFunction::RunSync() {
GcdPrivateAPIImpl* gcd_api = GcdPrivateAPIImpl::Get(GetProfile());
- if (!gcd_api)
- return false;
-
if (!gcd_api->QueryForDevices()) {
error_ =
"You must first subscribe to onDeviceStateChanged or onDeviceRemoved "
@@ -716,9 +731,6 @@ bool GcdPrivatePrefetchWifiPasswordFunction::RunAsync() {
GcdPrivateAPIImpl* gcd_api = GcdPrivateAPIImpl::Get(GetProfile());
- if (!gcd_api)
- return false;
-
gcd_api->RequestWifiPassword(
params->ssid,
base::Bind(&GcdPrivatePrefetchWifiPasswordFunction::OnResponse, this));
@@ -748,9 +760,6 @@ bool GcdPrivateEstablishSessionFunction::RunAsync() {
GcdPrivateAPIImpl* gcd_api = GcdPrivateAPIImpl::Get(GetProfile());
- if (!gcd_api)
- return false;
-
gcd_api->EstablishSession(
params->ip_address,
params->port,
@@ -785,9 +794,6 @@ bool GcdPrivateConfirmCodeFunction::RunAsync() {
GcdPrivateAPIImpl* gcd_api = GcdPrivateAPIImpl::Get(GetProfile());
- if (!gcd_api)
- return false;
-
gcd_api->ConfirmCode(
params->session_id,
base::Bind(&GcdPrivateConfirmCodeFunction::OnSessionEstablishedCallback,
@@ -817,8 +823,6 @@ bool GcdPrivateSendMessageFunction::RunAsync() {
GcdPrivateAPIImpl* gcd_api = GcdPrivateAPIImpl::Get(GetProfile());
- if (!gcd_api)
- return false;
gcd_api->SendMessage(
params->session_id,
@@ -854,9 +858,6 @@ bool GcdPrivateTerminateSessionFunction::RunAsync() {
GcdPrivateAPIImpl* gcd_api = GcdPrivateAPIImpl::Get(GetProfile());
- if (!gcd_api)
- return false;
-
gcd_api->RemoveSession(params->session_id);
SendResponse(true);
@@ -871,6 +872,24 @@ GcdPrivateGetCommandDefinitionsFunction::
~GcdPrivateGetCommandDefinitionsFunction() {
}
+GcdPrivateGetPrefetchedWifiNameListFunction::
+ GcdPrivateGetPrefetchedWifiNameListFunction() {
+}
+
+GcdPrivateGetPrefetchedWifiNameListFunction::
+ ~GcdPrivateGetPrefetchedWifiNameListFunction() {
+}
+
+bool GcdPrivateGetPrefetchedWifiNameListFunction::RunSync() {
+ GcdPrivateAPIImpl* gcd_api = GcdPrivateAPIImpl::Get(GetProfile());
+
+ scoped_ptr<base::ListValue> ssid_list = gcd_api->GetPrefetchedSSIDList();
+
+ SetResult(ssid_list.release());
+
+ return true;
+}
+
bool GcdPrivateGetCommandDefinitionsFunction::RunAsync() {
return false;
}

Powered by Google App Engine
This is Rietveld 408576698