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

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

Issue 1098823003: Separate USB device permissions prompt logic into subclasses. (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 5e93155bf47a7d89c4bd5ba1ddebcfe81ba113cd..ed3e1de4701b8b5336ec2e317f83a3b7de411fd3 100644
--- a/extensions/browser/api/device_permissions_prompt.h
+++ b/extensions/browser/api/device_permissions_prompt.h
@@ -10,11 +10,8 @@
#include "base/callback.h"
#include "base/logging.h"
#include "base/memory/ref_counted.h"
-#include "base/scoped_observer.h"
+#include "base/memory/scoped_vector.h"
#include "base/strings/string16.h"
-#include "content/public/browser/browser_thread.h"
-#include "device/usb/usb_device.h"
-#include "device/usb/usb_service.h"
namespace content {
class BrowserContext;
@@ -22,6 +19,7 @@ class WebContents;
}
namespace device {
+class UsbDevice;
class UsbDeviceFilter;
}
@@ -33,27 +31,19 @@ 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();
- };
+ using UsbDevicesCallback = base::Callback<void(
+ const std::vector<scoped_refptr<device::UsbDevice>>&)>;
// Context information available to the UI implementation.
- class Prompt : public base::RefCounted<Prompt>,
- public device::UsbService::Observer {
+ class Prompt : public base::RefCounted<Prompt> {
public:
// Displayed properties of a device.
struct DeviceInfo {
Jeffrey Yasskin 2015/04/23 20:40:07 Describe how this is extended. Probably also mark
Reilly Grant (use Gerrit) 2015/04/23 23:02:47 Done.
- DeviceInfo(scoped_refptr<device::UsbDevice> device);
- ~DeviceInfo();
+ DeviceInfo();
+ virtual ~DeviceInfo();
- scoped_refptr<device::UsbDevice> device;
base::string16 name;
+ base::string16 serial_number;
bool granted = false;
};
@@ -67,14 +57,14 @@ class DevicePermissionsPrompt {
virtual ~Observer();
};
- Prompt(Delegate* delegate,
- const Extension* extension,
- content::BrowserContext* context);
+ Prompt(const Extension* extension,
+ content::BrowserContext* context,
+ bool multiple);
Jeffrey Yasskin 2015/04/23 20:40:07 Comment what "multiple" means.
Reilly Grant (use Gerrit) 2015/04/23 23:02:47 Done.
// Only one observer may be registered at a time.
- void SetObserver(Observer* observer);
+ virtual void SetObserver(Observer* observer);
- base::string16 GetHeading() const;
+ virtual base::string16 GetHeading() const = 0;
base::string16 GetPromptMessage() const;
size_t GetDeviceCount() const { return devices_.size(); }
base::string16 GetDeviceName(size_t index) const;
@@ -83,46 +73,41 @@ class DevicePermissionsPrompt {
// Notifies the DevicePermissionsManager for the current extension that
// access to the device at the given index is now granted.
void GrantDevicePermission(size_t index);
- void Dismissed();
- bool multiple() const { return multiple_; }
+ virtual void Dismissed() = 0;
- void set_multiple(bool multiple) { multiple_ = multiple; }
- void set_filters(const std::vector<device::UsbDeviceFilter>& filters);
-
- private:
- friend class base::RefCounted<Prompt>;
+ bool multiple() const { return multiple_; }
+ protected:
virtual ~Prompt();
- // device::UsbService::Observer implementation:
- void OnDeviceAdded(scoped_refptr<device::UsbDevice> device) override;
- void OnDeviceRemoved(scoped_refptr<device::UsbDevice> device) override;
+ const Extension* extension() const { return extension_; }
+ Observer* observer() const { return observer_; }
+ content::BrowserContext* browser_context() const {
+ return browser_context_;
+ }
+
+ ScopedVector<DeviceInfo> devices_;
Jeffrey Yasskin 2015/04/23 20:40:07 Please comment the rules on the type of the object
Reilly Grant (use Gerrit) 2015/04/23 23:02:47 Done.
- void OnDevicesEnumerated(
- const std::vector<scoped_refptr<device::UsbDevice>>& devices);
- void AddCheckedUsbDevice(scoped_refptr<device::UsbDevice> device,
- bool allowed);
+ private:
+ friend class base::RefCounted<Prompt>;
const extensions::Extension* extension_ = nullptr;
+ Observer* observer_ = nullptr;
content::BrowserContext* browser_context_ = nullptr;
- Delegate* delegate_ = nullptr;
bool multiple_ = false;
- std::vector<device::UsbDeviceFilter> filters_;
- std::vector<DeviceInfo> devices_;
- Observer* observer_ = nullptr;
- ScopedObserver<device::UsbService, device::UsbService::Observer>
- usb_service_observer_;
+
+ DISALLOW_COPY_AND_ASSIGN(Prompt);
};
DevicePermissionsPrompt(content::WebContents* web_contents);
virtual ~DevicePermissionsPrompt();
- void AskForUsbDevices(Delegate* delegate,
- const Extension* extension,
+ void AskForUsbDevices(const Extension* extension,
content::BrowserContext* context,
bool multiple,
- const std::vector<device::UsbDeviceFilter>& filters);
+ const std::vector<device::UsbDeviceFilter>& filters,
+ const UsbDevicesCallback& callback);
protected:
virtual void ShowDialog() = 0;
@@ -136,6 +121,8 @@ class DevicePermissionsPrompt {
// Parameters available to the UI implementation.
scoped_refptr<Prompt> prompt_;
+
+ DISALLOW_COPY_AND_ASSIGN(DevicePermissionsPrompt);
};
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698