OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "chrome/service/cloud_print/cloud_print_token_store.h" | 5 #include "chrome/service/cloud_print/cloud_print_token_store.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/threading/thread_local.h" | 8 #include "base/threading/thread_local.h" |
9 | 9 |
| 10 namespace cloud_print { |
| 11 |
10 // Keep the global CloudPrintTokenStore in a TLS slot so it is impossible to | 12 // Keep the global CloudPrintTokenStore in a TLS slot so it is impossible to |
11 // incorrectly from the wrong thread. | 13 // incorrectly from the wrong thread. |
12 static base::LazyInstance<base::ThreadLocalPointer<CloudPrintTokenStore> > | 14 static base::LazyInstance<base::ThreadLocalPointer<CloudPrintTokenStore> > |
13 lazy_tls = LAZY_INSTANCE_INITIALIZER; | 15 lazy_tls = LAZY_INSTANCE_INITIALIZER; |
14 | 16 |
15 CloudPrintTokenStore* CloudPrintTokenStore::current() { | 17 CloudPrintTokenStore* CloudPrintTokenStore::current() { |
16 return lazy_tls.Pointer()->Get(); | 18 return lazy_tls.Pointer()->Get(); |
17 } | 19 } |
18 | 20 |
19 CloudPrintTokenStore::CloudPrintTokenStore() { | 21 CloudPrintTokenStore::CloudPrintTokenStore() { |
20 lazy_tls.Pointer()->Set(this); | 22 lazy_tls.Pointer()->Set(this); |
21 } | 23 } |
22 | 24 |
23 CloudPrintTokenStore::~CloudPrintTokenStore() { | 25 CloudPrintTokenStore::~CloudPrintTokenStore() { |
24 lazy_tls.Pointer()->Set(NULL); | 26 lazy_tls.Pointer()->Set(NULL); |
25 } | 27 } |
26 | 28 |
27 void CloudPrintTokenStore::SetToken(const std::string& token) { | 29 void CloudPrintTokenStore::SetToken(const std::string& token) { |
28 DCHECK(CalledOnValidThread()); | 30 DCHECK(CalledOnValidThread()); |
29 token_ = token; | 31 token_ = token; |
30 } | 32 } |
| 33 |
| 34 } // namespace cloud_print |
OLD | NEW |