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

Side by Side Diff: device/bluetooth/bluetooth_adapter_factory.cc

Issue 11411130: Implemented BluetoothTaskManagerWin class. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: changed to const char[] Created 7 years, 11 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
« no previous file with comments | « no previous file | device/bluetooth/bluetooth_adapter_win.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "device/bluetooth/bluetooth_adapter_factory.h" 5 #include "device/bluetooth/bluetooth_adapter_factory.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "device/bluetooth/bluetooth_adapter.h" 10 #include "device/bluetooth/bluetooth_adapter.h"
11 11
12 #if defined(OS_CHROMEOS) 12 #if defined(OS_CHROMEOS)
13 #include "device/bluetooth/bluetooth_adapter_chromeos.h" 13 #include "device/bluetooth/bluetooth_adapter_chromeos.h"
14 #elif defined(OS_WIN)
15 #include "device/bluetooth/bluetooth_adapter_win.h"
14 #endif 16 #endif
15 17
16 namespace { 18 namespace {
17 19
18 // Shared default adapter instance, we don't want to keep this class around 20 // Shared default adapter instance, we don't want to keep this class around
19 // if nobody is using it so use a WeakPtr and create the object when needed; 21 // if nobody is using it so use a WeakPtr and create the object when needed;
20 // since Google C++ Style (and clang's static analyzer) forbids us having 22 // since Google C++ Style (and clang's static analyzer) forbids us having
21 // exit-time destructors we use a leaky lazy instance for it. 23 // exit-time destructors we use a leaky lazy instance for it.
22 base::LazyInstance<base::WeakPtr<device::BluetoothAdapter> >::Leaky 24 base::LazyInstance<base::WeakPtr<device::BluetoothAdapter> >::Leaky
23 default_adapter = LAZY_INSTANCE_INITIALIZER; 25 default_adapter = LAZY_INSTANCE_INITIALIZER;
24 26
25 } // namespace 27 } // namespace
26 28
27 namespace device { 29 namespace device {
28 30
29 // static 31 // static
30 bool BluetoothAdapterFactory::IsBluetoothAdapterAvailable() { 32 bool BluetoothAdapterFactory::IsBluetoothAdapterAvailable() {
31 #if defined(OS_CHROMEOS) 33 #if defined(OS_CHROMEOS)
32 return true; 34 return true;
35 #elif defined(OS_WIN)
36 return true;
33 #endif 37 #endif
34 return false; 38 return false;
35 } 39 }
36 40
37 // static 41 // static
38 void BluetoothAdapterFactory::RunCallbackOnAdapterReady( 42 void BluetoothAdapterFactory::RunCallbackOnAdapterReady(
39 const AdapterCallback& callback) { 43 const AdapterCallback& callback) {
40 if (!default_adapter.Get().get()) { 44 if (!default_adapter.Get().get()) {
41 #if defined(OS_CHROMEOS) 45 #if defined(OS_CHROMEOS)
42 chromeos::BluetoothAdapterChromeOs* new_adapter = 46 chromeos::BluetoothAdapterChromeOs* new_adapter =
43 new chromeos::BluetoothAdapterChromeOs; 47 new chromeos::BluetoothAdapterChromeOs;
44 new_adapter->TrackDefaultAdapter(); 48 new_adapter->TrackDefaultAdapter();
45 default_adapter.Get() = new_adapter->weak_ptr_factory_.GetWeakPtr(); 49 default_adapter.Get() = new_adapter->weak_ptr_factory_.GetWeakPtr();
50 #elif defined(OS_WIN)
51 BluetoothAdapterWin* new_adapter = new BluetoothAdapterWin();
52 new_adapter->TrackDefaultAdapter();
53 default_adapter.Get() = new_adapter->weak_ptr_factory_.GetWeakPtr();
46 #endif 54 #endif
47 } 55 }
48 56
49 callback.Run(scoped_refptr<BluetoothAdapter>(default_adapter.Get())); 57 callback.Run(scoped_refptr<BluetoothAdapter>(default_adapter.Get()));
50 } 58 }
51 59
52 // static 60 // static
53 scoped_refptr<BluetoothAdapter> BluetoothAdapterFactory::GetAdapter() { 61 scoped_refptr<BluetoothAdapter> BluetoothAdapterFactory::GetAdapter() {
54 return scoped_refptr<BluetoothAdapter>(default_adapter.Get()); 62 return scoped_refptr<BluetoothAdapter>(default_adapter.Get());
55 } 63 }
56 64
57 // static 65 // static
58 BluetoothAdapter* BluetoothAdapterFactory::Create(const std::string& address) { 66 BluetoothAdapter* BluetoothAdapterFactory::Create(const std::string& address) {
59 BluetoothAdapter* adapter = NULL; 67 BluetoothAdapter* adapter = NULL;
60 #if defined(OS_CHROMEOS) 68 #if defined(OS_CHROMEOS)
61 chromeos::BluetoothAdapterChromeOs* adapter_chromeos = 69 chromeos::BluetoothAdapterChromeOs* adapter_chromeos =
62 new chromeos::BluetoothAdapterChromeOs; 70 new chromeos::BluetoothAdapterChromeOs;
63 adapter_chromeos->FindAdapter(address); 71 adapter_chromeos->FindAdapter(address);
64 adapter = adapter_chromeos; 72 adapter = adapter_chromeos;
73 #elif defined(OS_WIN)
74 adapter = new BluetoothAdapterWin();
65 #endif 75 #endif
66 return adapter; 76 return adapter;
67 } 77 }
68 78
69 } // namespace device 79 } // namespace device
OLDNEW
« no previous file with comments | « no previous file | device/bluetooth/bluetooth_adapter_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698