blob: c6279a131b7438905bc01248d1894c540cf87a44 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_EXTENSIONS_TOKEN_CACHE_TOKEN_CACHE_SERVICE_H_
#define CHROME_BROWSER_EXTENSIONS_TOKEN_CACHE_TOKEN_CACHE_SERVICE_H_
#include <map>
#include <string>
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/time/time.h"
#include "components/keyed_service/core/keyed_service.h"
#include "components/signin/core/browser/signin_manager_base.h"
class Profile;
namespace extensions {
// This class caches tokens for the current user. It will clear tokens out
// when the user logs out or after the specified timeout interval, or when
// the instance of chrome shuts down.
class TokenCacheService : public KeyedService,
public SigninManagerBase::Observer {
public:
explicit TokenCacheService(Profile* profile);
virtual ~TokenCacheService();
// Store a token for the currently logged in user. We will look it up later by
// the name given here, and we will expire the token after the timeout. For a
// timeout of 0, we never expire the token. After time_to_live expires, the
// token will be expired.
void StoreToken(const std::string& token_name, const std::string& token_value,
base::TimeDelta time_to_live);
// Retrieve a token for the currently logged in user. This returns an empty
// string if the token was not found or timed out.
std::string RetrieveToken(const std::string& token_name);
// KeyedService:
virtual void Shutdown() OVERRIDE;
private:
friend class TokenCacheTest;
FRIEND_TEST_ALL_PREFIXES(TokenCacheTest, SignoutTest);
// SigninManagerBase::Observer:
virtual void GoogleSignedOut(const std::string& username) OVERRIDE;
struct TokenCacheData {
std::string token;
base::Time expiration_time;
};
// Map the token name (string) to token data.
std::map<std::string, TokenCacheData> token_cache_;
const Profile* const profile_;
DISALLOW_COPY_AND_ASSIGN(TokenCacheService);
};
} // namespace extensions
#endif // CHROME_BROWSER_EXTENSIONS_TOKEN_CACHE_TOKEN_CACHE_SERVICE_H_
|