| 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 // This file has code to fetch the Obfuscated GAIA ID from the server |
| 6 |
| 7 #ifndef CHROME_BROWSER_EXTENSIONS_API_PUSH_MESSAGING_OBFUSCATED_GAIA_ID_FETCHER_
H_ |
| 8 #define CHROME_BROWSER_EXTENSIONS_API_PUSH_MESSAGING_OBFUSCATED_GAIA_ID_FETCHER_
H_ |
| 9 |
| 10 #include <string> |
| 11 |
| 12 #include "chrome/common/net/gaia/oauth2_api_call_flow.h" |
| 13 |
| 14 class GoogleServiceAuthError; |
| 15 |
| 16 namespace content { |
| 17 class URLFetcher; |
| 18 } |
| 19 |
| 20 namespace net { |
| 21 class URLRequestContextGetter; |
| 22 } |
| 23 |
| 24 namespace extensions { |
| 25 |
| 26 // Fetches obfuscated gaia id of the Google Account that is logged in to Chrome. |
| 27 // This starts an asynchronous operation which reports success to the delegate. |
| 28 // Call "Start()" to start the async fetch. |
| 29 class ObfuscatedGaiaIdFetcher : public OAuth2ApiCallFlow { |
| 30 public: |
| 31 // Delegate interface that is called when obfuscated gaia id fetch |
| 32 // succeeds or fails. |
| 33 class Delegate { |
| 34 public: |
| 35 virtual void OnObfuscatedGaiaIdFetchSuccess( |
| 36 const std::string& obfuscated_id) {} |
| 37 virtual void OnObfuscatedGaiaIdFetchFailure( |
| 38 const GoogleServiceAuthError& error) {} |
| 39 virtual ~Delegate() {} |
| 40 }; |
| 41 |
| 42 // TODO(petewil): Someday let's make a profile keyed service to cache |
| 43 // the GAIA ID. |
| 44 |
| 45 ObfuscatedGaiaIdFetcher(net::URLRequestContextGetter* context, |
| 46 Delegate* delegate, |
| 47 const std::string& refresh_token); |
| 48 virtual ~ObfuscatedGaiaIdFetcher(); |
| 49 |
| 50 protected: |
| 51 // OAuth2ApiCallFlow implementation |
| 52 virtual GURL CreateApiCallUrl() OVERRIDE; |
| 53 virtual std::string CreateApiCallBody() OVERRIDE; |
| 54 virtual void ProcessApiCallSuccess( |
| 55 const net::URLFetcher* source) OVERRIDE; |
| 56 virtual void ProcessApiCallFailure( |
| 57 const net::URLFetcher* source) OVERRIDE; |
| 58 virtual void ProcessNewAccessToken(const std::string& access_token) OVERRIDE; |
| 59 virtual void ProcessMintAccessTokenFailure( |
| 60 const GoogleServiceAuthError& error) OVERRIDE; |
| 61 |
| 62 private: |
| 63 FRIEND_TEST_ALL_PREFIXES(ObfuscatedGaiaIdFetcherTest, SetUp); |
| 64 FRIEND_TEST_ALL_PREFIXES(ObfuscatedGaiaIdFetcherTest, ParseResponse); |
| 65 FRIEND_TEST_ALL_PREFIXES(ObfuscatedGaiaIdFetcherTest, ProcessApiCallSuccess); |
| 66 FRIEND_TEST_ALL_PREFIXES(ObfuscatedGaiaIdFetcherTest, ProcessApiCallFailure); |
| 67 |
| 68 void ReportSuccess(const std::string& obfuscated_id); |
| 69 void ReportFailure(const GoogleServiceAuthError& error); |
| 70 |
| 71 // Get the obfuscated GAIA ID out of the response body. |
| 72 static bool ParseResponse( |
| 73 const std::string& data, std::string* obfuscated_id); |
| 74 |
| 75 // Unowned pointer to the delegate. Normally the delegate owns |
| 76 // this fetcher class. |
| 77 Delegate* delegate_; |
| 78 |
| 79 DISALLOW_COPY_AND_ASSIGN(ObfuscatedGaiaIdFetcher); |
| 80 }; |
| 81 |
| 82 } // namespace extensions |
| 83 |
| 84 #endif // CHROME_BROWSER_EXTENSIONS_API_PUSH_MESSAGING_OBFUSCATED_GAIA_ID_FETCH
ER_H_ |
| OLD | NEW |