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

Side by Side Diff: device/devices_app/usb/device_manager_impl.h

Issue 1316203006: Convert DeviceManagerDelegate to PermissionProvider mojo interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 DEVICE_USB_DEVICE_MANAGER_IMPL_H_ 5 #ifndef DEVICE_USB_DEVICE_MANAGER_IMPL_H_
6 #define DEVICE_USB_DEVICE_MANAGER_IMPL_H_ 6 #define DEVICE_USB_DEVICE_MANAGER_IMPL_H_
7 7
8 #include <queue> 8 #include <queue>
9 #include <set> 9 #include <set>
10 10
11 #include "base/containers/scoped_ptr_map.h" 11 #include "base/containers/scoped_ptr_map.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "device/devices_app/usb/public/interfaces/device_manager.mojom.h" 16 #include "device/devices_app/usb/public/interfaces/device_manager.mojom.h"
17 #include "device/devices_app/usb/public/interfaces/permission_provider.mojom.h"
17 #include "third_party/mojo/src/mojo/public/cpp/bindings/array.h" 18 #include "third_party/mojo/src/mojo/public/cpp/bindings/array.h"
18 #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_request.h" 19 #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_request.h"
19 #include "third_party/mojo/src/mojo/public/cpp/bindings/strong_binding.h" 20 #include "third_party/mojo/src/mojo/public/cpp/bindings/strong_binding.h"
20 21
21 namespace base { 22 namespace base {
22 class SequencedTaskRunner; 23 class SequencedTaskRunner;
23 } 24 }
24 25
25 namespace device { 26 namespace device {
26 27
27 class UsbDevice; 28 class UsbDevice;
28 class UsbDeviceFilter; 29 class UsbDeviceFilter;
29 class UsbDeviceHandle; 30 class UsbDeviceHandle;
30 31
31 namespace usb { 32 namespace usb {
32 33
33 class DeviceManagerDelegate; 34 class DeviceManagerDelegate;
34 35
35 // Implementation of the public DeviceManager interface. This interface can be 36 // Implementation of the public DeviceManager interface. This interface can be
36 // requested from the devices app located at "mojo:devices", if available. 37 // requested from the devices app located at "mojo:devices", if available.
37 class DeviceManagerImpl : public DeviceManager { 38 class DeviceManagerImpl : public DeviceManager {
38 public: 39 public:
39 DeviceManagerImpl( 40 DeviceManagerImpl(
40 mojo::InterfaceRequest<DeviceManager> request, 41 mojo::InterfaceRequest<DeviceManager> request,
41 scoped_ptr<DeviceManagerDelegate> delegate, 42 PermissionProviderPtr permission_provider,
42 scoped_refptr<base::SequencedTaskRunner> service_task_runner); 43 scoped_refptr<base::SequencedTaskRunner> service_task_runner);
43 ~DeviceManagerImpl() override; 44 ~DeviceManagerImpl() override;
44 45
45 void set_connection_error_handler(const mojo::Closure& error_handler); 46 void set_connection_error_handler(const mojo::Closure& error_handler);
46 47
47 private: 48 private:
48 class ServiceThreadHelper; 49 class ServiceThreadHelper;
49 50
50 // DeviceManager implementation: 51 // DeviceManager implementation:
51 void GetDevices(EnumerationOptionsPtr options, 52 void GetDevices(EnumerationOptionsPtr options,
52 const GetDevicesCallback& callback) override; 53 const GetDevicesCallback& callback) override;
53 void GetDeviceChanges(const GetDeviceChangesCallback& callback) override; 54 void GetDeviceChanges(const GetDeviceChangesCallback& callback) override;
54 void OpenDevice(const mojo::String& guid, 55 void OpenDevice(const mojo::String& guid,
55 mojo::InterfaceRequest<Device> device_request, 56 mojo::InterfaceRequest<Device> device_request,
56 const OpenDeviceCallback& callback) override; 57 const OpenDeviceCallback& callback) override;
57 58
58 // Callbacks to handle the async responses from the underlying UsbService. 59 // Callbacks to handle the async responses from the underlying UsbService.
59 void OnGetDevices(const GetDevicesCallback& callback, 60 void OnGetDevices(const GetDevicesCallback& callback,
60 mojo::Array<DeviceInfoPtr> devices); 61 mojo::Array<DeviceInfoPtr> devices);
61 void OnGetInitialDevices(const GetDeviceChangesCallback& callback, 62 void OnGetInitialDevices(mojo::Array<DeviceInfoPtr> devices);
62 mojo::Array<DeviceInfoPtr> devices);
63 63
64 // Methods called by |helper_| when devices are added or removed. 64 // Methods called by |helper_| when devices are added or removed.
65 void OnDeviceAdded(DeviceInfoPtr device); 65 void OnDeviceAdded(DeviceInfoPtr device);
66 void OnDeviceRemoved(std::string device_guid); 66 void OnDeviceRemoved(std::string device_guid);
67 void MaybeRunDeviceChangesCallback(); 67 void MaybeRunDeviceChangesCallback();
68 void OnPermissionCheckComplete(mojo::Array<DeviceInfoPtr> devices_added,
69 const std::set<std::string>& devices_removed,
70 mojo::Array<mojo::String> allowed_guids);
68 71
69 mojo::StrongBinding<DeviceManager> binding_; 72 mojo::StrongBinding<DeviceManager> binding_;
Ken Rockot(use gerrit already) 2015/09/02 22:42:33 as discussed offline, this can become a mojo::Bind
Ken Rockot(use gerrit already) 2015/09/02 23:07:18 to preserve what was also just discussed offline,
Reilly Grant (use Gerrit) 2015/09/02 23:58:19 Done.
70 73
71 scoped_ptr<DeviceManagerDelegate> delegate_; 74 PermissionProviderPtr permission_provider_;
72 scoped_refptr<base::SequencedTaskRunner> service_task_runner_; 75 scoped_refptr<base::SequencedTaskRunner> service_task_runner_;
73 76
74 // If there are unfinished calls to GetDeviceChanges their callbacks 77 // If there are unfinished calls to GetDeviceChanges their callbacks
75 // are stored in |device_change_callbacks_|. Otherwise device changes 78 // are stored in |device_change_callbacks_|. Otherwise device changes
76 // are collected in |devices_added_| and |devices_removed_| until the 79 // are collected in |devices_added_| and |devices_removed_| until the
77 // next call to GetDeviceChanges. 80 // next call to GetDeviceChanges.
78 std::queue<GetDeviceChangesCallback> device_change_callbacks_; 81 std::queue<GetDeviceChangesCallback> device_change_callbacks_;
79 mojo::Array<DeviceInfoPtr> devices_added_; 82 mojo::Array<DeviceInfoPtr> devices_added_;
80 std::set<std::string> devices_removed_; 83 std::set<std::string> devices_removed_;
84 // To ensure that GetDeviceChangesCallbacks are called in the correct order
85 // only perform a single request to |permission_provider_| at a time.
86 bool permission_request_pending_ = false;
87 // The first notification is allowed to be empty. All others are not.
88 bool first_notification_ = true;
81 89
82 // |helper_| is owned by the service thread and holds a weak reference 90 // |helper_| is owned by the service thread and holds a weak reference
83 // back to the device manager that created it. 91 // back to the device manager that created it.
84 ServiceThreadHelper* helper_ = nullptr; 92 ServiceThreadHelper* helper_ = nullptr;
85 93
86 base::WeakPtrFactory<DeviceManagerImpl> weak_factory_; 94 base::WeakPtrFactory<DeviceManagerImpl> weak_factory_;
87 95
88 DISALLOW_COPY_AND_ASSIGN(DeviceManagerImpl); 96 DISALLOW_COPY_AND_ASSIGN(DeviceManagerImpl);
89 }; 97 };
90 98
91 } // namespace usb 99 } // namespace usb
92 } // namespace device 100 } // namespace device
93 101
94 #endif // DEVICE_USB_DEVICE_MANAGER_IMPL_H_ 102 #endif // DEVICE_USB_DEVICE_MANAGER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698