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

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

Powered by Google App Engine
This is Rietveld 408576698