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..6047faeb77d67242724fc353cc6e941b103fe58a |
| --- /dev/null |
| +++ b/chrome/browser/extensions/api/push_messaging/obfuscated_gaia_id_fetcher.h |
| @@ -0,0 +1,116 @@ |
| +// 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> |
|
Munjal (Google)
2012/08/09 21:44:29
It seems that you are not using vector in the head
Pete Williamson
2012/08/13 21:21:14
Now we need it, left in place
|
| + |
| +#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 { |
| + |
| +// This class implements the OAuth2 flow to Google to call the |
| +// chrome web store abstraction for caling OAuth2 |
| +// to get an obfuscated channel ID. |
|
Munjal (Google)
2012/08/09 21:44:29
The comment is a bit confusing. Let us just say:
"
Pete Williamson
2012/08/13 21:21:14
Done.
|
| +class ObfuscatedGaiaIdFetcher : public OAuth2ApiCallFlow { |
| + public: |
| + // Parameters needed to get an Obfuscated Gaia ID. |
| + struct Parameters { |
| + public: |
| + Parameters(); |
| + Parameters(const std::string& rt, |
| + const std::string& eid); |
|
Munjal (Google)
2012/08/09 21:44:29
We currently don't use extension id. I think we sh
Pete Williamson
2012/08/13 21:21:14
To avoid creating more dependencies, and leave my
|
| + ~Parameters(); |
| + |
| + std::string login_refresh_token; |
| + std::string extension_id; |
| + }; |
| + |
| + // Interface for a delegate to be notified of changes when |
| + // the operation succeeds or fails. Pass your delegate in to |
|
Munjal (Google)
2012/08/09 21:44:29
May be just say:
"Delegate interface that is calle
Pete Williamson
2012/08/13 21:21:14
Done.
|
| + // the class constructor when creating this class if you |
| + // want to be notified when a result arrives. |
|
Munjal (Google)
2012/08/09 21:44:29
Remove second sentence of the comment (i.e. "Pass
|
| + class Delegate { |
| + public: |
| + virtual void OnObfuscatedGaiaIdFetchSuccess( |
| + const std::string& access_token) {} |
|
Munjal (Google)
2012/08/09 21:44:29
This callback should pass back the obfuscated id,
|
| + virtual void OnObfuscatedGaiaIdFetchFailure( |
| + const GoogleServiceAuthError& error) {} |
| + |
| + protected: |
| + virtual ~Delegate() {} |
| + }; |
| + |
| + ObfuscatedGaiaIdFetcher(net::URLRequestContextGetter* context, |
|
Munjal (Google)
2012/08/09 21:44:29
If we remove Parameters, we will probably need to
Pete Williamson
2012/08/13 21:21:14
We don't need a Profile* if we pass in the refresh
|
| + Delegate* delegate, |
| + const Parameters& parameters); |
| + virtual ~ObfuscatedGaiaIdFetcher(); |
| + |
| + // 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/09 21:44:29
I suggest we remove these two methods from here an
Pete Williamson
2012/08/13 21:21:14
marked TODO for now.
|
| + |
| + 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& access_token); |
|
Munjal (Google)
2012/08/09 21:44:29
Parameter name should be obfuscated_id or such.
Pete Williamson
2012/08/13 21:21:14
Done.
|
| + void ReportFailure(const GoogleServiceAuthError& error); |
| + |
| + // Get the obfuscated GAIA ID out of the response body. |
| + static bool ParseResponse( |
| + const std::string& data, std::string* channel_id); |
|
Munjal (Google)
2012/08/09 21:44:29
Nit: channel_id -> obfuscated_id?
Pete Williamson
2012/08/13 21:21:14
Done.
|
| + |
| + net::URLRequestContextGetter* context_; |
| + Delegate* delegate_; |
| + Parameters parameters_; |
| + std::string obfuscated_gaia_id_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ObfuscatedGaiaIdFetcher); |
| +}; |
| + |
| +} // namespace extensions |
| + |
| +#endif // CHROME_BROWSER_EXTENSIONS_API_PUSH_MESSAGING_OBFUSCATED_GAIA_ID_FETCHER_H_ |