Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_PUSH_MESSAGING_OBFUSCATED_GAIA_ID_FETCHER_ H_ | |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_PUSH_MESSAGING_OBFUSCATED_GAIA_ID_FETCHER_ H_ | |
| 7 | |
| 8 #include <string> | |
| 9 #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
| |
| 10 | |
| 11 #include "base/string16.h" | |
| 12 #include "chrome/common/net/gaia/oauth2_api_call_flow.h" | |
| 13 | |
| 14 class GoogleServiceAuthError; | |
| 15 class ObfuscatedGaiaIdFetchTest; | |
| 16 | |
| 17 namespace base { | |
| 18 class DictionaryValue; | |
| 19 } | |
| 20 | |
| 21 namespace content { | |
| 22 class URLFetcher; | |
| 23 } | |
| 24 | |
| 25 namespace net { | |
| 26 class URLRequestContextGetter; | |
| 27 } | |
| 28 | |
| 29 namespace extensions { | |
| 30 | |
| 31 // This class implements the OAuth2 flow to Google to call the | |
| 32 // chrome web store abstraction for caling OAuth2 | |
| 33 // 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.
| |
| 34 class ObfuscatedGaiaIdFetcher : public OAuth2ApiCallFlow { | |
| 35 public: | |
| 36 // Parameters needed to get an Obfuscated Gaia ID. | |
| 37 struct Parameters { | |
| 38 public: | |
| 39 Parameters(); | |
| 40 Parameters(const std::string& rt, | |
| 41 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
| |
| 42 ~Parameters(); | |
| 43 | |
| 44 std::string login_refresh_token; | |
| 45 std::string extension_id; | |
| 46 }; | |
| 47 | |
| 48 // Interface for a delegate to be notified of changes when | |
| 49 // 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.
| |
| 50 // the class constructor when creating this class if you | |
| 51 // 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
| |
| 52 class Delegate { | |
| 53 public: | |
| 54 virtual void OnObfuscatedGaiaIdFetchSuccess( | |
| 55 const std::string& access_token) {} | |
|
Munjal (Google)
2012/08/09 21:44:29
This callback should pass back the obfuscated id,
| |
| 56 virtual void OnObfuscatedGaiaIdFetchFailure( | |
| 57 const GoogleServiceAuthError& error) {} | |
| 58 | |
| 59 protected: | |
| 60 virtual ~Delegate() {} | |
| 61 }; | |
| 62 | |
| 63 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
| |
| 64 Delegate* delegate, | |
| 65 const Parameters& parameters); | |
| 66 virtual ~ObfuscatedGaiaIdFetcher(); | |
| 67 | |
| 68 // When the user logs out of chrome, clear the token so we get a fresh | |
| 69 // token for the next user to sign in to chrome. | |
| 70 void ClearGaiaId() { obfuscated_gaia_id_.clear(); } | |
| 71 | |
| 72 // Return whatever we have cached for a Gaia ID, | |
| 73 // or an empty string if we don't have anything. | |
| 74 // TODO: Munjal thinks it would be better not to have this class cache | |
| 75 // the obfuscated GAIA id. Chat with him to understand why, since I thought | |
| 76 // caching is a main job of this class. | |
| 77 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.
| |
| 78 | |
| 79 protected: | |
| 80 // Implementation of template methods in OAuth2ApiCallFlow. | |
| 81 virtual GURL CreateApiCallUrl() OVERRIDE; | |
| 82 virtual std::string CreateApiCallBody() OVERRIDE; | |
| 83 | |
| 84 virtual void ProcessApiCallSuccess( | |
| 85 const net::URLFetcher* source) OVERRIDE; | |
| 86 virtual void ProcessApiCallFailure( | |
| 87 const net::URLFetcher* source) OVERRIDE; | |
| 88 virtual void ProcessNewAccessToken(const std::string& access_token) OVERRIDE; | |
| 89 virtual void ProcessMintAccessTokenFailure( | |
| 90 const GoogleServiceAuthError& error) OVERRIDE; | |
| 91 | |
| 92 private: | |
| 93 friend class ObfuscatedGaiaIdFetcherTest; | |
| 94 FRIEND_TEST_ALL_PREFIXES(ObfuscatedGaiaIdFetcherTest, SetUp); | |
| 95 FRIEND_TEST_ALL_PREFIXES(ObfuscatedGaiaIdFetcherTest, ParseResponse); | |
| 96 FRIEND_TEST_ALL_PREFIXES(ObfuscatedGaiaIdFetcherTest, ProcessApiCallSuccess); | |
| 97 FRIEND_TEST_ALL_PREFIXES(ObfuscatedGaiaIdFetcherTest, ProcessApiCallFailure); | |
| 98 | |
| 99 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.
| |
| 100 void ReportFailure(const GoogleServiceAuthError& error); | |
| 101 | |
| 102 // Get the obfuscated GAIA ID out of the response body. | |
| 103 static bool ParseResponse( | |
| 104 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.
| |
| 105 | |
| 106 net::URLRequestContextGetter* context_; | |
| 107 Delegate* delegate_; | |
| 108 Parameters parameters_; | |
| 109 std::string obfuscated_gaia_id_; | |
| 110 | |
| 111 DISALLOW_COPY_AND_ASSIGN(ObfuscatedGaiaIdFetcher); | |
| 112 }; | |
| 113 | |
| 114 } // namespace extensions | |
| 115 | |
| 116 #endif // CHROME_BROWSER_EXTENSIONS_API_PUSH_MESSAGING_OBFUSCATED_GAIA_ID_FETCH ER_H_ | |
| OLD | NEW |