| 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 <jni.h> | 7 #include <jni.h> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/android/scoped_java_ref.h" | 10 #include "base/android/scoped_java_ref.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 typedef UsbMidiDevice::Factory::Callback Callback; | 24 typedef UsbMidiDevice::Factory::Callback Callback; |
| 25 | 25 |
| 26 } // namespace | 26 } // namespace |
| 27 | 27 |
| 28 UsbMidiDeviceFactoryAndroid::UsbMidiDeviceFactoryAndroid() : delegate_(NULL) {} | 28 UsbMidiDeviceFactoryAndroid::UsbMidiDeviceFactoryAndroid() : delegate_(NULL) {} |
| 29 | 29 |
| 30 UsbMidiDeviceFactoryAndroid::~UsbMidiDeviceFactoryAndroid() { | 30 UsbMidiDeviceFactoryAndroid::~UsbMidiDeviceFactoryAndroid() { |
| 31 JNIEnv* env = base::android::AttachCurrentThread(); | 31 JNIEnv* env = base::android::AttachCurrentThread(); |
| 32 if (!raw_factory_.is_null()) | 32 if (!raw_factory_.is_null()) |
| 33 Java_UsbMidiDeviceFactoryAndroid_close( | 33 midi::Java_UsbMidiDeviceFactoryAndroid_close( |
| 34 env, raw_factory_.obj(), base::android::GetApplicationContext()); | 34 env, raw_factory_.obj(), base::android::GetApplicationContext()); |
| 35 } | 35 } |
| 36 | 36 |
| 37 void UsbMidiDeviceFactoryAndroid::EnumerateDevices( | 37 void UsbMidiDeviceFactoryAndroid::EnumerateDevices( |
| 38 UsbMidiDeviceDelegate* delegate, | 38 UsbMidiDeviceDelegate* delegate, |
| 39 Callback callback) { | 39 Callback callback) { |
| 40 DCHECK(!delegate_); | 40 DCHECK(!delegate_); |
| 41 JNIEnv* env = base::android::AttachCurrentThread(); | 41 JNIEnv* env = base::android::AttachCurrentThread(); |
| 42 uintptr_t pointer = reinterpret_cast<uintptr_t>(this); | 42 uintptr_t pointer = reinterpret_cast<uintptr_t>(this); |
| 43 raw_factory_.Reset(Java_UsbMidiDeviceFactoryAndroid_create( | 43 raw_factory_.Reset(midi::Java_UsbMidiDeviceFactoryAndroid_create( |
| 44 env, base::android::GetApplicationContext(), pointer)); | 44 env, base::android::GetApplicationContext(), pointer)); |
| 45 | 45 |
| 46 delegate_ = delegate; | 46 delegate_ = delegate; |
| 47 callback_ = callback; | 47 callback_ = callback; |
| 48 | 48 |
| 49 if (Java_UsbMidiDeviceFactoryAndroid_enumerateDevices( | 49 if (midi::Java_UsbMidiDeviceFactoryAndroid_enumerateDevices( |
| 50 env, raw_factory_.obj(), base::android::GetApplicationContext())) { | 50 env, raw_factory_.obj(), 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 ScopedVector<UsbMidiDevice> 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. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 85 | 85 |
| 86 // Called from the Java world. | 86 // Called from the Java world. |
| 87 void UsbMidiDeviceFactoryAndroid::OnUsbMidiDeviceDetached( | 87 void UsbMidiDeviceFactoryAndroid::OnUsbMidiDeviceDetached( |
| 88 JNIEnv* env, | 88 JNIEnv* env, |
| 89 jobject caller, | 89 jobject caller, |
| 90 jint index) { | 90 jint index) { |
| 91 delegate_->OnDeviceDetached(index); | 91 delegate_->OnDeviceDetached(index); |
| 92 } | 92 } |
| 93 | 93 |
| 94 bool UsbMidiDeviceFactoryAndroid::RegisterUsbMidiDeviceFactory(JNIEnv* env) { | 94 bool UsbMidiDeviceFactoryAndroid::RegisterUsbMidiDeviceFactory(JNIEnv* env) { |
| 95 return RegisterNativesImpl(env); | 95 return midi::RegisterNativesImpl(env); |
| 96 } | 96 } |
| 97 | 97 |
| 98 } // namespace media | 98 } // namespace media |
| OLD | NEW |