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

Unified Diff: chrome/browser/chromeos/bluetooth/bluetooth_adapter_factory.cc

Issue 10899037: Refactoring bluetooth API code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: E Created 8 years, 3 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 side-by-side diff with in-line comments
Download patch
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..f1ccb5d451b580600806f987cdf6243649ca447c
--- /dev/null
+++ b/chrome/browser/chromeos/bluetooth/bluetooth_adapter_factory.cc
@@ -0,0 +1,44 @@
+// 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.
+//
+// TODO(youngki): Guard the ChromeOS specific part with "#ifdef CHROME_OS" block
+// once we move this code into common directory.
+
+#include "base/lazy_instance.h"
+#include "base/memory/ref_counted.h"
+#include "chrome/browser/chromeos/bluetooth/bluetooth_adapter_chromeos.h"
+#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;
keybuk 2012/09/21 19:16:59 This seems weirdly platform-specific when it shoul
youngki 2012/09/22 02:03:29 I was going to change it in the other CL, but I de
+
+} // 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();
keybuk 2012/09/21 19:16:59 Is this using chromeos::BluetoothAdapter::weak_ptr
youngki 2012/09/22 02:03:29 TrackDefaultAdapter() is right now BluetoothAdapte
+ }
+
+ return scoped_refptr<BluetoothAdapter>(default_adapter.Get());
+}
+
+// static
+BluetoothAdapter* BluetoothAdapterFactory::Create(const std::string& address) {
+ BluetoothAdapterChromeOs* adapter = new BluetoothAdapterChromeOs;
keybuk 2012/09/21 19:16:59 This is the only ChromeOs-specific line in this me
youngki 2012/09/22 02:03:29 I will guard it with #ifdef CHROME_OS in the next
+ adapter->FindAdapter(address);
+ return adapter;
+}
+
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698