Index: chrome/browser/extensions/api/token_cache/token_cache.h |
diff --git a/chrome/browser/extensions/api/token_cache/token_cache.h b/chrome/browser/extensions/api/token_cache/token_cache.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..dd4c84233e856ffe0b788f7911ef4f9367af2898 |
--- /dev/null |
+++ b/chrome/browser/extensions/api/token_cache/token_cache.h |
@@ -0,0 +1,74 @@ |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+// This class caches tokens for the current user. It will clear tokens out |
+// when the user logs out or after the specified timeout interval, or when |
+// the instance of chrome shuts down. |
+ |
+#ifndef CHROME_BROWSER_EXTENSIONS_API_TOKEN_CACHE_TOKEN_CACHE_H_ |
+#define CHROME_BROWSER_EXTENSIONS_API_TOKEN_CACHE_TOKEN_CACHE_H_ |
+ |
+#include <string> |
+#include <vector> |
+ |
+#include "base/basictypes.h" |
+#include "base/compiler_specific.h" |
+#include "base/time.h" |
+#include "chrome/browser/profiles/profile_keyed_service.h" |
+#include "content/public/browser/notification_observer.h" |
+#include "content/public/browser/notification_registrar.h" |
+#include "content/public/browser/notification_service.h" |
dcheng
2013/03/04 22:40:59
I think this include isn't needed.
Pete Williamson
2013/03/05 19:42:25
Nope, we need it for content::Source<Profile>
|
+ |
+class Profile; |
+ |
+struct TokenCacheData { |
+ std::string token_name; |
+ std::string token; |
+ base::Time expiration_time; |
+}; |
+ |
+// TODO: Should I put this in a namespace? Which one? |
dcheng
2013/03/04 22:40:59
I'm not sure that "api/token_cache" is an appropri
Pete Williamson
2013/03/05 19:42:25
Done.
|
+ |
+class TokenCacheService : public ProfileKeyedService, |
+ content::NotificationObserver { |
+ |
dcheng
2013/03/04 22:40:59
Extra newline.
Pete Williamson
2013/03/05 19:42:25
Done.
|
+ public: |
+ explicit TokenCacheService(Profile* profile); |
+ virtual ~TokenCacheService(); |
+ |
+ // Store a token for the currently logged in user. We will look it up later by |
+ // the name given here, and we will expire the token after the timeout. For a |
+ // timeout of 0, we never expire the token. After time_to_live expires, the |
+ // token will be expired. |
+ void StoreToken(const std::string& token_name, const std::string& token_value, |
+ const base::TimeDelta time_to_live); |
dcheng
2013/03/04 22:40:59
No const.
Pete Williamson
2013/03/05 19:42:25
Done.
|
+ |
+ // Retrieve a token for the currently logged in user. This returns an empty |
+ // string if the token was not found or timed out. |
+ std::string RetrieveToken(const std::string& token_name); |
+ |
+ std::vector<TokenCacheData>::iterator FindMatch( |
+ const std::string& token_name); |
+ |
+ // inherited from ProfileKeyedService |
+ virtual void Shutdown() OVERRIDE; |
+ |
+ // inherited from NotificationObserver |
+ virtual void Observe(int type, |
+ const content::NotificationSource& source, |
+ const content::NotificationDetails& details) OVERRIDE; |
+ |
+ private: |
+ // TODO(petewil): If we start putting lots of tokens in here, use a map |
+ // instead because the lookup time is O(n). |
+ std::vector<TokenCacheData> token_cache_; |
+ content::NotificationRegistrar registrar_; |
+ const Profile* profile_; |
+ |
+ friend class TokenCacheTest; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(TokenCacheService); |
+}; |
+ |
+#endif // CHROME_BROWSER_EXTENSIONS_API_TOKEN_CACHE_TOKEN_CACHE_H_ |