Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(106)

Side by Side Diff: chrome/browser/extensions/token_cache/token_cache_service.h

Issue 170383005: Move TokenCacheService away from listening for Signin notifications. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Call Shutdown() in unit test Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/extensions/token_cache/token_cache_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_EXTENSIONS_TOKEN_CACHE_TOKEN_CACHE_SERVICE_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_TOKEN_CACHE_TOKEN_CACHE_SERVICE_H_
6 #define CHROME_BROWSER_EXTENSIONS_TOKEN_CACHE_TOKEN_CACHE_SERVICE_H_ 6 #define CHROME_BROWSER_EXTENSIONS_TOKEN_CACHE_TOKEN_CACHE_SERVICE_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "chrome/browser/signin/signin_manager_base.h"
14 #include "components/browser_context_keyed_service/browser_context_keyed_service .h" 15 #include "components/browser_context_keyed_service/browser_context_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 16
22 class Profile; 17 class Profile;
23 18
24 namespace extensions { 19 namespace extensions {
25 20
26 // This class caches tokens for the current user. It will clear tokens out 21 // 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 22 // when the user logs out or after the specified timeout interval, or when
28 // the instance of chrome shuts down. 23 // the instance of chrome shuts down.
29 class TokenCacheService : public BrowserContextKeyedService, 24 class TokenCacheService : public BrowserContextKeyedService,
30 public content::NotificationObserver { 25 public SigninManagerBase::Observer {
31 public: 26 public:
32 explicit TokenCacheService(Profile* profile); 27 explicit TokenCacheService(Profile* profile);
33 virtual ~TokenCacheService(); 28 virtual ~TokenCacheService();
34 29
35 // Store a token for the currently logged in user. We will look it up later by 30 // 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 31 // 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 32 // timeout of 0, we never expire the token. After time_to_live expires, the
38 // token will be expired. 33 // token will be expired.
39 void StoreToken(const std::string& token_name, const std::string& token_value, 34 void StoreToken(const std::string& token_name, const std::string& token_value,
40 base::TimeDelta time_to_live); 35 base::TimeDelta time_to_live);
41 36
42 // Retrieve a token for the currently logged in user. This returns an empty 37 // Retrieve a token for the currently logged in user. This returns an empty
43 // string if the token was not found or timed out. 38 // string if the token was not found or timed out.
44 std::string RetrieveToken(const std::string& token_name); 39 std::string RetrieveToken(const std::string& token_name);
45 40
46 // Inherited from NotificationObserver. 41 // BrowserContextKeyedService:
47 virtual void Observe(int type, 42 virtual void Shutdown() OVERRIDE;
48 const content::NotificationSource& source,
49 const content::NotificationDetails& details) OVERRIDE;
50 43
51 private: 44 private:
52 friend class TokenCacheTest; 45 friend class TokenCacheTest;
46 FRIEND_TEST_ALL_PREFIXES(TokenCacheTest, SignoutTest);
47
48 // SigninManagerBase::Observer:
49 virtual void GoogleSignedOut(const std::string& username) OVERRIDE;
53 50
54 struct TokenCacheData { 51 struct TokenCacheData {
55 std::string token; 52 std::string token;
56 base::Time expiration_time; 53 base::Time expiration_time;
57 }; 54 };
58 55
59 // Map the token name (string) to token data. 56 // Map the token name (string) to token data.
60 std::map<std::string, TokenCacheData> token_cache_; 57 std::map<std::string, TokenCacheData> token_cache_;
61 content::NotificationRegistrar registrar_;
62 const Profile* const profile_; 58 const Profile* const profile_;
63 59
64 DISALLOW_COPY_AND_ASSIGN(TokenCacheService); 60 DISALLOW_COPY_AND_ASSIGN(TokenCacheService);
65 }; 61 };
66 62
67 } // namespace extensions 63 } // namespace extensions
68 64
69 #endif // CHROME_BROWSER_EXTENSIONS_TOKEN_CACHE_TOKEN_CACHE_SERVICE_H_ 65 #endif // CHROME_BROWSER_EXTENSIONS_TOKEN_CACHE_TOKEN_CACHE_SERVICE_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/token_cache/token_cache_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698