Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 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 // This class caches tokens for the current user. It will clear tokens out | |
| 6 // when the user logs out or after the specified timeout interval, or when | |
| 7 // the instance of chrome shuts down. | |
| 8 | |
| 9 #ifndef CHROME_BROWSER_EXTENSIONS_TOKEN_CACHE_TOKEN_CACHE_H_ | |
| 10 #define CHROME_BROWSER_EXTENSIONS_TOKEN_CACHE_TOKEN_CACHE_H_ | |
| 11 | |
| 12 #include <map> | |
| 13 #include <string> | |
| 14 | |
| 15 #include "base/basictypes.h" | |
| 16 #include "base/compiler_specific.h" | |
| 17 #include "base/time.h" | |
| 18 #include "chrome/browser/profiles/profile_keyed_service.h" | |
| 19 #include "content/public/browser/notification_observer.h" | |
| 20 #include "content/public/browser/notification_registrar.h" | |
| 21 | |
| 22 namespace content { | |
| 23 class NotificationSource; | |
| 24 } | |
| 25 | |
| 26 class Profile; | |
| 27 | |
| 28 namespace extensions { | |
| 29 | |
| 30 struct TokenCacheData { | |
| 31 std::string token; | |
| 32 base::Time expiration_time; | |
| 33 }; | |
| 34 | |
| 35 class TokenCacheService : public ProfileKeyedService, | |
|
Andrew T Wilson (Slow)
2013/03/06 16:55:28
BTW, technically I think this file should be named
| |
| 36 public content::NotificationObserver { | |
| 37 public: | |
| 38 explicit TokenCacheService(Profile* profile); | |
| 39 virtual ~TokenCacheService(); | |
| 40 | |
| 41 // Store a token for the currently logged in user. We will look it up later by | |
| 42 // the name given here, and we will expire the token after the timeout. For a | |
| 43 // timeout of 0, we never expire the token. After time_to_live expires, the | |
| 44 // token will be expired. | |
| 45 void StoreToken(const std::string& token_name, const std::string& token_value, | |
| 46 base::TimeDelta time_to_live); | |
| 47 | |
| 48 // Retrieve a token for the currently logged in user. This returns an empty | |
| 49 // string if the token was not found or timed out. | |
| 50 std::string RetrieveToken(const std::string& token_name); | |
| 51 | |
| 52 std::map<std::string, TokenCacheData>::iterator FindMatch( | |
|
Andrew T Wilson (Slow)
2013/03/06 16:55:28
This seems very specific to be exposing as part of
Pete Williamson
2013/03/06 19:04:31
Removed
| |
| 53 const std::string& token_name); | |
| 54 | |
| 55 // inherited from NotificationObserver | |
| 56 virtual void Observe(int type, | |
| 57 const content::NotificationSource& source, | |
| 58 const content::NotificationDetails& details) OVERRIDE; | |
| 59 | |
| 60 private: | |
| 61 std::map<std::string, TokenCacheData> token_cache_; | |
| 62 content::NotificationRegistrar registrar_; | |
| 63 const Profile* const profile_; | |
| 64 | |
| 65 friend class TokenCacheTest; | |
| 66 | |
| 67 DISALLOW_COPY_AND_ASSIGN(TokenCacheService); | |
| 68 }; | |
| 69 | |
| 70 } // namespace extensions | |
| 71 | |
| 72 #endif // CHROME_BROWSER_EXTENSIONS_TOKEN_CACHE_TOKEN_CACHE_H_ | |
| OLD | NEW |