Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(278)

Unified Diff: extensions/browser/api/device_permissions_prompt.h

Issue 1097603003: Remove knowledge of USB devices from permission prompt implementations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: extensions/browser/api/device_permissions_prompt.h
diff --git a/extensions/browser/api/device_permissions_prompt.h b/extensions/browser/api/device_permissions_prompt.h
index 26775bf81595de159fb7b17e17eb0091ddbd830b..30424f6abb8bdf3fe05002ba598463a3c3a414d6 100644
--- a/extensions/browser/api/device_permissions_prompt.h
+++ b/extensions/browser/api/device_permissions_prompt.h
@@ -33,6 +33,16 @@ class Extension;
// (similar to choosing files).
class DevicePermissionsPrompt {
public:
+ class Delegate {
+ public:
+ // Called with the list of selected USB devices.
+ virtual void OnUsbDevicesChosen(
+ const std::vector<scoped_refptr<device::UsbDevice>>& devices) = 0;
+
+ protected:
+ virtual ~Delegate();
+ };
+
// Context information available to the UI implementation.
class Prompt : public base::RefCounted<Prompt>,
public device::UsbService::Observer {
@@ -44,6 +54,7 @@ class DevicePermissionsPrompt {
scoped_refptr<device::UsbDevice> device;
base::string16 name;
+ bool granted = false;
};
// Since the set of devices can change while the UI is visible an
@@ -51,9 +62,14 @@ class DevicePermissionsPrompt {
class Observer {
public:
virtual void OnDevicesChanged() = 0;
+
+ protected:
+ virtual ~Observer();
};
- Prompt();
+ Prompt(Delegate* delegate,
+ const Extension* extension,
+ content::BrowserContext* context);
// Only one observer may be registered at a time.
void SetObserver(Observer* observer);
@@ -61,35 +77,17 @@ class DevicePermissionsPrompt {
base::string16 GetHeading() const;
base::string16 GetPromptMessage() const;
size_t GetDeviceCount() const { return devices_.size(); }
- scoped_refptr<device::UsbDevice> GetDevice(size_t index) const;
- base::string16 GetDeviceName(size_t index) const {
- DCHECK_LT(index, devices_.size());
- return devices_[index].name;
- }
- base::string16 GetDeviceSerialNumber(size_t index) const {
- DCHECK_LT(index, devices_.size());
- return devices_[index].device->serial_number();
- }
+ base::string16 GetDeviceName(size_t index) const;
+ base::string16 GetDeviceSerialNumber(size_t index) const;
// Notifies the DevicePermissionsManager for the current extension that
// access to the device at the given index is now granted.
- void GrantDevicePermission(size_t index) const;
-
- const extensions::Extension* extension() const { return extension_; }
- void set_extension(const extensions::Extension* extension) {
- extension_ = extension;
- }
-
- void set_browser_context(content::BrowserContext* context) {
- browser_context_ = context;
- }
+ void GrantDevicePermission(size_t index);
+ void Dismissed();
bool multiple() const { return multiple_; }
- void set_multiple(bool multiple) { multiple_ = multiple; }
- const std::vector<device::UsbDeviceFilter>& filters() const {
- return filters_;
- }
+ void set_multiple(bool multiple) { multiple_ = multiple; }
void set_filters(const std::vector<device::UsbDeviceFilter>& filters);
private:
@@ -108,6 +106,7 @@ class DevicePermissionsPrompt {
const extensions::Extension* extension_ = nullptr;
content::BrowserContext* browser_context_ = nullptr;
+ Delegate* delegate_;
Devlin 2015/04/17 19:39:25 init to null?
Reilly Grant (use Gerrit) 2015/04/17 20:05:03 Done.
bool multiple_ = false;
std::vector<device::UsbDeviceFilter> filters_;
std::vector<DeviceInfo> devices_;
@@ -116,16 +115,6 @@ class DevicePermissionsPrompt {
usb_service_observer_;
};
- class Delegate {
- public:
- // Called with the list of selected USB devices.
- virtual void OnUsbDevicesChosen(
- const std::vector<scoped_refptr<device::UsbDevice>>& devices) = 0;
-
- protected:
- virtual ~Delegate() {}
- };
-
DevicePermissionsPrompt(content::WebContents* web_contents);
virtual ~DevicePermissionsPrompt();
@@ -139,16 +128,12 @@ class DevicePermissionsPrompt {
virtual void ShowDialog() = 0;
content::WebContents* web_contents() { return web_contents_; }
- Delegate* delegate() { return delegate_; }
scoped_refptr<Prompt> prompt() { return prompt_; }
private:
// Parent web contents of the device permissions UI dialog.
content::WebContents* web_contents_;
- // The delegate called after the UI has been dismissed.
- Delegate* delegate_;
-
// Parameters available to the UI implementation.
scoped_refptr<Prompt> prompt_;
};

Powered by Google App Engine
This is Rietveld 408576698