OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 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. | |
4 | |
5 #ifndef CHROME_BROWSER_UI_ANDROID_USB_CHOOSER_ANDROID_H_ | |
6 #define CHROME_BROWSER_UI_ANDROID_USB_CHOOSER_ANDROID_H_ | |
7 | |
8 #include <string> | |
9 #include <vector> | |
10 | |
11 #include "base/android/scoped_java_ref.h" | |
12 #include "base/macros.h" | |
13 #include "base/memory/ref_counted.h" | |
14 #include "base/memory/weak_ptr.h" | |
15 #include "base/scoped_observer.h" | |
16 #include "base/strings/string16.h" | |
17 #include "device/usb/public/interfaces/chooser_service.mojom.h" | |
18 #include "device/usb/usb_service.h" | |
19 #include "mojo/public/cpp/bindings/array.h" | |
20 | |
21 namespace content { | |
22 class RenderFrameHost; | |
23 class WebContents; | |
24 } | |
25 | |
26 namespace device { | |
27 class UsbDevice; | |
28 class UsbDeviceFilter; | |
29 } | |
30 | |
31 // Represents a way to ask the user to select a USB device from a list of | |
32 // options. | |
33 class UsbChooserAndroid : public device::UsbService::Observer { | |
newt (away)
2016/03/15 19:03:54
For consistency with the java side of this class,
juncai
2016/03/16 00:40:36
Done.
| |
34 public: | |
35 UsbChooserAndroid( | |
36 mojo::Array<device::usb::DeviceFilterPtr> device_filters, | |
37 content::RenderFrameHost* render_frame_host, | |
38 const device::usb::ChooserService::GetPermissionCallback& callback); | |
39 ~UsbChooserAndroid() override; | |
40 | |
41 // device::UsbService::Observer: | |
42 void OnDeviceAdded(scoped_refptr<device::UsbDevice> device) override; | |
43 void OnDeviceRemoved(scoped_refptr<device::UsbDevice> device) override; | |
44 | |
45 // Called when the user selects the USB device with |guid| from the chooser | |
46 // dialog. | |
47 void Select(const std::string& guid); | |
48 // Called when the chooser dialog is closed. | |
49 void Cancel(); | |
50 | |
51 // Report the dialog's result. | |
52 void OnDialogFinished(JNIEnv* env, | |
53 const base::android::JavaParamRef<jobject>& obj, | |
54 jint event_type, | |
55 const base::android::JavaParamRef<jstring>& device_id); | |
56 | |
57 void ShowUsbOverviewLink(JNIEnv* env, | |
58 const base::android::JavaParamRef<jobject>& obj); | |
59 | |
60 static bool Register(JNIEnv* env); | |
61 | |
62 private: | |
63 void GotUsbDeviceList( | |
64 const std::vector<scoped_refptr<device::UsbDevice>>& devices); | |
65 | |
66 void AddDeviceToChooserDialog(scoped_refptr<device::UsbDevice> device) const; | |
67 void RemoveDeviceFromChooserDialog( | |
68 scoped_refptr<device::UsbDevice> device) const; | |
69 | |
70 void OpenUrl(const std::string& url); | |
71 | |
72 content::RenderFrameHost* const render_frame_host_; | |
73 device::usb::ChooserService::GetPermissionCallback callback_; | |
74 ScopedObserver<device::UsbService, device::UsbService::Observer> | |
75 usb_service_observer_; | |
76 std::vector<device::UsbDeviceFilter> filters_; | |
77 | |
78 std::vector<scoped_refptr<device::UsbDevice>> devices_; | |
79 | |
80 base::android::ScopedJavaGlobalRef<jobject> java_dialog_; | |
81 base::WeakPtrFactory<UsbChooserAndroid> weak_factory_; | |
82 | |
83 DISALLOW_COPY_AND_ASSIGN(UsbChooserAndroid); | |
84 }; | |
85 | |
86 #endif // CHROME_BROWSER_UI_ANDROID_USB_CHOOSER_ANDROID_H_ | |
OLD | NEW |