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

Unified Diff: chrome/browser/extensions/token_cache/token_cache_service.h

Issue 12380006: Build a new TokenCacheService so I can stop using TokenService for something it wasn't designed for. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Token Cache Service - fix gypi Created 7 years, 9 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
Index: chrome/browser/extensions/token_cache/token_cache_service.h
diff --git a/chrome/browser/extensions/token_cache/token_cache_service.h b/chrome/browser/extensions/token_cache/token_cache_service.h
new file mode 100644
index 0000000000000000000000000000000000000000..683e4aa0b1869dbdf046561f4d757019fcc42af7
--- /dev/null
+++ b/chrome/browser/extensions/token_cache/token_cache_service.h
@@ -0,0 +1,68 @@
+// 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.
+
+#ifndef CHROME_BROWSER_EXTENSIONS_TOKEN_CACHE_TOKEN_CACHE_SERVICE_H_
+#define CHROME_BROWSER_EXTENSIONS_TOKEN_CACHE_TOKEN_CACHE_SERVICE_H_
+
+#include <map>
+#include <string>
+
+#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"
+
+namespace content {
+class NotificationSource;
+}
+
+class Profile;
+
+namespace extensions {
+
+// 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.
asargent_no_longer_on_chrome 2013/03/12 00:11:31 We deciding to clear out the token cache when chro
Pete Williamson 2013/03/12 00:39:25 The token is only used by Push Messaging. If ther
+class TokenCacheService : public ProfileKeyedService,
+ public content::NotificationObserver {
+ 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,
+ base::TimeDelta time_to_live);
+
+ // 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);
+
+ // inherited from NotificationObserver
asargent_no_longer_on_chrome 2013/03/12 00:11:31 nit: capitalize Inherited, and finish sentence wit
Pete Williamson 2013/03/12 00:39:25 Done.
+ virtual void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) OVERRIDE;
+
+ private:
+ struct TokenCacheData {
+ std::string token;
+ base::Time expiration_time;
+ };
+
+ std::map<std::string, TokenCacheData> token_cache_;
asargent_no_longer_on_chrome 2013/03/12 00:11:31 Would it be worth mentioning in a comment here wha
Pete Williamson 2013/03/12 00:39:25 Done.
+ content::NotificationRegistrar registrar_;
+ const Profile* const profile_;
+
+ friend class TokenCacheTest;
asargent_no_longer_on_chrome 2013/03/12 00:11:31 nit: I don't think this is a hard rule in the styl
Pete Williamson 2013/03/12 00:39:25 Done.
+
+ DISALLOW_COPY_AND_ASSIGN(TokenCacheService);
+};
+
+} // namespace extensions
+
+#endif // CHROME_BROWSER_EXTENSIONS_TOKEN_CACHE_TOKEN_CACHE_SERVICE_H_

Powered by Google App Engine
This is Rietveld 408576698