Chromium Code Reviews| Index: extensions/browser/api/device_permissions_manager.h |
| diff --git a/extensions/browser/api/device_permissions_manager.h b/extensions/browser/api/device_permissions_manager.h |
| index 159cd7b3244b90d1cb9ea819374ea7f6c98140f2..600a1b1b7e7e8446033dc800e7f36e5b98dd3ee2 100644 |
| --- a/extensions/browser/api/device_permissions_manager.h |
| +++ b/extensions/browser/api/device_permissions_manager.h |
| @@ -40,13 +40,7 @@ namespace extensions { |
| class DevicePermissionEntry |
| : public base::RefCountedThreadSafe<DevicePermissionEntry> { |
| public: |
| - // TODO(reillyg): This function should be able to take only the |
| - // device::UsbDevice and read the strings from there. This is not yet possible |
| - // as the device can not be accessed from the UI thread. crbug.com/427985 |
| - DevicePermissionEntry(scoped_refptr<device::UsbDevice> device, |
| - const base::string16& serial_number, |
| - const base::string16& manufacturer_string, |
| - const base::string16& product_string); |
| + DevicePermissionEntry(scoped_refptr<device::UsbDevice> device); |
| DevicePermissionEntry(uint16_t vendor_id, |
| uint16_t product_id, |
| const base::string16& serial_number, |
| @@ -98,7 +92,7 @@ class DevicePermissionEntry |
| base::Time last_used_; |
| }; |
| -// Stores a copy of device permissions associated with a particular extension. |
| +// Stores device permissions associated with a particular extension. |
| class DevicePermissions { |
| public: |
| virtual ~DevicePermissions(); |
| @@ -108,8 +102,7 @@ class DevicePermissions { |
| // to call device->GetSerialNumber() which may not be possible on the |
| // current thread. |
| scoped_refptr<DevicePermissionEntry> FindEntry( |
| - scoped_refptr<device::UsbDevice> device, |
| - const base::string16& serial_number) const; |
| + scoped_refptr<device::UsbDevice> device) const; |
| const std::set<scoped_refptr<DevicePermissionEntry>>& entries() const { |
| return entries_; |
| @@ -121,9 +114,6 @@ class DevicePermissions { |
| // Reads permissions out of ExtensionPrefs. |
| DevicePermissions(content::BrowserContext* context, |
| const std::string& extension_id); |
| - // Does a shallow copy, duplicating the device lists so that the resulting |
| - // object can be used from a different thread. |
| - DevicePermissions(const DevicePermissions* original); |
| std::set<scoped_refptr<DevicePermissionEntry>> entries_; |
| std::map<scoped_refptr<device::UsbDevice>, |
| @@ -135,28 +125,21 @@ class DevicePermissions { |
| // Manages saved device permissions for all extensions. |
| class DevicePermissionsManager : public KeyedService, |
| public base::NonThreadSafe, |
| - public ProcessManagerObserver { |
| + public ProcessManagerObserver, |
| + public device::UsbService::Observer { |
| public: |
| static DevicePermissionsManager* Get(content::BrowserContext* context); |
| - // Returns a copy of the DevicePermissions object for a given extension that |
| - // can be used by any thread. |
| - scoped_ptr<DevicePermissions> GetForExtension( |
| - const std::string& extension_id); |
| + // The DevicePermissions object for a given extension. |
| + DevicePermissions* GetForExtension(const std::string& extension_id); |
| // Equivalent to calling GetForExtension and extracting the permission string |
| // for each entry. |
| std::vector<base::string16> GetPermissionMessageStrings( |
| const std::string& extension_id) const; |
| - // TODO(reillyg): AllowUsbDevice should only take the extension ID and |
| - // device, with the strings read from the device. This isn't possible now as |
| - // the device can not be accessed from the UI thread yet. crbug.com/427985 |
| void AllowUsbDevice(const std::string& extension_id, |
| - scoped_refptr<device::UsbDevice> device, |
| - const base::string16& serial_number, |
| - const base::string16& manufacturer_string, |
| - const base::string16& product_string); |
| + scoped_refptr<device::UsbDevice> device); |
| // Updates the "last used" timestamp on the given device entry and writes it |
| // out to ExtensionPrefs. |
| @@ -171,7 +154,6 @@ class DevicePermissionsManager : public KeyedService, |
| void Clear(const std::string& extension_id); |
| private: |
| - class FileThreadHelper; |
| friend class DevicePermissionsManagerFactory; |
| FRIEND_TEST_ALL_PREFIXES(DevicePermissionsManagerTest, SuspendExtension); |
| @@ -180,19 +162,19 @@ class DevicePermissionsManager : public KeyedService, |
| ~DevicePermissionsManager() override; |
| DevicePermissions* Get(const std::string& extension_id) const; |
|
Ken Rockot(use gerrit already)
2015/04/08 07:45:57
nit: I find Get and GetForExtension to be confusin
Reilly Grant (use Gerrit)
2015/04/08 21:39:04
An important difference is also that Get() is cons
|
| - DevicePermissions* GetOrInsert(const std::string& extension_id); |
| - void OnDeviceRemoved(scoped_refptr<device::UsbDevice> device); |
| // ProcessManagerObserver implementation |
| void OnBackgroundHostClose(const std::string& extension_id) override; |
| + // UsbService::Observer implementation |
| + void OnDeviceRemovedCleanup(scoped_refptr<device::UsbDevice> device) override; |
| + |
| content::BrowserContext* context_; |
| std::map<std::string, DevicePermissions*> extension_id_to_device_permissions_; |
| ScopedObserver<ProcessManager, ProcessManagerObserver> |
| process_manager_observer_; |
| - FileThreadHelper* helper_; |
| - |
| - base::WeakPtrFactory<DevicePermissionsManager> weak_factory_; |
| + ScopedObserver<device::UsbService, device::UsbService::Observer> |
| + usb_service_observer_; |
| DISALLOW_COPY_AND_ASSIGN(DevicePermissionsManager); |
| }; |