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

Side by Side Diff: chrome/service/cloud_print/cloud_print_token_store.cc

Issue 8491043: Allow linker initialization of lazy instance (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: thakis comment, renamed LAZY_INSTANCE_INITIALIZER Created 9 years, 1 month 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 | Annotate | Revision Log
OLDNEW
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698