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 flush tokens out | |
|
dcheng
2013/02/28 19:18:04
"flush" is an ambiguous term, since it could mean
Pete Williamson
2013/03/04 18:32:53
Done.
| |
| 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_TOKEN_CACHE_TOKEN_CACHE_H_ | |
| 10 #define CHROME_BROWSER_TOKEN_CACHE_TOKEN_CACHE_H_ | |
| 11 | |
| 12 #include <algorithm> | |
|
dcheng
2013/02/28 19:18:04
Why is this in the header?
Pete Williamson
2013/03/04 18:32:53
This was leftover from when I tried the find-if ve
| |
| 13 #include <string> | |
| 14 #include <vector> | |
| 15 | |
| 16 #include "base/basictypes.h" | |
| 17 #include "base/compiler_specific.h" | |
| 18 #include "base/time.h" | |
| 19 #include "chrome/browser/profiles/profile_keyed_service.h" | |
| 20 #include "content/public/browser/notification_observer.h" | |
| 21 #include "content/public/browser/notification_registrar.h" | |
| 22 #include "content/public/browser/notification_service.h" | |
| 23 | |
| 24 class Profile; | |
| 25 | |
| 26 struct TokenCacheData { | |
| 27 std::string token_name; | |
| 28 std::string token; | |
| 29 base::Time expiration_time; | |
| 30 }; | |
| 31 | |
| 32 // TODO: Should I put this in a namespace? Which one? | |
| 33 | |
| 34 class TokenCacheService : public ProfileKeyedService, | |
| 35 content::NotificationObserver { | |
|
dcheng
2013/02/28 19:18:04
Indent.
Pete Williamson
2013/03/04 18:32:53
Done.
dcheng
2013/03/04 22:40:59
Sorry, I should have clarified (and I also missed
Pete Williamson
2013/03/05 19:42:25
Done.
| |
| 36 | |
| 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. The timeout is the number of | |
| 44 // milliseconds after which to expire this token. | |
| 45 void StoreToken(const std::string& token_name, const std::string& token_value, | |
| 46 const int64 expiration_timeout); | |
|
dcheng
2013/02/28 19:18:04
Use base::TimeDelta instead.
Pete Williamson
2013/03/04 18:32:53
Done.
| |
| 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::vector<TokenCacheData>::iterator FindMatch( | |
| 53 const std::string& token_name); | |
| 54 | |
| 55 // inherited from ProfileKeyedService | |
| 56 virtual void Shutdown() OVERRIDE; | |
| 57 | |
| 58 // inherited from NotificationObserver | |
| 59 virtual void Observe(int type, | |
| 60 const content::NotificationSource& source, | |
| 61 const content::NotificationDetails& details) OVERRIDE; | |
| 62 | |
| 63 private: | |
| 64 // TODO(petewil): If we start putting lots of tokens in here, use a map | |
| 65 // instead because the lookup time is O(n). | |
| 66 std::vector<TokenCacheData> token_cache_; | |
|
dcheng
2013/02/28 19:18:04
Why not just use a map since that's logically what
Pete Williamson
2013/03/04 18:32:53
My concern is efficiency. Maps generate a lot mor
dcheng
2013/03/04 22:40:59
But then you just have to reimplement the lookup l
Pete Williamson
2013/03/05 19:42:25
Done.
| |
| 67 content::NotificationRegistrar registrar_; | |
| 68 Profile* profile_; | |
|
dcheng
2013/02/28 19:18:04
Profile* const.
Pete Williamson
2013/03/04 18:32:53
changed to "const Profile* profile_;"
dcheng
2013/03/04 22:40:59
In that case, const Profile* const profile_; pleas
Pete Williamson
2013/03/05 19:42:25
Done.
| |
| 69 | |
| 70 friend class TokenCacheTest; | |
|
dcheng
2013/02/28 19:18:04
DISALLOW_COPY_AND_ASSIGN.
Pete Williamson
2013/03/04 18:32:53
Done.
| |
| 71 }; | |
| 72 | |
| 73 | |
| 74 | |
| 75 #endif // CHROME_BROWSER_TOKEN_CACHE_TOKEN_CACHE_H_ | |
| OLD | NEW |