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

Side by Side Diff: device/bluetooth/bluetooth_adapter_factory.cc

Issue 2733283002: Require explicit selection of traits for LazyInstance (Closed)
Patch Set: l10n again Created 3 years, 9 months 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
« no previous file with comments | « crypto/nss_util.cc ('k') | device/bluetooth/bluetooth_adapter_factory_wrapper.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "device/bluetooth/bluetooth_adapter_factory.h" 5 #include "device/bluetooth/bluetooth_adapter_factory.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "build/build_config.h" 13 #include "build/build_config.h"
14 #include "device/bluetooth/bluetooth_adapter.h" 14 #include "device/bluetooth/bluetooth_adapter.h"
15 15
16 #if defined(OS_MACOSX) 16 #if defined(OS_MACOSX)
17 #include "base/mac/mac_util.h" 17 #include "base/mac/mac_util.h"
18 #endif 18 #endif
19 19
20 namespace device { 20 namespace device {
21 21
22 namespace { 22 namespace {
23 23
24 // Shared default adapter instance. We don't want to keep this class around 24 // Shared default adapter instance. We don't want to keep this class around
25 // if nobody is using it, so use a WeakPtr and create the object when needed. 25 // if nobody is using it, so use a WeakPtr and create the object when needed.
26 // Since Google C++ Style (and clang's static analyzer) forbids us having 26 // Since Google C++ Style (and clang's static analyzer) forbids us having
27 // exit-time destructors, we use a leaky lazy instance for it. 27 // exit-time destructors, we use a leaky lazy instance for it.
28 base::LazyInstance<base::WeakPtr<BluetoothAdapter> >::Leaky default_adapter = 28 base::LazyInstance<base::WeakPtr<BluetoothAdapter>>::Leaky default_adapter =
29 LAZY_INSTANCE_INITIALIZER; 29 LAZY_INSTANCE_INITIALIZER;
30 30
31 #if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_CHROMEOS) 31 #if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_CHROMEOS)
32 typedef std::vector<BluetoothAdapterFactory::AdapterCallback> 32 typedef std::vector<BluetoothAdapterFactory::AdapterCallback>
33 AdapterCallbackList; 33 AdapterCallbackList;
34 34
35 // List of adapter callbacks to be called once the adapter is initialized. 35 // List of adapter callbacks to be called once the adapter is initialized.
36 // Since Google C++ Style (and clang's static analyzer) forbids us having 36 // Since Google C++ Style (and clang's static analyzer) forbids us having
37 // exit-time destructors we use a lazy instance for it. 37 // exit-time destructors we use a lazy instance for it.
38 base::LazyInstance<AdapterCallbackList> adapter_callbacks = 38 base::LazyInstance<AdapterCallbackList>::DestructorAtExit adapter_callbacks =
39 LAZY_INSTANCE_INITIALIZER; 39 LAZY_INSTANCE_INITIALIZER;
40 40
41 void RunAdapterCallbacks() { 41 void RunAdapterCallbacks() {
42 DCHECK(default_adapter.Get()); 42 DCHECK(default_adapter.Get());
43 scoped_refptr<BluetoothAdapter> adapter(default_adapter.Get().get()); 43 scoped_refptr<BluetoothAdapter> adapter(default_adapter.Get().get());
44 for (std::vector<BluetoothAdapterFactory::AdapterCallback>::const_iterator 44 for (std::vector<BluetoothAdapterFactory::AdapterCallback>::const_iterator
45 iter = adapter_callbacks.Get().begin(); 45 iter = adapter_callbacks.Get().begin();
46 iter != adapter_callbacks.Get().end(); 46 iter != adapter_callbacks.Get().end();
47 ++iter) { 47 ++iter) {
48 iter->Run(adapter); 48 iter->Run(adapter);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 scoped_refptr<BluetoothAdapter> adapter) { 125 scoped_refptr<BluetoothAdapter> adapter) {
126 default_adapter.Get() = adapter->GetWeakPtrForTesting(); 126 default_adapter.Get() = adapter->GetWeakPtrForTesting();
127 } 127 }
128 128
129 // static 129 // static
130 bool BluetoothAdapterFactory::HasSharedInstanceForTesting() { 130 bool BluetoothAdapterFactory::HasSharedInstanceForTesting() {
131 return default_adapter.Get() != nullptr; 131 return default_adapter.Get() != nullptr;
132 } 132 }
133 133
134 } // namespace device 134 } // namespace device
OLDNEW
« no previous file with comments | « crypto/nss_util.cc ('k') | device/bluetooth/bluetooth_adapter_factory_wrapper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698