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 | |
10 #include "google_apis/gaia/oauth2_api_call_flow.h" | |
11 #include "google_apis/gaia/oauth2_token_service.h" | |
12 | |
13 class GoogleServiceAuthError; | |
14 | |
15 namespace content { | |
16 class URLFetcher; | |
17 } | |
18 | |
19 namespace net { | |
20 class URLRequestContextGetter; | |
21 } | |
22 | |
23 namespace extensions { | |
24 | |
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 { | |
29 public: | |
30 // Delegate interface that is called when obfuscated Gaia id fetch | |
31 // succeeds or fails. | |
32 class Delegate { | |
33 public: | |
34 virtual void OnObfuscatedGaiaIdFetchSuccess( | |
35 const std::string& obfuscated_id) {} | |
36 virtual void OnObfuscatedGaiaIdFetchFailure( | |
37 const GoogleServiceAuthError& error) {} | |
38 virtual ~Delegate() {} | |
39 }; | |
40 | |
41 // TODO(petewil): Someday let's make a profile keyed service to cache | |
42 // the Gaia ID. | |
43 explicit ObfuscatedGaiaIdFetcher(Delegate* delegate); | |
44 ~ObfuscatedGaiaIdFetcher() override; | |
45 | |
46 static OAuth2TokenService::ScopeSet GetScopes(); | |
47 | |
48 protected: | |
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; | |
54 | |
55 private: | |
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); | |
60 | |
61 void ReportSuccess(const std::string& obfuscated_id); | |
62 void ReportFailure(const GoogleServiceAuthError& error); | |
63 | |
64 // Get the obfuscated Gaia ID out of the response body. | |
65 static bool ParseResponse( | |
66 const std::string& data, std::string* obfuscated_id); | |
67 | |
68 // Unowned pointer to the delegate. Normally the delegate owns | |
69 // this fetcher class. | |
70 Delegate* delegate_; | |
71 | |
72 DISALLOW_COPY_AND_ASSIGN(ObfuscatedGaiaIdFetcher); | |
73 }; | |
74 | |
75 } // namespace extensions | |
76 | |
77 #endif // CHROME_BROWSER_EXTENSIONS_API_PUSH_MESSAGING_OBFUSCATED_GAIA_ID_FETCH
ER_H_ | |
OLD | NEW |