Don't send a SHChangeNotify for creating an app icon when creating a shortcut.
[chromium-blink-merge.git] / media / midi / usb_midi_device_factory_android.cc
blob6302572f9332a2050b440c9b59447589a67dfd67
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
3 // found in the LICENSE file.
5 #include "media/midi/usb_midi_device_factory_android.h"
7 #include <jni.h>
8 #include <vector>
10 #include "base/android/scoped_java_ref.h"
11 #include "base/bind.h"
12 #include "base/containers/hash_tables.h"
13 #include "base/lazy_instance.h"
14 #include "base/memory/scoped_vector.h"
15 #include "base/message_loop/message_loop.h"
16 #include "base/synchronization/lock.h"
17 #include "jni/UsbMidiDeviceFactoryAndroid_jni.h"
18 #include "media/midi/usb_midi_device_android.h"
20 namespace media {
22 namespace {
24 typedef UsbMidiDevice::Factory::Callback Callback;
26 } // namespace
28 UsbMidiDeviceFactoryAndroid::UsbMidiDeviceFactoryAndroid() : delegate_(NULL) {}
30 UsbMidiDeviceFactoryAndroid::~UsbMidiDeviceFactoryAndroid() {
31 JNIEnv* env = base::android::AttachCurrentThread();
32 if (!raw_factory_.is_null())
33 Java_UsbMidiDeviceFactoryAndroid_close(
34 env, raw_factory_.obj(), base::android::GetApplicationContext());
37 void UsbMidiDeviceFactoryAndroid::EnumerateDevices(
38 UsbMidiDeviceDelegate* delegate,
39 Callback callback) {
40 DCHECK(!delegate_);
41 JNIEnv* env = base::android::AttachCurrentThread();
42 uintptr_t pointer = reinterpret_cast<uintptr_t>(this);
43 raw_factory_.Reset(Java_UsbMidiDeviceFactoryAndroid_create(
44 env, base::android::GetApplicationContext(), pointer));
46 delegate_ = delegate;
47 callback_ = callback;
49 if (Java_UsbMidiDeviceFactoryAndroid_enumerateDevices(
50 env, raw_factory_.obj(), base::android::GetApplicationContext())) {
51 // Asynchronous operation.
52 return;
54 // No devices are found.
55 ScopedVector<UsbMidiDevice> devices;
56 callback.Run(true, &devices);
59 // Called from the Java world.
60 void UsbMidiDeviceFactoryAndroid::OnUsbMidiDeviceRequestDone(
61 JNIEnv* env,
62 jobject caller,
63 jobjectArray devices) {
64 size_t size = env->GetArrayLength(devices);
65 ScopedVector<UsbMidiDevice> devices_to_pass;
66 for (size_t i = 0; i < size; ++i) {
67 UsbMidiDeviceAndroid::ObjectRef raw_device(
68 env, env->GetObjectArrayElement(devices, i));
69 devices_to_pass.push_back(new UsbMidiDeviceAndroid(raw_device, delegate_));
72 callback_.Run(true, &devices_to_pass);
75 // Called from the Java world.
76 void UsbMidiDeviceFactoryAndroid::OnUsbMidiDeviceAttached(
77 JNIEnv* env,
78 jobject caller,
79 jobject device) {
80 UsbMidiDeviceAndroid::ObjectRef raw_device(env, device);
81 delegate_->OnDeviceAttached(
82 scoped_ptr<UsbMidiDevice>(
83 new UsbMidiDeviceAndroid(raw_device, delegate_)));
86 // Called from the Java world.
87 void UsbMidiDeviceFactoryAndroid::OnUsbMidiDeviceDetached(
88 JNIEnv* env,
89 jobject caller,
90 jint index) {
91 delegate_->OnDeviceDetached(index);
94 bool UsbMidiDeviceFactoryAndroid::RegisterUsbMidiDeviceFactory(JNIEnv* env) {
95 return RegisterNativesImpl(env);
98 } // namespace media