Chromium Code Reviews| 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 aaa36a50af7813ba08a920ffc2c41f870c298377..c6b96f4595d60954c313e2be3903e5510b163c7e 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/profiles/profile_manager.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 "chrome/common/net/gaia/google_service_auth_error.h" |
| #include "content/public/browser/browser_thread.h" |
| #include "googleurl/src/gurl.h" |
| +#include "obfuscated_gaia_id_fetcher.h" |
| namespace extensions { |
| @@ -23,8 +28,56 @@ PushMessagingEventRouter::PushMessagingEventRouter(Profile* profile) |
| PushMessagingEventRouter::~PushMessagingEventRouter() {} |
| +// TODO: Move these methods to be on the class that eventually creates |
| +// the Obfuscated Gaia ID fetcher, and pass "this" from that class for |
| +// the delegate. |
| +class GaiaFetcherDelegate : public ObfuscatedGaiaIdFetcher::Delegate { |
| + public: |
| + GaiaFetcherDelegate() {} |
| + virtual ~GaiaFetcherDelegate() {} |
| + virtual void OnObfuscatedGaiaIdFetchSuccess( |
| + const std::string& access_token) { |
| + LOG(INFO) << "*** GaiaFetcherDelegate::OnObfuscatedGaiaIdFetchSuccess" |
| + << "- success, " << access_token << " ***"; |
| + delete this; // TODO: temp only, remove when part of outer class |
| + } |
| + virtual void OnObfuscatedGaiaIdFetchFailure( |
| + const GoogleServiceAuthError& error) { |
| + LOG(INFO) << "*** GaiaFetcherDelegate::OnObfuscatedGaiaIdFetchFailure, " |
| + << "error is " << (int) error.state() << " ***"; |
| + delete this; // TODO: temp only, remove when part of outer class |
| + } |
| + |
| +}; |
| + |
| +// free function to start the fetch operation |
| +void StartGaiaIdFetch(Profile* profile) { |
| + // TODO: Not for checkin, just for testing, remove all this before checkin |
| + // LOG(INFO) << "*** PushMessagingEventRouter::Init called ***"; |
| + TokenService* token_service = TokenServiceFactory::GetForProfile(profile); |
| + net::URLRequestContextGetter* context = profile->GetRequestContext(); |
| + const std::string refreshToken = token_service->GetOAuth2LoginRefreshToken(); |
| + GaiaFetcherDelegate* delegate = new GaiaFetcherDelegate(); |
| + std::vector<std::string> scopes; |
| + scopes.push_back( |
| + "https://www.googleapis.com/auth/chromewebstore.notification"); |
|
Munjal (Google)
2012/08/15 20:15:44
Put this scope in ObfuscatedGaiaIdFetcher class in
|
| + // TODO: Don't forget to manage the lifetime of the fetcher object |
| + ObfuscatedGaiaIdFetcher* fetcher = |
| + new ObfuscatedGaiaIdFetcher(context, delegate, refreshToken, scopes); |
| + fetcher->Start(); |
| + // LOG(INFO) << "*** PushMessagingEventRouter::Init exiting ***"; |
| +} |
| + |
| void PushMessagingEventRouter::Init() { |
| // TODO(dcheng): Add hooks into InvalidationHandler when landed. |
| + |
| + // TODO: remove this and do it the right way before checkin |
| + MessageLoop::current()->PostDelayedTask( |
| + FROM_HERE, |
| + base::Bind(&StartGaiaIdFetch, profile_), |
| + base::TimeDelta::FromMilliseconds(2000)); |
| + |
| + |
| } |
| void PushMessagingEventRouter::OnMessage(const std::string& extension_id, |