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

Unified Diff: chrome/browser/extensions/api/push_messaging/push_messaging_api.cc

Issue 10836182: Obfuscated Gaia ID fetcher (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Style changes per DCheng and Munjal Created 8 years, 4 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/push_messaging/push_messaging_api.cc
diff --git a/chrome/browser/extensions/api/push_messaging/push_messaging_api.cc b/chrome/browser/extensions/api/push_messaging/push_messaging_api.cc
index cc92f87bf20c337da9829d319bb89c3c14820560..e213ed57a2dcbe3391d0efd9a10305e70ec39b5c 100644
--- a/chrome/browser/extensions/api/push_messaging/push_messaging_api.cc
+++ b/chrome/browser/extensions/api/push_messaging/push_messaging_api.cc
@@ -9,9 +9,14 @@
#include "chrome/browser/extensions/event_names.h"
#include "chrome/browser/extensions/event_router.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/signin/token_service.h"
+#include "chrome/browser/signin/token_service_factory.h"
#include "chrome/common/extensions/api/experimental_push_messaging.h"
#include "content/public/browser/browser_thread.h"
#include "googleurl/src/gurl.h"
+#include "chrome/browser/extensions/api/push_messaging/obfuscated_gaia_id_fetcher.h"
+
+using content::BrowserThread;
namespace extensions {
@@ -43,4 +48,63 @@ void PushMessagingEventRouter::OnMessage(const std::string& extension_id,
GURL());
}
+PushMessagingGetChannelIdFunction::PushMessagingGetChannelIdFunction() {}
+
+PushMessagingGetChannelIdFunction::~PushMessagingGetChannelIdFunction() {}
+
+bool PushMessagingGetChannelIdFunction::RunImpl() {
+ // Start the async fetch of the GAIA ID.
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ net::URLRequestContextGetter* context = profile()->GetRequestContext();
+ TokenService* token_service = TokenServiceFactory::GetForProfile(profile());
+ const std::string& refresh_token =
+ token_service->GetOAuth2LoginRefreshToken();
+ fetcher_.reset(new ObfuscatedGaiaIdFetcher(context, this, refresh_token));
+
+ // Keep the PushMessagingGetChannelIdFunction object alive until we get
+ // a response.
Munjal (Google) 2012/08/20 21:16:22 Nit: Remove this comment in favor of the comment I
Pete Williamson 2012/08/20 22:26:45 Done.
+ AddRef();
Munjal (Google) 2012/08/20 21:16:22 Nit: add the following comment on the same line as
Pete Williamson 2012/08/20 22:26:45 Done.
+ fetcher_->Start();
+
+ // Will finish asynchronously.
+ return true;
+}
+
+void PushMessagingGetChannelIdFunction::Respond(
+ const std::string& gaia_id, long status) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ // Unpack the status and GaiaId parameters, and use it to build the
+ // channel ID here.
+ std::string channel_id(gaia_id);
+ if (!gaia_id.empty()) {
Munjal (Google) 2012/08/20 21:16:22 shouldn't we bail out if gaia_id is empty?
Pete Williamson 2012/08/20 22:26:45 Even if the gaia_id is empty, we still need to ret
+ channel_id += ".";
+ channel_id += extension_id();
+ }
+
+ // TODO(petewil): It may be a good idea to further
+ // obfuscate the channel ID to prevent the user's obfuscated GAIA ID
+ // from being readily obtained. Security review will tell us if we need to.
+
+ // Create a ChannelId results object and set the fields.
+ glue::ChannelIdResult result;
+ result.channel_id = channel_id;
+ result.status = status;
+ results_ = glue::GetChannelId::Results::Create(result);
+ SendResponse(true);
+
+ // Once we have handed off the response, we can allow the
+ // PushMessagingGetChannelIdFunction object to die.
Munjal (Google) 2012/08/20 21:16:22 Nit: Remove this comment in favor the comment I su
Pete Williamson 2012/08/20 22:26:45 Done.
+ Release();
Munjal (Google) 2012/08/20 21:16:22 Nit: Add the following comment to be consistent wi
Pete Williamson 2012/08/20 22:26:45 Done.
+}
+
+void PushMessagingGetChannelIdFunction::OnObfuscatedGaiaIdFetchSuccess(
+ const std::string& gaia_id) {
+ Respond(gaia_id, 0);
+}
+
+void PushMessagingGetChannelIdFunction::OnObfuscatedGaiaIdFetchFailure(
+ const GoogleServiceAuthError& error) {
+ Respond(std::string(), error.state());
+}
+
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698