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> | |
| 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 // Fetches obfuscated gaia id of the Google Account that is logged in to Chrome | |
| 32 class ObfuscatedGaiaIdFetcher : public OAuth2ApiCallFlow { | |
| 33 | |
| 34 public: | |
| 35 // Delegate interface that is called when obfuscated gaia id fetch | |
| 36 // succeeds or fails. | |
| 37 class Delegate { | |
| 38 public: | |
| 39 virtual void OnObfuscatedGaiaIdFetchSuccess( | |
| 40 const std::string& obfuscated_id) {} | |
| 41 virtual void OnObfuscatedGaiaIdFetchFailure( | |
| 42 const GoogleServiceAuthError& error) {} | |
| 43 | |
| 44 protected: | |
| 45 virtual ~Delegate() {} | |
| 46 }; | |
| 47 | |
| 48 ObfuscatedGaiaIdFetcher(net::URLRequestContextGetter* context, | |
| 49 Delegate* delegate, | |
| 50 const std::string& refreshToken, | |
|
Munjal (Google)
2012/08/15 20:15:44
refresh_token
Pete Williamson
2012/08/15 22:02:29
Done.
| |
| 51 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
| |
| 52 virtual ~ObfuscatedGaiaIdFetcher(); | |
| 53 | |
| 54 // TODO: Move these two methods into a new class, a profileKeyedService | |
| 55 // 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.
| |
| 56 // When the user logs out of chrome, clear the token so we get a fresh | |
| 57 // token for the next user to sign in to chrome. | |
| 58 // void ClearGaiaId() { obfuscated_gaia_id_.clear(); } | |
| 59 // Return whatever we have cached for a Gaia ID, | |
| 60 // or an empty string if we don't have anything. | |
| 61 // TODO: Munjal thinks it would be better not to have this class cache | |
| 62 // the obfuscated GAIA id. Chat with him to understand why, since I thought | |
| 63 // caching is a main job of this class. | |
| 64 // const std::string& GetCachedObfuscatedGaiaId() | |
| 65 // { 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
| |
| 66 | |
| 67 protected: | |
| 68 // Implementation of template methods in OAuth2ApiCallFlow. | |
| 69 virtual GURL CreateApiCallUrl() OVERRIDE; | |
| 70 virtual std::string CreateApiCallBody() OVERRIDE; | |
| 71 | |
| 72 virtual void ProcessApiCallSuccess( | |
| 73 const net::URLFetcher* source) OVERRIDE; | |
| 74 virtual void ProcessApiCallFailure( | |
| 75 const net::URLFetcher* source) OVERRIDE; | |
| 76 virtual void ProcessNewAccessToken(const std::string& access_token) OVERRIDE; | |
| 77 virtual void ProcessMintAccessTokenFailure( | |
| 78 const GoogleServiceAuthError& error) OVERRIDE; | |
| 79 | |
| 80 private: | |
| 81 friend class ObfuscatedGaiaIdFetcherTest; | |
| 82 FRIEND_TEST_ALL_PREFIXES(ObfuscatedGaiaIdFetcherTest, SetUp); | |
| 83 FRIEND_TEST_ALL_PREFIXES(ObfuscatedGaiaIdFetcherTest, ParseResponse); | |
| 84 FRIEND_TEST_ALL_PREFIXES(ObfuscatedGaiaIdFetcherTest, ProcessApiCallSuccess); | |
| 85 FRIEND_TEST_ALL_PREFIXES(ObfuscatedGaiaIdFetcherTest, ProcessApiCallFailure); | |
| 86 | |
| 87 void ReportSuccess(const std::string& obfuscated_id); | |
| 88 void ReportFailure(const GoogleServiceAuthError& error); | |
| 89 | |
| 90 // Get the obfuscated GAIA ID out of the response body. | |
| 91 static bool ParseResponse( | |
| 92 const std::string& data, std::string* obfuscated_id); | |
| 93 | |
| 94 Delegate* delegate_; | |
| 95 std::string obfuscated_gaia_id_; | |
| 96 | |
| 97 DISALLOW_COPY_AND_ASSIGN(ObfuscatedGaiaIdFetcher); | |
| 98 }; | |
| 99 | |
| 100 } // namespace extensions | |
| 101 | |
| 102 #endif // CHROME_BROWSER_EXTENSIONS_API_PUSH_MESSAGING_OBFUSCATED_GAIA_ID_FETCH ER_H_ | |
| OLD | NEW |