| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/child/bluetooth/web_bluetooth_impl.h" | 5 #include "content/child/bluetooth/web_bluetooth_impl.h" |
| 6 | 6 |
| 7 #include "content/child/bluetooth/bluetooth_dispatcher.h" |
| 8 #include "content/child/thread_safe_sender.h" |
| 9 |
| 7 namespace content { | 10 namespace content { |
| 8 | 11 |
| 9 WebBluetoothImpl::WebBluetoothImpl() | 12 WebBluetoothImpl::WebBluetoothImpl(ThreadSafeSender* thread_safe_sender) |
| 10 : m_bluetoothMockDataSet(MockData::NOT_MOCKING), | 13 : thread_safe_sender_(thread_safe_sender) { |
| 11 m_bluetoothRequestDeviceRejectType( | |
| 12 blink::WebBluetoothError::NotFoundError) { | |
| 13 } | 14 } |
| 14 | 15 |
| 16 WebBluetoothImpl::~WebBluetoothImpl() { |
| 17 } |
| 18 |
| 19 // TODO(scheib): Remove old void version after crrev.com/715613005 lands. |
| 15 void WebBluetoothImpl::requestDevice( | 20 void WebBluetoothImpl::requestDevice( |
| 16 blink::WebBluetoothRequestDeviceCallbacks* callbacks) { | 21 blink::WebCallbacks<void, blink::WebBluetoothError>* callbacks) { |
| 17 // Mock implementation of blink::WebBluetooth until a more complete | 22 GetDispatcher()->requestDevice(callbacks); |
| 18 // implementation is built out. | 23 } |
| 19 switch (m_bluetoothMockDataSet) { | 24 |
| 20 case MockData::NOT_MOCKING: { | 25 // TODO(scheib): Remove old void version after crrev.com/715613005 lands. |
| 21 blink::WebBluetoothError* error = new blink::WebBluetoothError( | 26 void WebBluetoothImpl::requestDevice( |
| 22 blink::WebBluetoothError::NotFoundError, ""); | 27 blink::WebCallbacks<blink::WebBluetoothDevice, blink::WebBluetoothError>* |
| 23 callbacks->onError(error); | 28 callbacks) { |
| 24 break; | 29 GetDispatcher()->requestDevice(callbacks); |
| 25 } | |
| 26 case MockData::REJECT: { | |
| 27 blink::WebBluetoothError* error = | |
| 28 new blink::WebBluetoothError(m_bluetoothRequestDeviceRejectType, ""); | |
| 29 callbacks->onError(error); | |
| 30 break; | |
| 31 } | |
| 32 case MockData::RESOLVE: { | |
| 33 callbacks->onSuccess(); | |
| 34 break; | |
| 35 } | |
| 36 } | |
| 37 } | 30 } |
| 38 | 31 |
| 39 void WebBluetoothImpl::SetBluetoothMockDataSetForTesting( | 32 void WebBluetoothImpl::SetBluetoothMockDataSetForTesting( |
| 40 const std::string& name) { | 33 const std::string& name) { |
| 41 if (name == "RejectRequestDevice_NotFoundError") { | 34 GetDispatcher()->SetBluetoothMockDataSetForTesting(name); |
| 42 m_bluetoothMockDataSet = MockData::REJECT; | 35 } |
| 43 m_bluetoothRequestDeviceRejectType = | 36 |
| 44 blink::WebBluetoothError::NotFoundError; | 37 BluetoothDispatcher* WebBluetoothImpl::GetDispatcher() { |
| 45 } else if (name == "RejectRequestDevice_SecurityError") { | 38 return BluetoothDispatcher::GetOrCreateThreadSpecificInstance( |
| 46 m_bluetoothMockDataSet = MockData::REJECT; | 39 thread_safe_sender_.get()); |
| 47 m_bluetoothRequestDeviceRejectType = | |
| 48 blink::WebBluetoothError::SecurityError; | |
| 49 } else if (name == "ResolveRequestDevice_Empty") { | |
| 50 m_bluetoothMockDataSet = MockData::RESOLVE; | |
| 51 } else { | |
| 52 m_bluetoothMockDataSet = MockData::NOT_MOCKING; | |
| 53 } | |
| 54 } | 40 } |
| 55 | 41 |
| 56 } // namespace content | 42 } // namespace content |
| OLD | NEW |