Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_android.h" | 5 #include "device/bluetooth/bluetooth_adapter_android.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
| 9 #include "base/sequenced_task_runner.h" | 9 #include "base/sequenced_task_runner.h" |
| 10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| 11 #include "base/thread_task_runner_handle.h" | 11 #include "base/thread_task_runner_handle.h" |
| 12 #include "device/bluetooth/android/wrappers.h" | 12 #include "device/bluetooth/android/wrappers.h" |
| 13 #include "device/bluetooth/bluetooth_advertisement.h" | 13 #include "device/bluetooth/bluetooth_advertisement.h" |
| 14 #include "device/bluetooth/bluetooth_device_android.h" | |
| 14 #include "jni/ChromeBluetoothAdapter_jni.h" | 15 #include "jni/ChromeBluetoothAdapter_jni.h" |
| 15 | 16 |
| 16 using base::android::AttachCurrentThread; | 17 using base::android::AttachCurrentThread; |
| 17 using base::android::ConvertJavaStringToUTF8; | 18 using base::android::ConvertJavaStringToUTF8; |
| 18 | 19 |
| 19 namespace device { | 20 namespace device { |
| 20 | 21 |
| 21 // static | 22 // static |
| 22 base::WeakPtr<BluetoothAdapter> BluetoothAdapter::CreateAdapter( | 23 base::WeakPtr<BluetoothAdapter> BluetoothAdapter::CreateAdapter( |
| 23 const InitCallback& init_callback) { | 24 const InitCallback& init_callback) { |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 scoped_ptr<BluetoothAdvertisement::Data> advertisement_data, | 125 scoped_ptr<BluetoothAdvertisement::Data> advertisement_data, |
| 125 const CreateAdvertisementCallback& callback, | 126 const CreateAdvertisementCallback& callback, |
| 126 const CreateAdvertisementErrorCallback& error_callback) { | 127 const CreateAdvertisementErrorCallback& error_callback) { |
| 127 error_callback.Run(BluetoothAdvertisement::ERROR_UNSUPPORTED_PLATFORM); | 128 error_callback.Run(BluetoothAdvertisement::ERROR_UNSUPPORTED_PLATFORM); |
| 128 } | 129 } |
| 129 | 130 |
| 130 void BluetoothAdapterAndroid::OnScanFailed(JNIEnv* env, jobject obj) { | 131 void BluetoothAdapterAndroid::OnScanFailed(JNIEnv* env, jobject obj) { |
| 131 MarkDiscoverySessionsAsInactive(); | 132 MarkDiscoverySessionsAsInactive(); |
| 132 } | 133 } |
| 133 | 134 |
| 135 void BluetoothAdapterAndroid::CreateOrUpdateDeviceOnScan( | |
| 136 JNIEnv* env, | |
| 137 jobject obj, | |
|
Jeffrey Yasskin
2015/07/07 00:11:14
|obj| isn't used? Wildly guessing at why it's ther
scheib
2015/07/08 00:49:10
:( Yes, this seems unfortunate that JNI presumes t
| |
| 138 const jstring& jaddress, | |
| 139 jobject bluetooth_device_wrapper, | |
| 140 jobject advertised_uuids) { | |
| 141 BluetoothDevice*& device = devices_[ConvertJavaStringToUTF8(env, jaddress)]; | |
| 142 if (!device) { | |
| 143 device = BluetoothDeviceAndroid::Create(bluetooth_device_wrapper); | |
| 144 static_cast<BluetoothDeviceAndroid*>(device) | |
| 145 ->UpdateAdvertisedUUIDs(advertised_uuids); | |
| 146 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | |
| 147 DeviceAdded(this, device)); | |
| 148 } else { | |
| 149 if (static_cast<BluetoothDeviceAndroid*>(device) | |
| 150 ->UpdateAdvertisedUUIDs(advertised_uuids)) { | |
| 151 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | |
| 152 DeviceChanged(this, device)); | |
| 153 } | |
| 154 } | |
| 155 } | |
| 156 | |
| 134 BluetoothAdapterAndroid::BluetoothAdapterAndroid() : weak_ptr_factory_(this) { | 157 BluetoothAdapterAndroid::BluetoothAdapterAndroid() : weak_ptr_factory_(this) { |
| 135 } | 158 } |
| 136 | 159 |
| 137 BluetoothAdapterAndroid::~BluetoothAdapterAndroid() { | 160 BluetoothAdapterAndroid::~BluetoothAdapterAndroid() { |
| 138 Java_ChromeBluetoothAdapter_onBluetoothAdapterAndroidDestruction( | 161 Java_ChromeBluetoothAdapter_onBluetoothAdapterAndroidDestruction( |
| 139 AttachCurrentThread(), j_adapter_.obj()); | 162 AttachCurrentThread(), j_adapter_.obj()); |
| 140 } | 163 } |
| 141 | 164 |
| 142 void BluetoothAdapterAndroid::AddDiscoverySession( | 165 void BluetoothAdapterAndroid::AddDiscoverySession( |
| 143 BluetoothDiscoveryFilter* discovery_filter, | 166 BluetoothDiscoveryFilter* discovery_filter, |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 171 // TODO(scheib): Support filters crbug.com/490401 | 194 // TODO(scheib): Support filters crbug.com/490401 |
| 172 NOTIMPLEMENTED(); | 195 NOTIMPLEMENTED(); |
| 173 error_callback.Run(); | 196 error_callback.Run(); |
| 174 } | 197 } |
| 175 | 198 |
| 176 void BluetoothAdapterAndroid::RemovePairingDelegateInternal( | 199 void BluetoothAdapterAndroid::RemovePairingDelegateInternal( |
| 177 device::BluetoothDevice::PairingDelegate* pairing_delegate) { | 200 device::BluetoothDevice::PairingDelegate* pairing_delegate) { |
| 178 } | 201 } |
| 179 | 202 |
| 180 } // namespace device | 203 } // namespace device |
| OLD | NEW |