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 { | 10 namespace cloud_print { |
11 | 11 |
12 // 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 |
13 // incorrectly from the wrong thread. | 13 // incorrectly from the wrong thread. |
14 static base::LazyInstance<base::ThreadLocalPointer<CloudPrintTokenStore> > | 14 static base::LazyInstance< |
15 lazy_tls = LAZY_INSTANCE_INITIALIZER; | 15 base::ThreadLocalPointer<CloudPrintTokenStore>>::DestructorAtExit lazy_tls = |
| 16 LAZY_INSTANCE_INITIALIZER; |
16 | 17 |
17 CloudPrintTokenStore* CloudPrintTokenStore::current() { | 18 CloudPrintTokenStore* CloudPrintTokenStore::current() { |
18 return lazy_tls.Pointer()->Get(); | 19 return lazy_tls.Pointer()->Get(); |
19 } | 20 } |
20 | 21 |
21 CloudPrintTokenStore::CloudPrintTokenStore() { | 22 CloudPrintTokenStore::CloudPrintTokenStore() { |
22 lazy_tls.Pointer()->Set(this); | 23 lazy_tls.Pointer()->Set(this); |
23 } | 24 } |
24 | 25 |
25 CloudPrintTokenStore::~CloudPrintTokenStore() { | 26 CloudPrintTokenStore::~CloudPrintTokenStore() { |
26 lazy_tls.Pointer()->Set(NULL); | 27 lazy_tls.Pointer()->Set(NULL); |
27 } | 28 } |
28 | 29 |
29 void CloudPrintTokenStore::SetToken(const std::string& token) { | 30 void CloudPrintTokenStore::SetToken(const std::string& token) { |
30 DCHECK(CalledOnValidThread()); | 31 DCHECK(CalledOnValidThread()); |
31 token_ = token; | 32 token_ = token; |
32 } | 33 } |
33 | 34 |
34 } // namespace cloud_print | 35 } // namespace cloud_print |
OLD | NEW |