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.
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_
10 #include "google_apis/gaia/oauth2_api_call_flow.h"
12 class GoogleServiceAuthError;
19 class URLRequestContextGetter;
22 namespace extensions {
24 // Fetches obfuscated Gaia ID of the Google Account that is logged in to Chrome.
25 // This starts an asynchronous operation which reports success to the delegate.
26 // Call "Start()" to start the async fetch.
27 class ObfuscatedGaiaIdFetcher : public OAuth2ApiCallFlow {
29 // Delegate interface that is called when obfuscated Gaia id fetch
33 virtual void OnObfuscatedGaiaIdFetchSuccess(
34 const std::string& obfuscated_id) {}
35 virtual void OnObfuscatedGaiaIdFetchFailure(
36 const GoogleServiceAuthError& error) {}
37 virtual ~Delegate() {}
40 // TODO(petewil): Someday let's make a profile keyed service to cache
43 ObfuscatedGaiaIdFetcher(net::URLRequestContextGetter* context,
45 const std::string& refresh_token);
46 virtual ~ObfuscatedGaiaIdFetcher();
48 static std::vector<std::string> GetScopes();
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;
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);
68 void ReportSuccess(const std::string& obfuscated_id);
69 void ReportFailure(const GoogleServiceAuthError& error);
71 // Get the obfuscated Gaia ID out of the response body.
72 static bool ParseResponse(
73 const std::string& data, std::string* obfuscated_id);
75 // Unowned pointer to the delegate. Normally the delegate owns
76 // this fetcher class.
79 DISALLOW_COPY_AND_ASSIGN(ObfuscatedGaiaIdFetcher);
82 } // namespace extensions
84 #endif // CHROME_BROWSER_EXTENSIONS_API_PUSH_MESSAGING_OBFUSCATED_GAIA_ID_FETCHER_H_