| 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 15 matching lines...) Expand all Loading... |
| 26 using Callback = UsbMidiDevice::Factory::Callback; | 26 using Callback = UsbMidiDevice::Factory::Callback; |
| 27 | 27 |
| 28 } // namespace | 28 } // namespace |
| 29 | 29 |
| 30 UsbMidiDeviceFactoryAndroid::UsbMidiDeviceFactoryAndroid() : delegate_(NULL) {} | 30 UsbMidiDeviceFactoryAndroid::UsbMidiDeviceFactoryAndroid() : delegate_(NULL) {} |
| 31 | 31 |
| 32 UsbMidiDeviceFactoryAndroid::~UsbMidiDeviceFactoryAndroid() { | 32 UsbMidiDeviceFactoryAndroid::~UsbMidiDeviceFactoryAndroid() { |
| 33 JNIEnv* env = base::android::AttachCurrentThread(); | 33 JNIEnv* env = base::android::AttachCurrentThread(); |
| 34 if (!raw_factory_.is_null()) | 34 if (!raw_factory_.is_null()) |
| 35 Java_UsbMidiDeviceFactoryAndroid_close( | 35 Java_UsbMidiDeviceFactoryAndroid_close( |
| 36 env, raw_factory_.obj(), base::android::GetApplicationContext()); | 36 env, raw_factory_, base::android::GetApplicationContext()); |
| 37 } | 37 } |
| 38 | 38 |
| 39 void UsbMidiDeviceFactoryAndroid::EnumerateDevices( | 39 void UsbMidiDeviceFactoryAndroid::EnumerateDevices( |
| 40 UsbMidiDeviceDelegate* delegate, | 40 UsbMidiDeviceDelegate* delegate, |
| 41 Callback callback) { | 41 Callback callback) { |
| 42 DCHECK(!delegate_); | 42 DCHECK(!delegate_); |
| 43 JNIEnv* env = base::android::AttachCurrentThread(); | 43 JNIEnv* env = base::android::AttachCurrentThread(); |
| 44 uintptr_t pointer = reinterpret_cast<uintptr_t>(this); | 44 uintptr_t pointer = reinterpret_cast<uintptr_t>(this); |
| 45 raw_factory_.Reset(Java_UsbMidiDeviceFactoryAndroid_create( | 45 raw_factory_.Reset(Java_UsbMidiDeviceFactoryAndroid_create( |
| 46 env, base::android::GetApplicationContext(), pointer)); | 46 env, base::android::GetApplicationContext(), pointer)); |
| 47 | 47 |
| 48 delegate_ = delegate; | 48 delegate_ = delegate; |
| 49 callback_ = callback; | 49 callback_ = callback; |
| 50 | 50 |
| 51 if (Java_UsbMidiDeviceFactoryAndroid_enumerateDevices( | 51 if (Java_UsbMidiDeviceFactoryAndroid_enumerateDevices( |
| 52 env, raw_factory_.obj(), base::android::GetApplicationContext())) { | 52 env, raw_factory_, base::android::GetApplicationContext())) { |
| 53 // Asynchronous operation. | 53 // Asynchronous operation. |
| 54 return; | 54 return; |
| 55 } | 55 } |
| 56 // No devices are found. | 56 // No devices are found. |
| 57 ScopedVector<UsbMidiDevice> devices; | 57 ScopedVector<UsbMidiDevice> devices; |
| 58 callback.Run(true, &devices); | 58 callback.Run(true, &devices); |
| 59 } | 59 } |
| 60 | 60 |
| 61 // Called from the Java world. | 61 // Called from the Java world. |
| 62 void UsbMidiDeviceFactoryAndroid::OnUsbMidiDeviceRequestDone( | 62 void UsbMidiDeviceFactoryAndroid::OnUsbMidiDeviceRequestDone( |
| (...skipping 27 matching lines...) Expand all Loading... |
| 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 RegisterNativesImpl(env); |
| 96 } | 96 } |
| 97 | 97 |
| 98 } // namespace midi | 98 } // namespace midi |
| 99 } // namespace media | 99 } // namespace media |
| OLD | NEW |