| 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 #ifndef EXTENSIONS_BROWSER_DEVICE_PERMISSIONS_PROMPT_H_ | 5 #ifndef EXTENSIONS_BROWSER_DEVICE_PERMISSIONS_PROMPT_H_ |
| 6 #define EXTENSIONS_BROWSER_DEVICE_PERMISSIONS_PROMPT_H_ | 6 #define EXTENSIONS_BROWSER_DEVICE_PERMISSIONS_PROMPT_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/scoped_observer.h" |
| 13 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
| 15 #include "content/public/browser/browser_thread.h" |
| 16 #include "device/usb/usb_service.h" |
| 14 | 17 |
| 15 namespace content { | 18 namespace content { |
| 16 class BrowserContext; | 19 class BrowserContext; |
| 17 class WebContents; | 20 class WebContents; |
| 18 } | 21 } |
| 19 | 22 |
| 20 namespace device { | 23 namespace device { |
| 21 class UsbDevice; | 24 class UsbDevice; |
| 22 class UsbDeviceFilter; | 25 class UsbDeviceFilter; |
| 23 } | 26 } |
| 24 | 27 |
| 25 namespace extensions { | 28 namespace extensions { |
| 26 | 29 |
| 27 class Extension; | 30 class Extension; |
| 28 | 31 |
| 29 // Platform-independent interface for displaing a UI for choosing devices | 32 // Platform-independent interface for displaing a UI for choosing devices |
| 30 // (similar to choosing files). | 33 // (similar to choosing files). |
| 31 class DevicePermissionsPrompt { | 34 class DevicePermissionsPrompt { |
| 32 public: | 35 public: |
| 33 // Context information available to the UI implementation. | 36 // Context information available to the UI implementation. |
| 34 class Prompt : public base::RefCountedThreadSafe<Prompt> { | 37 class Prompt : public base::RefCountedThreadSafe< |
| 38 Prompt, |
| 39 content::BrowserThread::DeleteOnFileThread>, |
| 40 public device::UsbService::Observer { |
| 35 public: | 41 public: |
| 36 // Displayed properties of a device. | 42 // Displayed properties of a device. |
| 37 struct DeviceInfo { | 43 struct DeviceInfo { |
| 38 DeviceInfo(scoped_refptr<device::UsbDevice> device, | 44 DeviceInfo(scoped_refptr<device::UsbDevice> device); |
| 39 const base::string16& name, | |
| 40 const base::string16& product_string, | |
| 41 const base::string16& manufacturer_string, | |
| 42 const base::string16& serial_number); | |
| 43 ~DeviceInfo(); | 45 ~DeviceInfo(); |
| 44 | 46 |
| 45 scoped_refptr<device::UsbDevice> device; | 47 scoped_refptr<device::UsbDevice> device; |
| 46 base::string16 name; | 48 base::string16 name; |
| 47 base::string16 product_string; | 49 base::string16 original_manufacturer_string; |
| 48 base::string16 manufacturer_string; | 50 base::string16 original_product_string; |
| 49 base::string16 serial_number; | 51 base::string16 serial_number; |
| 50 }; | 52 }; |
| 51 | 53 |
| 52 // Since the set of devices can change while the UI is visible an | 54 // Since the set of devices can change while the UI is visible an |
| 53 // implementation should register an observer. | 55 // implementation should register an observer. |
| 54 class Observer { | 56 class Observer { |
| 55 public: | 57 public: |
| 56 virtual void OnDevicesChanged() = 0; | 58 virtual void OnDevicesChanged() = 0; |
| 57 }; | 59 }; |
| 58 | 60 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 89 | 91 |
| 90 bool multiple() const { return multiple_; } | 92 bool multiple() const { return multiple_; } |
| 91 void set_multiple(bool multiple) { multiple_ = multiple; } | 93 void set_multiple(bool multiple) { multiple_ = multiple; } |
| 92 | 94 |
| 93 const std::vector<device::UsbDeviceFilter>& filters() const { | 95 const std::vector<device::UsbDeviceFilter>& filters() const { |
| 94 return filters_; | 96 return filters_; |
| 95 } | 97 } |
| 96 void set_filters(const std::vector<device::UsbDeviceFilter>& filters); | 98 void set_filters(const std::vector<device::UsbDeviceFilter>& filters); |
| 97 | 99 |
| 98 private: | 100 private: |
| 99 friend class base::RefCountedThreadSafe<Prompt>; | 101 friend struct content::BrowserThread::DeleteOnThread< |
| 102 content::BrowserThread::FILE>; |
| 103 friend class base::DeleteHelper<Prompt>; |
| 100 | 104 |
| 101 virtual ~Prompt(); | 105 virtual ~Prompt(); |
| 102 | 106 |
| 103 // Querying for devices must be done asynchronously on the FILE thread. | 107 // Querying for devices must be done asynchronously on the FILE thread. |
| 104 void DoDeviceQuery(); | 108 void DoDeviceQuery(); |
| 105 void SetDevices(const std::vector<DeviceInfo>& devices); | 109 void SetDevices(const std::vector<DeviceInfo>& devices); |
| 110 void AddDevice(const DeviceInfo& device); |
| 111 void RemoveDevice(scoped_refptr<device::UsbDevice> device); |
| 112 |
| 113 // device::UsbService::Observer implementation: |
| 114 void OnDeviceAdded(scoped_refptr<device::UsbDevice> device) override; |
| 115 void OnDeviceRemoved(scoped_refptr<device::UsbDevice> device) override; |
| 106 | 116 |
| 107 const extensions::Extension* extension_; | 117 const extensions::Extension* extension_; |
| 108 content::BrowserContext* browser_context_; | 118 content::BrowserContext* browser_context_; |
| 109 bool multiple_; | 119 bool multiple_; |
| 110 std::vector<device::UsbDeviceFilter> filters_; | 120 std::vector<device::UsbDeviceFilter> filters_; |
| 111 std::vector<DeviceInfo> devices_; | 121 std::vector<DeviceInfo> devices_; |
| 112 Observer* observer_; | 122 Observer* observer_; |
| 123 ScopedObserver<device::UsbService, device::UsbService::Observer> |
| 124 usb_service_observer_; |
| 113 }; | 125 }; |
| 114 | 126 |
| 115 class Delegate { | 127 class Delegate { |
| 116 public: | 128 public: |
| 117 // Called with the list of selected USB devices. | 129 // Called with the list of selected USB devices. |
| 118 virtual void OnUsbDevicesChosen( | 130 virtual void OnUsbDevicesChosen( |
| 119 const std::vector<scoped_refptr<device::UsbDevice>>& devices) = 0; | 131 const std::vector<scoped_refptr<device::UsbDevice>>& devices) = 0; |
| 120 | 132 |
| 121 protected: | 133 protected: |
| 122 virtual ~Delegate() {} | 134 virtual ~Delegate() {} |
| (...skipping 22 matching lines...) Expand all Loading... |
| 145 // The delegate called after the UI has been dismissed. | 157 // The delegate called after the UI has been dismissed. |
| 146 Delegate* delegate_; | 158 Delegate* delegate_; |
| 147 | 159 |
| 148 // Parameters available to the UI implementation. | 160 // Parameters available to the UI implementation. |
| 149 scoped_refptr<Prompt> prompt_; | 161 scoped_refptr<Prompt> prompt_; |
| 150 }; | 162 }; |
| 151 | 163 |
| 152 } // namespace extensions | 164 } // namespace extensions |
| 153 | 165 |
| 154 #endif // EXTENSIONS_BROWSER_API_DEVICE_PERMISSIONS_PROMPT_H_ | 166 #endif // EXTENSIONS_BROWSER_API_DEVICE_PERMISSIONS_PROMPT_H_ |
| OLD | NEW |