| 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..ecf71ae11fe4e5937b6c6c66ad934c06facd00e1 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,67 @@ 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));
|
| +
|
| + // Balanced in ReportResult()
|
| + AddRef();
|
| +
|
| + fetcher_->Start();
|
| +
|
| + // Will finish asynchronously.
|
| + return true;
|
| +}
|
| +
|
| +void PushMessagingGetChannelIdFunction::ReportResult(
|
| + 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()) {
|
| + channel_id += ".";
|
| + channel_id += extension_id();
|
| + } else if (status == 0) {
|
| + // If somehow we don't have an error set, but there is no GAIA ID,
|
| + // return an error now.
|
| + DCHECK(status != 0);
|
| + status = GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS;
|
| + }
|
| +
|
| + // 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);
|
| +
|
| + // Balanced in RunImpl
|
| + Release();
|
| +}
|
| +
|
| +void PushMessagingGetChannelIdFunction::OnObfuscatedGaiaIdFetchSuccess(
|
| + const std::string& gaia_id) {
|
| + ReportResult(gaia_id, 0);
|
| +}
|
| +
|
| +void PushMessagingGetChannelIdFunction::OnObfuscatedGaiaIdFetchFailure(
|
| + const GoogleServiceAuthError& error) {
|
| + ReportResult(std::string(), error.state());
|
| +}
|
| +
|
| } // namespace extensions
|
|
|