OLD | NEW |
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 <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
14 #include "device/bluetooth/bluetooth_adapter.h" | 14 #include "device/bluetooth/bluetooth_adapter.h" |
15 | 15 |
16 #if defined(OS_MACOSX) | |
17 #include "base/mac/mac_util.h" | |
18 #endif | |
19 | |
20 namespace device { | 16 namespace device { |
21 | 17 |
22 namespace { | 18 namespace { |
23 | 19 |
24 // 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 |
25 // 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. |
26 // 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 |
27 // exit-time destructors, we use a leaky lazy instance for it. | 23 // exit-time destructors, we use a leaky lazy instance for it. |
28 base::LazyInstance<base::WeakPtr<BluetoothAdapter> >::Leaky default_adapter = | 24 base::LazyInstance<base::WeakPtr<BluetoothAdapter> >::Leaky default_adapter = |
29 LAZY_INSTANCE_INITIALIZER; | 25 LAZY_INSTANCE_INITIALIZER; |
(...skipping 23 matching lines...) Expand all Loading... |
53 | 49 |
54 } // namespace | 50 } // namespace |
55 | 51 |
56 // static | 52 // static |
57 bool BluetoothAdapterFactory::IsBluetoothAdapterAvailable() { | 53 bool BluetoothAdapterFactory::IsBluetoothAdapterAvailable() { |
58 // SetAdapterForTesting() may be used to provide a test or mock adapter | 54 // SetAdapterForTesting() may be used to provide a test or mock adapter |
59 // instance even on platforms that would otherwise not support it. | 55 // instance even on platforms that would otherwise not support it. |
60 if (default_adapter.Get()) | 56 if (default_adapter.Get()) |
61 return true; | 57 return true; |
62 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) || defined(OS_WIN) || \ | 58 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) || defined(OS_WIN) || \ |
63 defined(OS_LINUX) | 59 defined(OS_LINUX) || defined(OS_MACOSX) |
64 return true; | 60 return true; |
65 #elif defined(OS_MACOSX) | |
66 return base::mac::IsOSLionOrLater(); | |
67 #else | 61 #else |
68 return false; | 62 return false; |
69 #endif | 63 #endif |
70 } | 64 } |
71 | 65 |
72 // static | 66 // static |
73 void BluetoothAdapterFactory::GetAdapter(const AdapterCallback& callback) { | 67 void BluetoothAdapterFactory::GetAdapter(const AdapterCallback& callback) { |
74 DCHECK(IsBluetoothAdapterAvailable()); | 68 DCHECK(IsBluetoothAdapterAvailable()); |
75 | 69 |
76 #if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_CHROMEOS) | 70 #if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_CHROMEOS) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 scoped_refptr<BluetoothAdapter> adapter) { | 102 scoped_refptr<BluetoothAdapter> adapter) { |
109 default_adapter.Get() = adapter->GetWeakPtrForTesting(); | 103 default_adapter.Get() = adapter->GetWeakPtrForTesting(); |
110 } | 104 } |
111 | 105 |
112 // static | 106 // static |
113 bool BluetoothAdapterFactory::HasSharedInstanceForTesting() { | 107 bool BluetoothAdapterFactory::HasSharedInstanceForTesting() { |
114 return default_adapter.Get(); | 108 return default_adapter.Get(); |
115 } | 109 } |
116 | 110 |
117 } // namespace device | 111 } // namespace device |
OLD | NEW |