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

Side by Side 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: A 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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"
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.
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698