OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/lazy_instance.h" |
| 6 #include "base/memory/ref_counted.h" |
| 7 #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter_chromeos.h" |
| 8 #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter_factory.h" |
| 9 |
| 10 namespace { |
| 11 |
| 12 // Shared default adapter instance, we don't want to keep this class around |
| 13 // if nobody is using it so use a WeakPtr and create the object when needed; |
| 14 // since Google C++ Style (and clang's static analyzer) forbids us having |
| 15 // exit-time destructors we use a leaky lazy instance for it. |
| 16 base::LazyInstance<base::WeakPtr<chromeos::BluetoothAdapterChromeOs> >::Leaky |
| 17 default_adapter = LAZY_INSTANCE_INITIALIZER; |
| 18 |
| 19 } // namespace |
| 20 |
| 21 namespace chromeos { |
| 22 |
| 23 // static |
| 24 scoped_refptr<BluetoothAdapter> BluetoothAdapterFactory::DefaultAdapter() { |
| 25 if (!default_adapter.Get().get()) { |
| 26 BluetoothAdapterChromeOs* new_adapter = new BluetoothAdapterChromeOs; |
| 27 default_adapter.Get() = new_adapter->weak_ptr_factory_.GetWeakPtr(); |
| 28 default_adapter.Get()->TrackDefaultAdapter(); |
| 29 } |
| 30 |
| 31 return scoped_refptr<BluetoothAdapter>(default_adapter.Get()); |
| 32 } |
| 33 |
| 34 // static |
| 35 BluetoothAdapter* BluetoothAdapterFactory::Create(const std::string& address) { |
| 36 BluetoothAdapterChromeOs* adapter = new BluetoothAdapterChromeOs; |
| 37 adapter->FindAdapter(address); |
| 38 return adapter; |
| 39 } |
| 40 |
| 41 } // namespace chromeos |
OLD | NEW |