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 #ifndef CHROME_BROWSER_EXTENSIONS_TOKEN_CACHE_TOKEN_CACHE_SERVICE_H_ | |
6 #define CHROME_BROWSER_EXTENSIONS_TOKEN_CACHE_TOKEN_CACHE_SERVICE_H_ | |
7 | |
8 #include <map> | |
9 #include <string> | |
10 | |
11 #include "base/basictypes.h" | |
12 #include "base/compiler_specific.h" | |
13 #include "base/time.h" | |
14 #include "chrome/browser/profiles/profile_keyed_service.h" | |
15 #include "content/public/browser/notification_observer.h" | |
16 #include "content/public/browser/notification_registrar.h" | |
17 | |
18 namespace content { | |
19 class NotificationSource; | |
20 } | |
21 | |
22 class Profile; | |
23 | |
24 namespace extensions { | |
25 | |
26 // This class caches tokens for the current user. It will clear tokens out | |
27 // when the user logs out or after the specified timeout interval, or when | |
28 // 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
| |
29 class TokenCacheService : public ProfileKeyedService, | |
30 public content::NotificationObserver { | |
31 public: | |
32 explicit TokenCacheService(Profile* profile); | |
33 virtual ~TokenCacheService(); | |
34 | |
35 // Store a token for the currently logged in user. We will look it up later by | |
36 // the name given here, and we will expire the token after the timeout. For a | |
37 // timeout of 0, we never expire the token. After time_to_live expires, the | |
38 // token will be expired. | |
39 void StoreToken(const std::string& token_name, const std::string& token_value, | |
40 base::TimeDelta time_to_live); | |
41 | |
42 // Retrieve a token for the currently logged in user. This returns an empty | |
43 // string if the token was not found or timed out. | |
44 std::string RetrieveToken(const std::string& token_name); | |
45 | |
46 // 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.
| |
47 virtual void Observe(int type, | |
48 const content::NotificationSource& source, | |
49 const content::NotificationDetails& details) OVERRIDE; | |
50 | |
51 private: | |
52 struct TokenCacheData { | |
53 std::string token; | |
54 base::Time expiration_time; | |
55 }; | |
56 | |
57 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.
| |
58 content::NotificationRegistrar registrar_; | |
59 const Profile* const profile_; | |
60 | |
61 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.
| |
62 | |
63 DISALLOW_COPY_AND_ASSIGN(TokenCacheService); | |
64 }; | |
65 | |
66 } // namespace extensions | |
67 | |
68 #endif // CHROME_BROWSER_EXTENSIONS_TOKEN_CACHE_TOKEN_CACHE_SERVICE_H_ | |
OLD | NEW |