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 // Keep the global CloudPrintTokenStore in a TLS slot so it is impossible to | 10 // Keep the global CloudPrintTokenStore in a TLS slot so it is impossible to |
11 // incorrectly from the wrong thread. | 11 // incorrectly from the wrong thread. |
12 static base::LazyInstance<base::ThreadLocalPointer<CloudPrintTokenStore> > | 12 static base::LazyInstance<base::ThreadLocalPointer<CloudPrintTokenStore> > |
13 lazy_tls(base::LINKER_INITIALIZED); | 13 lazy_tls = LAZY_INSTANCE_INITIALIZER; |
14 | 14 |
15 CloudPrintTokenStore* CloudPrintTokenStore::current() { | 15 CloudPrintTokenStore* CloudPrintTokenStore::current() { |
16 return lazy_tls.Pointer()->Get(); | 16 return lazy_tls.Pointer()->Get(); |
17 } | 17 } |
18 | 18 |
19 CloudPrintTokenStore::CloudPrintTokenStore() { | 19 CloudPrintTokenStore::CloudPrintTokenStore() { |
20 lazy_tls.Pointer()->Set(this); | 20 lazy_tls.Pointer()->Set(this); |
21 } | 21 } |
22 | 22 |
23 CloudPrintTokenStore::~CloudPrintTokenStore() { | 23 CloudPrintTokenStore::~CloudPrintTokenStore() { |
24 lazy_tls.Pointer()->Set(NULL); | 24 lazy_tls.Pointer()->Set(NULL); |
25 } | 25 } |
26 | 26 |
27 void CloudPrintTokenStore::SetToken(const std::string& token) { | 27 void CloudPrintTokenStore::SetToken(const std::string& token) { |
28 DCHECK(CalledOnValidThread()); | 28 DCHECK(CalledOnValidThread()); |
29 token_ = token; | 29 token_ = token; |
30 } | 30 } |
OLD | NEW |