| 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 "media/midi/usb_midi_device_factory_android.h" | 5 #include "media/midi/usb_midi_device_factory_android.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/android/context_utils.h" | 9 #include "base/android/context_utils.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 | 45 |
| 46 delegate_ = delegate; | 46 delegate_ = delegate; |
| 47 callback_ = callback; | 47 callback_ = callback; |
| 48 | 48 |
| 49 if (Java_UsbMidiDeviceFactoryAndroid_enumerateDevices( | 49 if (Java_UsbMidiDeviceFactoryAndroid_enumerateDevices( |
| 50 env, raw_factory_, base::android::GetApplicationContext())) { | 50 env, raw_factory_, base::android::GetApplicationContext())) { |
| 51 // Asynchronous operation. | 51 // Asynchronous operation. |
| 52 return; | 52 return; |
| 53 } | 53 } |
| 54 // No devices are found. | 54 // No devices are found. |
| 55 ScopedVector<UsbMidiDevice> devices; | 55 UsbMidiDevice::Devices devices; |
| 56 callback.Run(true, &devices); | 56 callback.Run(true, &devices); |
| 57 } | 57 } |
| 58 | 58 |
| 59 // Called from the Java world. | 59 // Called from the Java world. |
| 60 void UsbMidiDeviceFactoryAndroid::OnUsbMidiDeviceRequestDone( | 60 void UsbMidiDeviceFactoryAndroid::OnUsbMidiDeviceRequestDone( |
| 61 JNIEnv* env, | 61 JNIEnv* env, |
| 62 const JavaParamRef<jobject>& caller, | 62 const JavaParamRef<jobject>& caller, |
| 63 const JavaParamRef<jobjectArray>& devices) { | 63 const JavaParamRef<jobjectArray>& devices) { |
| 64 size_t size = env->GetArrayLength(devices); | 64 size_t size = env->GetArrayLength(devices); |
| 65 ScopedVector<UsbMidiDevice> devices_to_pass; | 65 UsbMidiDevice::Devices devices_to_pass; |
| 66 for (size_t i = 0; i < size; ++i) { | 66 for (size_t i = 0; i < size; ++i) { |
| 67 base::android::ScopedJavaLocalRef<jobject> raw_device( | 67 base::android::ScopedJavaLocalRef<jobject> raw_device( |
| 68 env, env->GetObjectArrayElement(devices, i)); | 68 env, env->GetObjectArrayElement(devices, i)); |
| 69 devices_to_pass.push_back(new UsbMidiDeviceAndroid(raw_device, delegate_)); | 69 devices_to_pass.push_back( |
| 70 base::MakeUnique<UsbMidiDeviceAndroid>(raw_device, delegate_)); |
| 70 } | 71 } |
| 71 | 72 |
| 72 callback_.Run(true, &devices_to_pass); | 73 callback_.Run(true, &devices_to_pass); |
| 73 } | 74 } |
| 74 | 75 |
| 75 // Called from the Java world. | 76 // Called from the Java world. |
| 76 void UsbMidiDeviceFactoryAndroid::OnUsbMidiDeviceAttached( | 77 void UsbMidiDeviceFactoryAndroid::OnUsbMidiDeviceAttached( |
| 77 JNIEnv* env, | 78 JNIEnv* env, |
| 78 const JavaParamRef<jobject>& caller, | 79 const JavaParamRef<jobject>& caller, |
| 79 const JavaParamRef<jobject>& device) { | 80 const JavaParamRef<jobject>& device) { |
| 80 delegate_->OnDeviceAttached( | 81 delegate_->OnDeviceAttached( |
| 81 base::MakeUnique<UsbMidiDeviceAndroid>(device, delegate_)); | 82 base::MakeUnique<UsbMidiDeviceAndroid>(device, delegate_)); |
| 82 } | 83 } |
| 83 | 84 |
| 84 // Called from the Java world. | 85 // Called from the Java world. |
| 85 void UsbMidiDeviceFactoryAndroid::OnUsbMidiDeviceDetached( | 86 void UsbMidiDeviceFactoryAndroid::OnUsbMidiDeviceDetached( |
| 86 JNIEnv* env, | 87 JNIEnv* env, |
| 87 const JavaParamRef<jobject>& caller, | 88 const JavaParamRef<jobject>& caller, |
| 88 jint index) { | 89 jint index) { |
| 89 delegate_->OnDeviceDetached(index); | 90 delegate_->OnDeviceDetached(index); |
| 90 } | 91 } |
| 91 | 92 |
| 92 bool UsbMidiDeviceFactoryAndroid::RegisterUsbMidiDeviceFactory(JNIEnv* env) { | 93 bool UsbMidiDeviceFactoryAndroid::RegisterUsbMidiDeviceFactory(JNIEnv* env) { |
| 93 return RegisterNativesImpl(env); | 94 return RegisterNativesImpl(env); |
| 94 } | 95 } |
| 95 | 96 |
| 96 } // namespace midi | 97 } // namespace midi |
| OLD | NEW |