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

Side by Side Diff: chrome/browser/extensions/api/identity/identity_api.h

Issue 14329014: Identity API: Add token cache and identity.invalidateAuthToken. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rounding third rebase Created 7 years, 8 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
« no previous file with comments | « no previous file | chrome/browser/extensions/api/identity/identity_api.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_API_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_API_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_API_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 83
84 // Initiate/complete the sub-flows. 84 // Initiate/complete the sub-flows.
85 void StartSigninFlow(); 85 void StartSigninFlow();
86 void StartMintTokenFlow(IdentityMintRequestQueue::MintType type); 86 void StartMintTokenFlow(IdentityMintRequestQueue::MintType type);
87 void CompleteMintTokenFlow(); 87 void CompleteMintTokenFlow();
88 88
89 // IdentityMintRequestQueue::Request implementation: 89 // IdentityMintRequestQueue::Request implementation:
90 virtual void StartMintToken(IdentityMintRequestQueue::MintType type) OVERRIDE; 90 virtual void StartMintToken(IdentityMintRequestQueue::MintType type) OVERRIDE;
91 91
92 // OAuth2MintTokenFlow::Delegate implementation: 92 // OAuth2MintTokenFlow::Delegate implementation:
93 virtual void OnMintTokenSuccess(const std::string& access_token) OVERRIDE; 93 virtual void OnMintTokenSuccess(const std::string& access_token,
94 int time_to_live) OVERRIDE;
94 virtual void OnMintTokenFailure( 95 virtual void OnMintTokenFailure(
95 const GoogleServiceAuthError& error) OVERRIDE; 96 const GoogleServiceAuthError& error) OVERRIDE;
96 virtual void OnIssueAdviceSuccess( 97 virtual void OnIssueAdviceSuccess(
97 const IssueAdviceInfo& issue_advice) OVERRIDE; 98 const IssueAdviceInfo& issue_advice) OVERRIDE;
98 99
99 // IdentitySigninFlow::Delegate implementation: 100 // IdentitySigninFlow::Delegate implementation:
100 virtual void SigninSuccess(const std::string& token) OVERRIDE; 101 virtual void SigninSuccess(const std::string& token) OVERRIDE;
101 virtual void SigninFailed() OVERRIDE; 102 virtual void SigninFailed() OVERRIDE;
102 103
103 // ExtensionInstallPrompt::Delegate implementation: 104 // ExtensionInstallPrompt::Delegate implementation:
(...skipping 19 matching lines...) Expand all
123 std::string refresh_token_; 124 std::string refresh_token_;
124 bool should_prompt_for_signin_; 125 bool should_prompt_for_signin_;
125 126
126 // When launched in interactive mode, and if there is no existing grant, 127 // When launched in interactive mode, and if there is no existing grant,
127 // a permissions prompt will be popped up to the user. 128 // a permissions prompt will be popped up to the user.
128 IssueAdviceInfo issue_advice_; 129 IssueAdviceInfo issue_advice_;
129 scoped_ptr<ExtensionInstallPrompt> install_ui_; 130 scoped_ptr<ExtensionInstallPrompt> install_ui_;
130 scoped_ptr<IdentitySigninFlow> signin_flow_; 131 scoped_ptr<IdentitySigninFlow> signin_flow_;
131 }; 132 };
132 133
134 class IdentityRemoveCachedAuthTokenFunction : public SyncExtensionFunction {
135 public:
136 DECLARE_EXTENSION_FUNCTION("experimental.identity.removeCachedAuthToken",
137 EXPERIMENTAL_IDENTITY_REMOVECACHEDAUTHTOKEN)
138 IdentityRemoveCachedAuthTokenFunction();
139
140 protected:
141 virtual ~IdentityRemoveCachedAuthTokenFunction();
142
143 // SyncExtensionFunction implementation:
144 virtual bool RunImpl() OVERRIDE;
145 };
146
133 class IdentityLaunchWebAuthFlowFunction : public AsyncExtensionFunction, 147 class IdentityLaunchWebAuthFlowFunction : public AsyncExtensionFunction,
134 public WebAuthFlow::Delegate { 148 public WebAuthFlow::Delegate {
135 public: 149 public:
136 DECLARE_EXTENSION_FUNCTION("experimental.identity.launchWebAuthFlow", 150 DECLARE_EXTENSION_FUNCTION("experimental.identity.launchWebAuthFlow",
137 EXPERIMENTAL_IDENTITY_LAUNCHWEBAUTHFLOW) 151 EXPERIMENTAL_IDENTITY_LAUNCHWEBAUTHFLOW)
138 152
139 IdentityLaunchWebAuthFlowFunction(); 153 IdentityLaunchWebAuthFlowFunction();
140 154
141 // URL checking helpers. Public for testing. 155 // URL checking helpers. Public for testing.
142 // Checks to see if the current URL ends the flow. 156 // Checks to see if the current URL ends the flow.
(...skipping 10 matching lines...) Expand all
153 virtual void OnAuthFlowFailure(WebAuthFlow::Failure failure) OVERRIDE; 167 virtual void OnAuthFlowFailure(WebAuthFlow::Failure failure) OVERRIDE;
154 virtual void OnAuthFlowURLChange(const GURL& redirect_url) OVERRIDE; 168 virtual void OnAuthFlowURLChange(const GURL& redirect_url) OVERRIDE;
155 169
156 // Helper to initialize final URLs vector. 170 // Helper to initialize final URLs vector.
157 void InitFinalRedirectURLPrefixes(const std::string& extension_id); 171 void InitFinalRedirectURLPrefixes(const std::string& extension_id);
158 172
159 scoped_ptr<WebAuthFlow> auth_flow_; 173 scoped_ptr<WebAuthFlow> auth_flow_;
160 std::vector<GURL> final_prefixes_; 174 std::vector<GURL> final_prefixes_;
161 }; 175 };
162 176
177 class IdentityTokenCacheValue {
178 public:
179 IdentityTokenCacheValue();
180 explicit IdentityTokenCacheValue(const IssueAdviceInfo& issue_advice);
181 IdentityTokenCacheValue(const std::string& token,
182 base::TimeDelta time_to_live);
183 ~IdentityTokenCacheValue();
184
185 // Order of these entries is used to determine whether or not new
186 // entries supercede older ones in SetCachedToken.
187 enum CacheValueStatus {
188 CACHE_STATUS_NOTFOUND,
189 CACHE_STATUS_ADVICE,
190 CACHE_STATUS_TOKEN
191 };
192
193 CacheValueStatus status() const;
194 const IssueAdviceInfo& issue_advice() const;
195 const std::string& token() const;
196
197 private:
198 bool is_expired() const;
199
200 CacheValueStatus status_;
201 IssueAdviceInfo issue_advice_;
202 std::string token_;
203 base::Time expiration_time_;
204 };
205
163 class IdentityAPI : public ProfileKeyedAPI, 206 class IdentityAPI : public ProfileKeyedAPI,
164 public SigninGlobalError::AuthStatusProvider, 207 public SigninGlobalError::AuthStatusProvider,
165 public content::NotificationObserver { 208 public content::NotificationObserver {
166 public: 209 public:
167 explicit IdentityAPI(Profile* profile); 210 explicit IdentityAPI(Profile* profile);
168 virtual ~IdentityAPI(); 211 virtual ~IdentityAPI();
169 void Initialize(); 212 void Initialize();
170 213
171 // Request serialization queue for getAuthToken. 214 // Request serialization queue for getAuthToken.
172 IdentityMintRequestQueue* mint_queue(); 215 IdentityMintRequestQueue* mint_queue();
173 216
217 // Token cache
218 void SetCachedToken(const std::string& extension_id,
219 const std::vector<std::string> scopes,
220 const IdentityTokenCacheValue& token_data);
221 void EraseCachedToken(const std::string& extension_id,
222 const std::string& token);
223 void EraseAllCachedTokens();
224 const IdentityTokenCacheValue& GetCachedToken(
225 const std::string& extension_id, const std::vector<std::string> scopes);
226
174 void ReportAuthError(const GoogleServiceAuthError& error); 227 void ReportAuthError(const GoogleServiceAuthError& error);
175 228
176 // ProfileKeyedAPI implementation. 229 // ProfileKeyedAPI implementation.
177 virtual void Shutdown() OVERRIDE; 230 virtual void Shutdown() OVERRIDE;
178 static ProfileKeyedAPIFactory<IdentityAPI>* GetFactoryInstance(); 231 static ProfileKeyedAPIFactory<IdentityAPI>* GetFactoryInstance();
179 232
180 // AuthStatusProvider implementation. 233 // AuthStatusProvider implementation.
181 virtual GoogleServiceAuthError GetAuthStatus() const OVERRIDE; 234 virtual GoogleServiceAuthError GetAuthStatus() const OVERRIDE;
182 235
183 // content::NotificationObserver implementation. 236 // content::NotificationObserver implementation.
184 virtual void Observe(int type, 237 virtual void Observe(int type,
185 const content::NotificationSource& source, 238 const content::NotificationSource& source,
186 const content::NotificationDetails& details) OVERRIDE; 239 const content::NotificationDetails& details) OVERRIDE;
187 240
188 private: 241 private:
189 friend class ProfileKeyedAPIFactory<IdentityAPI>; 242 friend class ProfileKeyedAPIFactory<IdentityAPI>;
190 243
244 struct TokenCacheKey {
245 TokenCacheKey(const std::string& extension_id,
246 const std::set<std::string> scopes);
247 ~TokenCacheKey();
248 bool operator<(const TokenCacheKey& rhs) const;
249 std::string extension_id;
250 std::set<std::string> scopes;
251 };
252
191 // ProfileKeyedAPI implementation. 253 // ProfileKeyedAPI implementation.
192 static const char* service_name() { 254 static const char* service_name() {
193 return "IdentityAPI"; 255 return "IdentityAPI";
194 } 256 }
195 static const bool kServiceIsNULLWhileTesting = true; 257 static const bool kServiceIsNULLWhileTesting = true;
196 258
197 Profile* profile_; 259 Profile* profile_;
198 SigninManagerBase* signin_manager_; 260 SigninManagerBase* signin_manager_;
199 GoogleServiceAuthError error_; 261 GoogleServiceAuthError error_;
200 // Used to listen to notifications from the TokenService. 262 // Used to listen to notifications from the TokenService.
201 content::NotificationRegistrar registrar_; 263 content::NotificationRegistrar registrar_;
202 IdentityMintRequestQueue mint_queue_; 264 IdentityMintRequestQueue mint_queue_;
265 std::map<TokenCacheKey, IdentityTokenCacheValue> token_cache_;
203 }; 266 };
204 267
205 template <> 268 template <>
206 void ProfileKeyedAPIFactory<IdentityAPI>::DeclareFactoryDependencies(); 269 void ProfileKeyedAPIFactory<IdentityAPI>::DeclareFactoryDependencies();
207 270
208 } // namespace extensions 271 } // namespace extensions
209 272
210 #endif // CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_API_H_ 273 #endif // CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_API_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/api/identity/identity_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698