| 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" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 return BluetoothAdapterAndroid::Create( | 24 return BluetoothAdapterAndroid::Create( |
| 25 BluetoothAdapterWrapper_CreateWithDefaultAdapter().obj()); | 25 BluetoothAdapterWrapper_CreateWithDefaultAdapter().obj()); |
| 26 } | 26 } |
| 27 | 27 |
| 28 // static | 28 // static |
| 29 base::WeakPtr<BluetoothAdapterAndroid> BluetoothAdapterAndroid::Create( | 29 base::WeakPtr<BluetoothAdapterAndroid> BluetoothAdapterAndroid::Create( |
| 30 jobject java_bluetooth_adapter_wrapper) { | 30 jobject java_bluetooth_adapter_wrapper) { |
| 31 BluetoothAdapterAndroid* adapter = new BluetoothAdapterAndroid(); | 31 BluetoothAdapterAndroid* adapter = new BluetoothAdapterAndroid(); |
| 32 | 32 |
| 33 adapter->j_adapter_.Reset(Java_ChromeBluetoothAdapter_create( | 33 adapter->j_adapter_.Reset(Java_ChromeBluetoothAdapter_create( |
| 34 AttachCurrentThread(), reinterpret_cast<intptr_t>(adapter), | 34 AttachCurrentThread(), java_bluetooth_adapter_wrapper)); |
| 35 java_bluetooth_adapter_wrapper)); | |
| 36 | 35 |
| 37 return adapter->weak_ptr_factory_.GetWeakPtr(); | 36 return adapter->weak_ptr_factory_.GetWeakPtr(); |
| 38 } | 37 } |
| 39 | 38 |
| 40 // static | 39 // static |
| 41 bool BluetoothAdapterAndroid::RegisterJNI(JNIEnv* env) { | 40 bool BluetoothAdapterAndroid::RegisterJNI(JNIEnv* env) { |
| 42 return RegisterNativesImpl(env); // Generated in BluetoothAdapter_jni.h | 41 return RegisterNativesImpl(env); // Generated in BluetoothAdapter_jni.h |
| 43 } | 42 } |
| 44 | 43 |
| 45 std::string BluetoothAdapterAndroid::GetAddress() const { | 44 std::string BluetoothAdapterAndroid::GetAddress() const { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 error_callback.Run(BluetoothAudioSink::ERROR_UNSUPPORTED_PLATFORM); | 119 error_callback.Run(BluetoothAudioSink::ERROR_UNSUPPORTED_PLATFORM); |
| 121 } | 120 } |
| 122 | 121 |
| 123 void BluetoothAdapterAndroid::RegisterAdvertisement( | 122 void BluetoothAdapterAndroid::RegisterAdvertisement( |
| 124 scoped_ptr<BluetoothAdvertisement::Data> advertisement_data, | 123 scoped_ptr<BluetoothAdvertisement::Data> advertisement_data, |
| 125 const CreateAdvertisementCallback& callback, | 124 const CreateAdvertisementCallback& callback, |
| 126 const CreateAdvertisementErrorCallback& error_callback) { | 125 const CreateAdvertisementErrorCallback& error_callback) { |
| 127 error_callback.Run(BluetoothAdvertisement::ERROR_UNSUPPORTED_PLATFORM); | 126 error_callback.Run(BluetoothAdvertisement::ERROR_UNSUPPORTED_PLATFORM); |
| 128 } | 127 } |
| 129 | 128 |
| 130 void BluetoothAdapterAndroid::OnScanFailed(JNIEnv* env, jobject obj) { | |
| 131 MarkDiscoverySessionsAsInactive(); | |
| 132 } | |
| 133 | |
| 134 BluetoothAdapterAndroid::BluetoothAdapterAndroid() : weak_ptr_factory_(this) { | 129 BluetoothAdapterAndroid::BluetoothAdapterAndroid() : weak_ptr_factory_(this) { |
| 135 } | 130 } |
| 136 | 131 |
| 137 BluetoothAdapterAndroid::~BluetoothAdapterAndroid() { | 132 BluetoothAdapterAndroid::~BluetoothAdapterAndroid() { |
| 138 Java_ChromeBluetoothAdapter_onBluetoothAdapterAndroidDestruction( | |
| 139 AttachCurrentThread(), j_adapter_.obj()); | |
| 140 } | 133 } |
| 141 | 134 |
| 142 void BluetoothAdapterAndroid::AddDiscoverySession( | 135 void BluetoothAdapterAndroid::AddDiscoverySession( |
| 143 BluetoothDiscoveryFilter* discovery_filter, | 136 BluetoothDiscoveryFilter* discovery_filter, |
| 144 const base::Closure& callback, | 137 const base::Closure& callback, |
| 145 const ErrorCallback& error_callback) { | 138 const ErrorCallback& error_callback) { |
| 146 // TODO(scheib): Support filters crbug.com/490401 | 139 error_callback.Run(); |
| 147 if (Java_ChromeBluetoothAdapter_addDiscoverySession(AttachCurrentThread(), | |
| 148 j_adapter_.obj())) { | |
| 149 callback.Run(); | |
| 150 } else { | |
| 151 error_callback.Run(); | |
| 152 } | |
| 153 } | 140 } |
| 154 | 141 |
| 155 void BluetoothAdapterAndroid::RemoveDiscoverySession( | 142 void BluetoothAdapterAndroid::RemoveDiscoverySession( |
| 156 BluetoothDiscoveryFilter* discovery_filter, | 143 BluetoothDiscoveryFilter* discovery_filter, |
| 157 const base::Closure& callback, | 144 const base::Closure& callback, |
| 158 const ErrorCallback& error_callback) { | 145 const ErrorCallback& error_callback) { |
| 159 if (Java_ChromeBluetoothAdapter_removeDiscoverySession(AttachCurrentThread(), | 146 error_callback.Run(); |
| 160 j_adapter_.obj())) { | |
| 161 callback.Run(); | |
| 162 } else { | |
| 163 error_callback.Run(); | |
| 164 } | |
| 165 } | 147 } |
| 166 | 148 |
| 167 void BluetoothAdapterAndroid::SetDiscoveryFilter( | 149 void BluetoothAdapterAndroid::SetDiscoveryFilter( |
| 168 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter, | 150 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter, |
| 169 const base::Closure& callback, | 151 const base::Closure& callback, |
| 170 const ErrorCallback& error_callback) { | 152 const ErrorCallback& error_callback) { |
| 171 // TODO(scheib): Support filters crbug.com/490401 | |
| 172 NOTIMPLEMENTED(); | |
| 173 error_callback.Run(); | 153 error_callback.Run(); |
| 174 } | 154 } |
| 175 | 155 |
| 176 void BluetoothAdapterAndroid::RemovePairingDelegateInternal( | 156 void BluetoothAdapterAndroid::RemovePairingDelegateInternal( |
| 177 device::BluetoothDevice::PairingDelegate* pairing_delegate) { | 157 device::BluetoothDevice::PairingDelegate* pairing_delegate) { |
| 178 } | 158 } |
| 179 | 159 |
| 180 } // namespace device | 160 } // namespace device |
| OLD | NEW |