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

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

Issue 2722473002: DO NOT SUBMIT. Stub implementation of FakeBluetooth mojo interface (Closed)
Patch Set: Created 3 years, 9 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"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 ++iter) { 47 ++iter) {
48 iter->Run(adapter); 48 iter->Run(adapter);
49 } 49 }
50 adapter_callbacks.Get().clear(); 50 adapter_callbacks.Get().clear();
51 } 51 }
52 #endif // defined(OS_WIN) || defined(OS_LINUX) || defined(OS_CHROMEOS) 52 #endif // defined(OS_WIN) || defined(OS_LINUX) || defined(OS_CHROMEOS)
53 53
54 } // namespace 54 } // namespace
55 55
56 // static 56 // static
57 bool BluetoothAdapterFactory::availability_set_ = false;
58 bool BluetoothAdapterFactory::low_energy_available_ = false;
59
60 // static
57 bool BluetoothAdapterFactory::IsBluetoothAdapterAvailable() { 61 bool BluetoothAdapterFactory::IsBluetoothAdapterAvailable() {
58 // SetAdapterForTesting() may be used to provide a test or mock adapter 62 // SetAdapterForTesting() may be used to provide a test or mock adapter
59 // instance even on platforms that would otherwise not support it. 63 // instance even on platforms that would otherwise not support it.
60 if (default_adapter.Get()) 64 if (default_adapter.Get())
61 return true; 65 return true;
62 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) || defined(OS_WIN) || \ 66 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) || defined(OS_WIN) || \
63 defined(OS_LINUX) || defined(OS_MACOSX) 67 defined(OS_LINUX) || defined(OS_MACOSX)
64 return true; 68 return true;
65 #else 69 #else
66 return false; 70 return false;
67 #endif 71 #endif
68 } 72 }
69 73
70 // static 74 // static
71 bool BluetoothAdapterFactory::IsLowEnergyAvailable() { 75 bool BluetoothAdapterFactory::IsLowEnergyAvailable() {
72 DCHECK(IsBluetoothAdapterAvailable()); 76 DCHECK(IsBluetoothAdapterAvailable());
73 77
78 if (availability_set_) {
79 return low_energy_available_;
80 }
81
74 // SetAdapterForTesting() may be used to provide a test or mock adapter 82 // SetAdapterForTesting() may be used to provide a test or mock adapter
75 // instance even on platforms that would otherwise not support it. 83 // instance even on platforms that would otherwise not support it.
76 if (default_adapter.Get()) 84 if (default_adapter.Get())
77 return true; 85 return true;
78 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) || defined(OS_WIN) || \ 86 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) || defined(OS_WIN) || \
79 defined(OS_LINUX) 87 defined(OS_LINUX)
80 return true; 88 return true;
81 #elif defined(OS_MACOSX) 89 #elif defined(OS_MACOSX)
82 return base::mac::IsAtLeastOS10_10(); 90 return base::mac::IsAtLeastOS10_10();
83 #else 91 #else
(...skipping 30 matching lines...) Expand all
114 122
115 #if defined(OS_CHROMEOS) || defined(OS_LINUX) 123 #if defined(OS_CHROMEOS) || defined(OS_LINUX)
116 // static 124 // static
117 void BluetoothAdapterFactory::Shutdown() { 125 void BluetoothAdapterFactory::Shutdown() {
118 if (default_adapter.Get()) 126 if (default_adapter.Get())
119 default_adapter.Get().get()->Shutdown(); 127 default_adapter.Get().get()->Shutdown();
120 } 128 }
121 #endif 129 #endif
122 130
123 // static 131 // static
132 void BluetoothAdapterFactory::SetAvailability(bool available) {
133 availability_set_ = true;
134 low_energy_available_ = available;
135 }
136
137 // static
124 void BluetoothAdapterFactory::SetAdapterForTesting( 138 void BluetoothAdapterFactory::SetAdapterForTesting(
125 scoped_refptr<BluetoothAdapter> adapter) { 139 scoped_refptr<BluetoothAdapter> adapter) {
126 default_adapter.Get() = adapter->GetWeakPtrForTesting(); 140 default_adapter.Get() = adapter->GetWeakPtrForTesting();
127 } 141 }
128 142
129 // static 143 // static
130 bool BluetoothAdapterFactory::HasSharedInstanceForTesting() { 144 bool BluetoothAdapterFactory::HasSharedInstanceForTesting() {
131 return default_adapter.Get() != nullptr; 145 return default_adapter.Get() != nullptr;
132 } 146 }
133 147
134 } // namespace device 148 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_adapter_factory.h ('k') | device/bluetooth/bluetooth_adapter_factory_wrapper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698