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 #include "content/public/browser/notification_service.h" | |
|
dcheng
2013/03/05 22:38:44
1) Forward declare content::NotificationSource.
2)
Pete Williamson
2013/03/06 00:09:40
Done.
| |
| 22 | |
| 23 class Profile; | |
| 24 | |
| 25 namespace extensions { | |
| 26 | |
| 27 struct TokenCacheData { | |
| 28 std::string token; | |
| 29 base::Time expiration_time; | |
| 30 }; | |
| 31 | |
| 32 class TokenCacheService : public ProfileKeyedService, | |
| 33 content::NotificationObserver { | |
|
dcheng
2013/03/05 22:38:44
Align inherited classes, add missing "public" keyw
Pete Williamson
2013/03/06 00:09:40
Done.
| |
| 34 | |
|
dcheng
2013/03/05 22:38:44
Extra newline?
Pete Williamson
2013/03/06 00:09:40
Done.
| |
| 35 public: | |
| 36 explicit TokenCacheService(Profile* profile); | |
| 37 virtual ~TokenCacheService(); | |
| 38 | |
| 39 // Store a token for the currently logged in user. We will look it up later by | |
| 40 // the name given here, and we will expire the token after the timeout. For a | |
| 41 // timeout of 0, we never expire the token. After time_to_live expires, the | |
| 42 // token will be expired. | |
| 43 void StoreToken(const std::string& token_name, const std::string& token_value, | |
| 44 base::TimeDelta time_to_live); | |
| 45 | |
| 46 // Retrieve a token for the currently logged in user. This returns an empty | |
| 47 // string if the token was not found or timed out. | |
| 48 std::string RetrieveToken(const std::string& token_name); | |
| 49 | |
| 50 std::map<std::string, TokenCacheData>::iterator FindMatch( | |
| 51 const std::string& token_name); | |
| 52 | |
| 53 // inherited from ProfileKeyedService | |
| 54 virtual void Shutdown() OVERRIDE; | |
| 55 | |
| 56 // inherited from NotificationObserver | |
| 57 virtual void Observe(int type, | |
| 58 const content::NotificationSource& source, | |
| 59 const content::NotificationDetails& details) OVERRIDE; | |
| 60 | |
| 61 private: | |
| 62 std::map<std::string, TokenCacheData> token_cache_; | |
| 63 content::NotificationRegistrar registrar_; | |
| 64 const Profile* const profile_; | |
| 65 | |
| 66 friend class TokenCacheTest; | |
| 67 | |
| 68 DISALLOW_COPY_AND_ASSIGN(TokenCacheService); | |
| 69 }; | |
| 70 | |
| 71 } // namespace extensions | |
| 72 | |
| 73 #endif // CHROME_BROWSER_EXTENSIONS_TOKEN_CACHE_TOKEN_CACHE_H_ | |
| OLD | NEW |