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_API_TOKEN_CACHE_TOKEN_CACHE_H_ | |
| 10 #define CHROME_BROWSER_EXTENSIONS_API_TOKEN_CACHE_TOKEN_CACHE_H_ | |
| 11 | |
| 12 #include <string> | |
| 13 #include <vector> | |
| 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 #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>
| |
| 22 | |
| 23 class Profile; | |
| 24 | |
| 25 struct TokenCacheData { | |
| 26 std::string token_name; | |
| 27 std::string token; | |
| 28 base::Time expiration_time; | |
| 29 }; | |
| 30 | |
| 31 // 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.
| |
| 32 | |
| 33 class TokenCacheService : public ProfileKeyedService, | |
| 34 content::NotificationObserver { | |
| 35 | |
|
dcheng
2013/03/04 22:40:59
Extra newline.
Pete Williamson
2013/03/05 19:42:25
Done.
| |
| 36 public: | |
| 37 explicit TokenCacheService(Profile* profile); | |
| 38 virtual ~TokenCacheService(); | |
| 39 | |
| 40 // Store a token for the currently logged in user. We will look it up later by | |
| 41 // the name given here, and we will expire the token after the timeout. For a | |
| 42 // timeout of 0, we never expire the token. After time_to_live expires, the | |
| 43 // token will be expired. | |
| 44 void StoreToken(const std::string& token_name, const std::string& token_value, | |
| 45 const base::TimeDelta time_to_live); | |
|
dcheng
2013/03/04 22:40:59
No const.
Pete Williamson
2013/03/05 19:42:25
Done.
| |
| 46 | |
| 47 // Retrieve a token for the currently logged in user. This returns an empty | |
| 48 // string if the token was not found or timed out. | |
| 49 std::string RetrieveToken(const std::string& token_name); | |
| 50 | |
| 51 std::vector<TokenCacheData>::iterator FindMatch( | |
| 52 const std::string& token_name); | |
| 53 | |
| 54 // inherited from ProfileKeyedService | |
| 55 virtual void Shutdown() OVERRIDE; | |
| 56 | |
| 57 // inherited from NotificationObserver | |
| 58 virtual void Observe(int type, | |
| 59 const content::NotificationSource& source, | |
| 60 const content::NotificationDetails& details) OVERRIDE; | |
| 61 | |
| 62 private: | |
| 63 // TODO(petewil): If we start putting lots of tokens in here, use a map | |
| 64 // instead because the lookup time is O(n). | |
| 65 std::vector<TokenCacheData> token_cache_; | |
| 66 content::NotificationRegistrar registrar_; | |
| 67 const Profile* profile_; | |
| 68 | |
| 69 friend class TokenCacheTest; | |
| 70 | |
| 71 DISALLOW_COPY_AND_ASSIGN(TokenCacheService); | |
| 72 }; | |
| 73 | |
| 74 #endif // CHROME_BROWSER_EXTENSIONS_API_TOKEN_CACHE_TOKEN_CACHE_H_ | |
| OLD | NEW |