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

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: CR changes per Munjal and DCheng 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..e7fdcb559108896ce58ed86bd0d7faafb2ff3c6a 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,68 @@ void PushMessagingEventRouter::OnMessage(const std::string& extension_id,
GURL());
}
+PushMessagingGetChannelIdFunction::PushMessagingGetChannelIdFunction() {}
+
+PushMessagingGetChannelIdFunction::~PushMessagingGetChannelIdFunction() {}
+
+bool PushMessagingGetChannelIdFunction::RunImpl() {
+ // Start the async fetch of the GAIA ID.
+ StartGaiaIdFetch();
+
+ // Will finish asynchronously.
+ return true;
+}
+
+void PushMessagingGetChannelIdFunction::RespondOnUIThread(
Munjal (Google) 2012/08/20 20:01:25 I still don't understand fully whether we need to
Pete Williamson 2012/08/20 20:53:05 We aren't doing any thread posting anymore. Chang
+ const std::string& gaia_id, const long status) {
dcheng 2012/08/20 19:10:01 Just 'long' instead of 'const long'
Pete Williamson 2012/08/20 20:53:05 Done.
+ 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()) {
+ channel_id += ".";
+ channel_id += extension_id();
+ }
+
+ // TODO: (after initial checkin) It may be a good idea to further
dcheng 2012/08/20 19:10:01 TODO(petewil)
Pete Williamson 2012/08/20 20:53:05 Done.
+ // 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.
+ Release();
+}
+
+// Member function to start the fetch operation.
+// This must be called on the UI thread.
+void PushMessagingGetChannelIdFunction::StartGaiaIdFetch() {
+ net::URLRequestContextGetter* context = profile()->GetRequestContext();
+ TokenService* token_service = TokenServiceFactory::GetForProfile(profile());
+ const std::string& refresh_token =
dcheng 2012/08/20 19:10:01 One space.
Pete Williamson 2012/08/20 20:53:05 Done.
+ token_service->GetOAuth2LoginRefreshToken();
+
+ fetcher_.reset(new ObfuscatedGaiaIdFetcher(context, this, refresh_token));
+ // Keep the PushMessagingGetChannelIdFunction object alive until we get
+ // a response.
+ AddRef();
dcheng 2012/08/20 19:10:01 My preference would be to move this into RunImpl,
Pete Williamson 2012/08/20 20:53:05 Done. (Actually, I moved the whole function into R
+ fetcher_->Start();
+}
+
+void PushMessagingGetChannelIdFunction::OnObfuscatedGaiaIdFetchSuccess(
+ const std::string& gaia_id) {
+ RespondOnUIThread(gaia_id, 0);
+}
+
+void PushMessagingGetChannelIdFunction::OnObfuscatedGaiaIdFetchFailure(
+ const GoogleServiceAuthError& error) {
+ RespondOnUIThread(std::string(), error.state());
+}
+
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698