Chromium Code Reviews| Index: chrome/browser/extensions/api/push_messaging/obfuscated_gaia_id_fetcher.h |
| diff --git a/chrome/browser/extensions/api/push_messaging/obfuscated_gaia_id_fetcher.h b/chrome/browser/extensions/api/push_messaging/obfuscated_gaia_id_fetcher.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..0fdd4533778c272f7d5705ade5213c098f6252d8 |
| --- /dev/null |
| +++ b/chrome/browser/extensions/api/push_messaging/obfuscated_gaia_id_fetcher.h |
| @@ -0,0 +1,102 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_EXTENSIONS_API_PUSH_MESSAGING_OBFUSCATED_GAIA_ID_FETCHER_H_ |
| +#define CHROME_BROWSER_EXTENSIONS_API_PUSH_MESSAGING_OBFUSCATED_GAIA_ID_FETCHER_H_ |
| + |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "base/string16.h" |
| +#include "chrome/common/net/gaia/oauth2_api_call_flow.h" |
| + |
| +class GoogleServiceAuthError; |
| +class ObfuscatedGaiaIdFetchTest; |
| + |
| +namespace base { |
| +class DictionaryValue; |
| +} |
| + |
| +namespace content { |
| +class URLFetcher; |
| +} |
| + |
| +namespace net { |
| +class URLRequestContextGetter; |
| +} |
| + |
| +namespace extensions { |
| + |
| +// Fetches obfuscated gaia id of the Google Account that is logged in to Chrome |
| +class ObfuscatedGaiaIdFetcher : public OAuth2ApiCallFlow { |
| + |
| + public: |
| + // Delegate interface that is called when obfuscated gaia id fetch |
| + // succeeds or fails. |
| + class Delegate { |
| + public: |
| + virtual void OnObfuscatedGaiaIdFetchSuccess( |
| + const std::string& obfuscated_id) {} |
| + virtual void OnObfuscatedGaiaIdFetchFailure( |
| + const GoogleServiceAuthError& error) {} |
| + |
| + protected: |
| + virtual ~Delegate() {} |
| + }; |
| + |
| + ObfuscatedGaiaIdFetcher(net::URLRequestContextGetter* context, |
| + Delegate* delegate, |
| + const std::string& refreshToken, |
|
Munjal (Google)
2012/08/15 20:15:44
refresh_token
Pete Williamson
2012/08/15 22:02:29
Done.
|
| + const std::vector<std::string>& scopes); |
|
Munjal (Google)
2012/08/15 20:15:44
No need to take in scopes as an argument. The fetc
Pete Williamson
2012/08/15 22:02:29
That's a bit difficult in this case because we pas
|
| + virtual ~ObfuscatedGaiaIdFetcher(); |
| + |
| + // TODO: Move these two methods into a new class, a profileKeyedService |
| + // that lazily caches the ID |
|
Munjal (Google)
2012/08/15 20:15:44
I suggest just remove these two methods until we d
Pete Williamson
2012/08/15 22:02:29
Done.
|
| + // When the user logs out of chrome, clear the token so we get a fresh |
| + // token for the next user to sign in to chrome. |
| + // void ClearGaiaId() { obfuscated_gaia_id_.clear(); } |
| + // Return whatever we have cached for a Gaia ID, |
| + // or an empty string if we don't have anything. |
| + // TODO: Munjal thinks it would be better not to have this class cache |
| + // the obfuscated GAIA id. Chat with him to understand why, since I thought |
| + // caching is a main job of this class. |
| + // const std::string& GetCachedObfuscatedGaiaId() |
| + // { return obfuscated_gaia_id_; } |
|
Munjal (Google)
2012/08/15 20:15:44
I suggest we remove this method. But if you don't,
Pete Williamson
2012/08/15 22:02:29
I just removed them, they were only still in the c
|
| + |
| + protected: |
| + // Implementation of template methods in OAuth2ApiCallFlow. |
| + virtual GURL CreateApiCallUrl() OVERRIDE; |
| + virtual std::string CreateApiCallBody() OVERRIDE; |
| + |
| + virtual void ProcessApiCallSuccess( |
| + const net::URLFetcher* source) OVERRIDE; |
| + virtual void ProcessApiCallFailure( |
| + const net::URLFetcher* source) OVERRIDE; |
| + virtual void ProcessNewAccessToken(const std::string& access_token) OVERRIDE; |
| + virtual void ProcessMintAccessTokenFailure( |
| + const GoogleServiceAuthError& error) OVERRIDE; |
| + |
| + private: |
| + friend class ObfuscatedGaiaIdFetcherTest; |
| + FRIEND_TEST_ALL_PREFIXES(ObfuscatedGaiaIdFetcherTest, SetUp); |
| + FRIEND_TEST_ALL_PREFIXES(ObfuscatedGaiaIdFetcherTest, ParseResponse); |
| + FRIEND_TEST_ALL_PREFIXES(ObfuscatedGaiaIdFetcherTest, ProcessApiCallSuccess); |
| + FRIEND_TEST_ALL_PREFIXES(ObfuscatedGaiaIdFetcherTest, ProcessApiCallFailure); |
| + |
| + void ReportSuccess(const std::string& obfuscated_id); |
| + void ReportFailure(const GoogleServiceAuthError& error); |
| + |
| + // Get the obfuscated GAIA ID out of the response body. |
| + static bool ParseResponse( |
| + const std::string& data, std::string* obfuscated_id); |
| + |
| + Delegate* delegate_; |
| + std::string obfuscated_gaia_id_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ObfuscatedGaiaIdFetcher); |
| +}; |
| + |
| +} // namespace extensions |
| + |
| +#endif // CHROME_BROWSER_EXTENSIONS_API_PUSH_MESSAGING_OBFUSCATED_GAIA_ID_FETCHER_H_ |