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"
11 #include "google_apis/gaia/oauth2_token_service.h"
13 class GoogleServiceAuthError;
20 class URLRequestContextGetter;
23 namespace extensions {
25 // Fetches obfuscated Gaia ID of the Google Account that is logged in to Chrome.
26 // This starts an asynchronous operation which reports success to the delegate.
27 // Call "Start()" to start the async fetch.
28 class ObfuscatedGaiaIdFetcher : public OAuth2ApiCallFlow {
30 // Delegate interface that is called when obfuscated Gaia id fetch
34 virtual void OnObfuscatedGaiaIdFetchSuccess(
35 const std::string& obfuscated_id) {}
36 virtual void OnObfuscatedGaiaIdFetchFailure(
37 const GoogleServiceAuthError& error) {}
38 virtual ~Delegate() {}
41 // TODO(petewil): Someday let's make a profile keyed service to cache
43 explicit ObfuscatedGaiaIdFetcher(Delegate* delegate);
44 ~ObfuscatedGaiaIdFetcher() override;
46 static OAuth2TokenService::ScopeSet GetScopes();
49 // OAuth2ApiCallFlow implementation
50 GURL CreateApiCallUrl() override;
51 std::string CreateApiCallBody() override;
52 void ProcessApiCallSuccess(const net::URLFetcher* source) override;
53 void ProcessApiCallFailure(const net::URLFetcher* source) override;
56 FRIEND_TEST_ALL_PREFIXES(ObfuscatedGaiaIdFetcherTest, SetUp);
57 FRIEND_TEST_ALL_PREFIXES(ObfuscatedGaiaIdFetcherTest, ParseResponse);
58 FRIEND_TEST_ALL_PREFIXES(ObfuscatedGaiaIdFetcherTest, ProcessApiCallSuccess);
59 FRIEND_TEST_ALL_PREFIXES(ObfuscatedGaiaIdFetcherTest, ProcessApiCallFailure);
61 void ReportSuccess(const std::string& obfuscated_id);
62 void ReportFailure(const GoogleServiceAuthError& error);
64 // Get the obfuscated Gaia ID out of the response body.
65 static bool ParseResponse(
66 const std::string& data, std::string* obfuscated_id);
68 // Unowned pointer to the delegate. Normally the delegate owns
69 // this fetcher class.
72 DISALLOW_COPY_AND_ASSIGN(ObfuscatedGaiaIdFetcher);
75 } // namespace extensions
77 #endif // CHROME_BROWSER_EXTENSIONS_API_PUSH_MESSAGING_OBFUSCATED_GAIA_ID_FETCHER_H_