Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Side by Side Diff: chrome/browser/extensions/api/push_messaging/obfuscated_gaia_id_fetch.h

Issue 10837013: Chrome Cloud Messaging (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: InvalidationHandler + event Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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_FETCH_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_PUSH_MESSAGING_OBFUSCATED_GAIA_ID_FETCH_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/memory/weak_ptr.h"
12 #include "base/string16.h"
13 #include "chrome/common/net/gaia/oauth2_api_call_flow.h"
14
15 class GoogleServiceAuthError;
16 class ObfuscatedGaiaIdFetchTest;
17
18 namespace base {
19 class DictionaryValue;
20 }
21
22 namespace content {
23 class URLFetcher;
24 }
25
26 namespace net {
27 class URLRequestContextGetter;
28 }
29
30 namespace extension {
31
32 // This class implements the OAuth2 flow to Google to call the
33 // chrome web store API to get an obfuscated channel ID
34 //
35 class ObfuscatedGaiaIdFetch : public OAuth2ApiCallFlow {
36 public:
37
38 // Parameters needed to get an Obfuscated Gaia ID
39 struct Parameters {
40 public:
41 Parameters();
42 Parameters(const std::string& rt,
43 const std::string& eid,
44 const std::vector<std::string>& scopes_arg);
45 ~Parameters();
46
47 std::string login_refresh_token;
48 std::string extension_id;
49 std::vector<std::string> scopes;
50 };
51
52 // interface for a delegate to be notified of changes when
53 // the operation succeeds or fails. Pass your delegate in to
54 // the class constructor when creating this class if you
55 // want to be notified when a result arrives.
56 class Delegate {
57 public:
58 virtual void OnObfuscatedGaiaIdFetchSuccess(
59 const std::string& access_token) {}
60 virtual void OnObfuscatedGaiaIdFetchFailure(
61 const GoogleServiceAuthError& error) {}
62
63 protected:
64 virtual ~Delegate() {}
65 };
66
67 ObfuscatedGaiaIdFetch(net::URLRequestContextGetter* context,
68 Delegate* delegate,
69 const Parameters& parameters);
70 virtual ~ObfuscatedGaiaIdFetch();
71
72 // when the user logs out, clear the token so we get a fresh
73 // token for the next user
74 void ClearGaiaId()
75 { obfuscatedGaiaId_.clear(); }
76
77 // return whatever we have cached for a Gaia ID,
78 // or an empty string if we don't have anything
79 const std::string& GetCachedObfuscatedGaiaId()
80 { return obfuscatedGaiaId_; }
81
82 // begin a fetch operation. The Delegate will be called when
83 // the operation is complete (likely on a different thread)
84 void StartObfuscatedGaiaIdFetch()
85 { Start(); }
86
87 protected:
88 // Implementation of template methods in OAuth2ApiCallFlow.
89 virtual GURL CreateApiCallUrl() OVERRIDE;
90 virtual std::string CreateApiCallBody() OVERRIDE;
91
92 virtual void ProcessApiCallSuccess(
93 const net::URLFetcher* source) OVERRIDE;
94 virtual void ProcessApiCallFailure(
95 const net::URLFetcher* source) OVERRIDE;
96 virtual void ProcessNewAccessToken(
97 const std::string& access_token) OVERRIDE;
98 virtual void ProcessMintAccessTokenFailure(
99 const GoogleServiceAuthError& error) OVERRIDE;
100
101 private:
102 friend class ObfuscatedGaiaIdFetchTest;
103 FRIEND_TEST_ALL_PREFIXES(ObfuscatedGaiaIdFetchTest,
104 ParseGaiaTokenResponse);
105 FRIEND_TEST_ALL_PREFIXES(ObfuscatedGaiaIdFetchTest,
106 ProcessApiCallSuccess);
107 FRIEND_TEST_ALL_PREFIXES(ObfuscatedGaiaIdFetchTest,
108 ProcessApiCallFailure);
109 FRIEND_TEST_ALL_PREFIXES(ObfuscatedGaiaIdFetchTest,
110 ProcessObfuscatedGaiaIdFailure);
111
112 void ReportSuccess(const std::string& access_token);
113 void ReportFailure(const GoogleServiceAuthError& error);
114
115 // get the obfuscated GAIA ID out of the response body
116 static bool ParseObfuscatedGaiaIdFetchResponse(
117 const std::string& data, std::string* channel_id);
118
119 net::URLRequestContextGetter* context_;
120 Delegate* delegate_;
121 Parameters parameters_;
122 base::WeakPtrFactory<ObfuscatedGaiaIdFetch> weak_factory_;
123 std::string obfuscatedGaiaId_;
124
125 DISALLOW_COPY_AND_ASSIGN(ObfuscatedGaiaIdFetch);
126 };
127
128
129 } // namespace extension
130
131 #endif // CHROME_BROWSER_EXTENSIONS_API_PUSH_MESSAGING_OBFUSCATED_GAIA_ID_FETCH _H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698