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

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

Issue 2808353004: bluetooth: Rename Is*Available to Is*Supported (Closed)
Patch Set: merge Created 3 years, 8 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
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 <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) 16 #if defined(OS_MACOSX)
17 #include "base/mac/mac_util.h" 17 #include "base/mac/mac_util.h"
18 #endif 18 #endif
19 #if defined(OS_WIN)
20 #include "base/win/windows_version.h"
21 #endif
19 22
20 namespace device { 23 namespace device {
21 24
22 namespace { 25 namespace {
23 26
24 // Shared default adapter instance. We don't want to keep this class around 27 // 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. 28 // 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 29 // Since Google C++ Style (and clang's static analyzer) forbids us having
27 // exit-time destructors, we use a leaky lazy instance for it. 30 // exit-time destructors, we use a leaky lazy instance for it.
28 base::LazyInstance<base::WeakPtr<BluetoothAdapter>>::Leaky default_adapter = 31 base::LazyInstance<base::WeakPtr<BluetoothAdapter>>::Leaky default_adapter =
(...skipping 18 matching lines...) Expand all
47 ++iter) { 50 ++iter) {
48 iter->Run(adapter); 51 iter->Run(adapter);
49 } 52 }
50 adapter_callbacks.Get().clear(); 53 adapter_callbacks.Get().clear();
51 } 54 }
52 #endif // defined(OS_WIN) || defined(OS_LINUX) || defined(OS_CHROMEOS) 55 #endif // defined(OS_WIN) || defined(OS_LINUX) || defined(OS_CHROMEOS)
53 56
54 } // namespace 57 } // namespace
55 58
56 // static 59 // static
57 bool BluetoothAdapterFactory::IsBluetoothAdapterAvailable() { 60 bool BluetoothAdapterFactory::IsBluetoothSupported() {
58 // SetAdapterForTesting() may be used to provide a test or mock adapter 61 // SetAdapterForTesting() may be used to provide a test or mock adapter
59 // instance even on platforms that would otherwise not support it. 62 // instance even on platforms that would otherwise not support it.
60 if (default_adapter.Get()) 63 if (default_adapter.Get())
61 return true; 64 return true;
62 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) || defined(OS_WIN) || \ 65 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) || defined(OS_WIN) || \
63 defined(OS_LINUX) || defined(OS_MACOSX) 66 defined(OS_LINUX) || defined(OS_MACOSX)
64 return true; 67 return true;
65 #else 68 #else
66 return false; 69 return false;
67 #endif 70 #endif
68 } 71 }
69 72
70 // static 73 // static
71 bool BluetoothAdapterFactory::IsLowEnergyAvailable() { 74 bool BluetoothAdapterFactory::IsLowEnergySupported() {
72 DCHECK(IsBluetoothAdapterAvailable());
73
74 // SetAdapterForTesting() may be used to provide a test or mock adapter 75 // SetAdapterForTesting() may be used to provide a test or mock adapter
75 // instance even on platforms that would otherwise not support it. 76 // instance even on platforms that would otherwise not support it.
76 if (default_adapter.Get()) 77 if (default_adapter.Get())
77 return true; 78 return true;
78 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) || defined(OS_WIN) || \ 79
79 defined(OS_LINUX) 80 #if defined(OS_ANDROID) && __ANDROID_API__ >= 23
80 return true; 81 return true;
82 #elif defined(OS_WIN)
83 return base::win::GetVersion() >= base::win::VERSION_WIN8;
scheib 2017/04/13 05:06:25 Will we get in trouble with 8 level being supporte
ortuno 2017/04/18 01:25:42 And scanning! I kept the support at 8 to reflect o
scheib 2017/04/18 03:38:41 /shrug/ I would go with 10 now. But, your call.
ortuno 2017/04/18 07:05:34 Increased to win 10 and added a note as to why we
81 #elif defined(OS_MACOSX) 84 #elif defined(OS_MACOSX)
82 return base::mac::IsAtLeastOS10_10(); 85 return base::mac::IsAtLeastOS10_10();
86 #elif defined(OS_LINUX) || defined(OS_CHROMEOS)
87 return true;
83 #else 88 #else
84 return false; 89 return false;
85 #endif // defined(OS_ANDROID) || defined(OS_CHROMEOS) || defined(OS_WIN) || 90 #endif
86 // defined(OS_LINUX)
87 } 91 }
88 92
89 // static 93 // static
90 void BluetoothAdapterFactory::GetAdapter(const AdapterCallback& callback) { 94 void BluetoothAdapterFactory::GetAdapter(const AdapterCallback& callback) {
91 DCHECK(IsBluetoothAdapterAvailable()); 95 DCHECK(IsBluetoothSupported());
92 96
93 #if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_CHROMEOS) 97 #if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_CHROMEOS)
94 if (!default_adapter.Get()) { 98 if (!default_adapter.Get()) {
95 default_adapter.Get() = 99 default_adapter.Get() =
96 BluetoothAdapter::CreateAdapter(base::Bind(&RunAdapterCallbacks)); 100 BluetoothAdapter::CreateAdapter(base::Bind(&RunAdapterCallbacks));
97 DCHECK(!default_adapter.Get()->IsInitialized()); 101 DCHECK(!default_adapter.Get()->IsInitialized());
98 } 102 }
99 103
100 if (!default_adapter.Get()->IsInitialized()) 104 if (!default_adapter.Get()->IsInitialized())
101 adapter_callbacks.Get().push_back(callback); 105 adapter_callbacks.Get().push_back(callback);
(...skipping 23 matching lines...) Expand all
125 scoped_refptr<BluetoothAdapter> adapter) { 129 scoped_refptr<BluetoothAdapter> adapter) {
126 default_adapter.Get() = adapter->GetWeakPtrForTesting(); 130 default_adapter.Get() = adapter->GetWeakPtrForTesting();
127 } 131 }
128 132
129 // static 133 // static
130 bool BluetoothAdapterFactory::HasSharedInstanceForTesting() { 134 bool BluetoothAdapterFactory::HasSharedInstanceForTesting() {
131 return default_adapter.Get() != nullptr; 135 return default_adapter.Get() != nullptr;
132 } 136 }
133 137
134 } // namespace device 138 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698