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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/extensions/api/identity/identity_api.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/api/identity/identity_api.h
diff --git a/chrome/browser/extensions/api/identity/identity_api.h b/chrome/browser/extensions/api/identity/identity_api.h
index f7b444842c9eac37c6855181e5c2ca1dd914266a..f8a164e566d47636bdfca6bb41b819b6e295e1ad 100644
--- a/chrome/browser/extensions/api/identity/identity_api.h
+++ b/chrome/browser/extensions/api/identity/identity_api.h
@@ -90,7 +90,8 @@ class IdentityGetAuthTokenFunction : public AsyncExtensionFunction,
virtual void StartMintToken(IdentityMintRequestQueue::MintType type) OVERRIDE;
// OAuth2MintTokenFlow::Delegate implementation:
- virtual void OnMintTokenSuccess(const std::string& access_token) OVERRIDE;
+ virtual void OnMintTokenSuccess(const std::string& access_token,
+ int time_to_live) OVERRIDE;
virtual void OnMintTokenFailure(
const GoogleServiceAuthError& error) OVERRIDE;
virtual void OnIssueAdviceSuccess(
@@ -130,6 +131,19 @@ class IdentityGetAuthTokenFunction : public AsyncExtensionFunction,
scoped_ptr<IdentitySigninFlow> signin_flow_;
};
+class IdentityRemoveCachedAuthTokenFunction : public SyncExtensionFunction {
+ public:
+ DECLARE_EXTENSION_FUNCTION("experimental.identity.removeCachedAuthToken",
+ EXPERIMENTAL_IDENTITY_REMOVECACHEDAUTHTOKEN)
+ IdentityRemoveCachedAuthTokenFunction();
+
+ protected:
+ virtual ~IdentityRemoveCachedAuthTokenFunction();
+
+ // SyncExtensionFunction implementation:
+ virtual bool RunImpl() OVERRIDE;
+};
+
class IdentityLaunchWebAuthFlowFunction : public AsyncExtensionFunction,
public WebAuthFlow::Delegate {
public:
@@ -160,6 +174,35 @@ class IdentityLaunchWebAuthFlowFunction : public AsyncExtensionFunction,
std::vector<GURL> final_prefixes_;
};
+class IdentityTokenCacheValue {
+ public:
+ IdentityTokenCacheValue();
+ explicit IdentityTokenCacheValue(const IssueAdviceInfo& issue_advice);
+ IdentityTokenCacheValue(const std::string& token,
+ base::TimeDelta time_to_live);
+ ~IdentityTokenCacheValue();
+
+ // Order of these entries is used to determine whether or not new
+ // entries supercede older ones in SetCachedToken.
+ enum CacheValueStatus {
+ CACHE_STATUS_NOTFOUND,
+ CACHE_STATUS_ADVICE,
+ CACHE_STATUS_TOKEN
+ };
+
+ CacheValueStatus status() const;
+ const IssueAdviceInfo& issue_advice() const;
+ const std::string& token() const;
+
+ private:
+ bool is_expired() const;
+
+ CacheValueStatus status_;
+ IssueAdviceInfo issue_advice_;
+ std::string token_;
+ base::Time expiration_time_;
+};
+
class IdentityAPI : public ProfileKeyedAPI,
public SigninGlobalError::AuthStatusProvider,
public content::NotificationObserver {
@@ -171,6 +214,16 @@ class IdentityAPI : public ProfileKeyedAPI,
// Request serialization queue for getAuthToken.
IdentityMintRequestQueue* mint_queue();
+ // Token cache
+ void SetCachedToken(const std::string& extension_id,
+ const std::vector<std::string> scopes,
+ const IdentityTokenCacheValue& token_data);
+ void EraseCachedToken(const std::string& extension_id,
+ const std::string& token);
+ void EraseAllCachedTokens();
+ const IdentityTokenCacheValue& GetCachedToken(
+ const std::string& extension_id, const std::vector<std::string> scopes);
+
void ReportAuthError(const GoogleServiceAuthError& error);
// ProfileKeyedAPI implementation.
@@ -188,6 +241,15 @@ class IdentityAPI : public ProfileKeyedAPI,
private:
friend class ProfileKeyedAPIFactory<IdentityAPI>;
+ struct TokenCacheKey {
+ TokenCacheKey(const std::string& extension_id,
+ const std::set<std::string> scopes);
+ ~TokenCacheKey();
+ bool operator<(const TokenCacheKey& rhs) const;
+ std::string extension_id;
+ std::set<std::string> scopes;
+ };
+
// ProfileKeyedAPI implementation.
static const char* service_name() {
return "IdentityAPI";
@@ -200,6 +262,7 @@ class IdentityAPI : public ProfileKeyedAPI,
// Used to listen to notifications from the TokenService.
content::NotificationRegistrar registrar_;
IdentityMintRequestQueue mint_queue_;
+ std::map<TokenCacheKey, IdentityTokenCacheValue> token_cache_;
};
template <>
« 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