| 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 #ifndef DEVICE_USB_USB_SERVICE_ANDROID_H_ | 5 #ifndef DEVICE_USB_USB_SERVICE_ANDROID_H_ |
| 6 #define DEVICE_USB_USB_SERVICE_ANDROID_H_ | 6 #define DEVICE_USB_USB_SERVICE_ANDROID_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <unordered_map> |
| 9 | 10 |
| 10 #include "base/android/scoped_java_ref.h" | 11 #include "base/android/scoped_java_ref.h" |
| 11 #include "device/usb/usb_service.h" | 12 #include "device/usb/usb_service.h" |
| 12 | 13 |
| 13 namespace device { | 14 namespace device { |
| 14 | 15 |
| 16 class UsbDeviceAndroid; |
| 17 |
| 15 // USB service implementation for Android. This is a stub implementation that | 18 // USB service implementation for Android. This is a stub implementation that |
| 16 // does not return any devices. | 19 // does not return any devices. |
| 17 class UsbServiceAndroid : public UsbService { | 20 class UsbServiceAndroid : public UsbService { |
| 18 public: | 21 public: |
| 19 // Register C++ methods exposed to Java using JNI. | 22 // Register C++ methods exposed to Java using JNI. |
| 20 static bool RegisterJNI(JNIEnv* env); | 23 static bool RegisterJNI(JNIEnv* env); |
| 21 | 24 |
| 22 UsbServiceAndroid(); | 25 UsbServiceAndroid(); |
| 23 ~UsbServiceAndroid() override; | 26 ~UsbServiceAndroid() override; |
| 24 | 27 |
| 25 // UsbService: | 28 // UsbService: |
| 26 scoped_refptr<UsbDevice> GetDevice(const std::string& guid) override; | 29 scoped_refptr<UsbDevice> GetDevice(const std::string& guid) override; |
| 27 void GetDevices(const GetDevicesCallback& callback) override; | 30 void GetDevices(const GetDevicesCallback& callback) override; |
| 28 | 31 |
| 32 // Methods called by Java. |
| 33 void DeviceAttached(JNIEnv* env, |
| 34 const base::android::JavaRef<jobject>& caller, |
| 35 const base::android::JavaRef<jobject>& usb_device); |
| 36 void DeviceDetached(JNIEnv* env, |
| 37 const base::android::JavaRef<jobject>& caller, |
| 38 jint device_id); |
| 39 |
| 29 private: | 40 private: |
| 41 void AddDevice(scoped_refptr<UsbDeviceAndroid> device); |
| 42 |
| 43 std::unordered_map<jint, scoped_refptr<UsbDeviceAndroid>> devices_by_id_; |
| 44 std::unordered_map<std::string, scoped_refptr<UsbDeviceAndroid>> |
| 45 devices_by_guid_; |
| 46 |
| 30 // Java object org.chromium.device.usb.ChromeUsbService. | 47 // Java object org.chromium.device.usb.ChromeUsbService. |
| 31 base::android::ScopedJavaGlobalRef<jobject> j_object_; | 48 base::android::ScopedJavaGlobalRef<jobject> j_object_; |
| 32 }; | 49 }; |
| 33 | 50 |
| 34 } // namespace device | 51 } // namespace device |
| 35 | 52 |
| 36 #endif // DEVICE_USB_USB_SERVICE_ANDROID_H_ | 53 #endif // DEVICE_USB_USB_SERVICE_ANDROID_H_ |
| OLD | NEW |