Chromium Code Reviews| Index: chrome/browser/chromeos/bluetooth/bluetooth_adapter_factory.cc |
| diff --git a/chrome/browser/chromeos/bluetooth/bluetooth_adapter_factory.cc b/chrome/browser/chromeos/bluetooth/bluetooth_adapter_factory.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1f6803a9f24fcd052c359eeda87b95858b80d7d8 |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/bluetooth/bluetooth_adapter_factory.cc |
| @@ -0,0 +1,41 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/lazy_instance.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "chrome/browser/chromeos/bluetooth/bluetooth_adapter_chromeos.h" |
|
bryeung
2012/09/18 19:18:39
All of this ChromeOS stuff should be hidden behind
youngki
2012/09/19 01:13:55
I was planning on doing it in a different CL when
bryeung
2012/09/19 13:27:16
Okay. This class looks pretty weird without that
youngki
2012/09/19 19:35:23
Added TODO at the top of the file.
|
| +#include "chrome/browser/chromeos/bluetooth/bluetooth_adapter_factory.h" |
| + |
| +namespace { |
| + |
| +// Shared default adapter instance, we don't want to keep this class around |
| +// if nobody is using it so use a WeakPtr and create the object when needed; |
| +// since Google C++ Style (and clang's static analyzer) forbids us having |
| +// exit-time destructors we use a leaky lazy instance for it. |
| +base::LazyInstance<base::WeakPtr<chromeos::BluetoothAdapterChromeOs> >::Leaky |
| + default_adapter = LAZY_INSTANCE_INITIALIZER; |
| + |
| +} // namespace |
| + |
| +namespace chromeos { |
| + |
| +// static |
| +scoped_refptr<BluetoothAdapter> BluetoothAdapterFactory::DefaultAdapter() { |
| + if (!default_adapter.Get().get()) { |
| + BluetoothAdapterChromeOs* new_adapter = new BluetoothAdapterChromeOs; |
| + default_adapter.Get() = new_adapter->weak_ptr_factory_.GetWeakPtr(); |
| + default_adapter.Get()->TrackDefaultAdapter(); |
| + } |
| + |
| + return scoped_refptr<BluetoothAdapter>(default_adapter.Get()); |
| +} |
| + |
| +// static |
| +BluetoothAdapter* BluetoothAdapterFactory::Create(const std::string& address) { |
| + BluetoothAdapterChromeOs* adapter = new BluetoothAdapterChromeOs; |
| + adapter->FindAdapter(address); |
| + return adapter; |
| +} |
| + |
| +} // namespace chromeos |