OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 CONTENT_RENDERER_MEDIA_MEDIA_DEVICES_EVENT_DISPATCHER_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_DEVICES_EVENT_DISPATCHER_H_ |
6 #define CONTENT_RENDERER_MEDIA_MEDIA_DEVICES_EVENT_DISPATCHER_H_ | 6 #define CONTENT_RENDERER_MEDIA_MEDIA_DEVICES_EVENT_DISPATCHER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <utility> | 10 #include <utility> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "base/threading/thread_checker.h" | 15 #include "base/threading/thread_checker.h" |
16 #include "content/common/content_export.h" | 16 #include "content/common/content_export.h" |
17 #include "content/common/media/media_devices.h" | 17 #include "content/common/media/media_devices.h" |
18 #include "content/common/media/media_devices.mojom.h" | 18 #include "content/common/media/media_devices.mojom.h" |
19 #include "content/public/renderer/render_frame_observer.h" | 19 #include "content/public/renderer/render_frame_observer.h" |
20 #include "content/public/renderer/render_frame_observer_tracker.h" | 20 #include "content/public/renderer/render_frame_observer_tracker.h" |
21 | 21 |
22 namespace url { | |
23 class Origin; | |
24 } | |
25 | |
26 namespace content { | 22 namespace content { |
27 | 23 |
28 // This class implements the logic for managing media device-change | 24 // This class implements the logic for managing media device-change |
29 // subscriptions on the renderer process. It manages the generation of | 25 // subscriptions on the renderer process. It manages the generation of |
30 // subscription IDs and handles the interaction with the Mojo objects that | 26 // subscription IDs and handles the interaction with the Mojo objects that |
31 // communicate with the browser process. There is at most one instance of this | 27 // communicate with the browser process. There is at most one instance of this |
32 // class per frame. | 28 // class per frame. |
33 class CONTENT_EXPORT MediaDevicesEventDispatcher | 29 class CONTENT_EXPORT MediaDevicesEventDispatcher |
34 : public RenderFrameObserver, | 30 : public RenderFrameObserver, |
35 public RenderFrameObserverTracker<MediaDevicesEventDispatcher>, | 31 public RenderFrameObserverTracker<MediaDevicesEventDispatcher>, |
36 public base::SupportsWeakPtr<MediaDevicesEventDispatcher> { | 32 public base::SupportsWeakPtr<MediaDevicesEventDispatcher> { |
37 public: | 33 public: |
38 using SubscriptionId = uint32_t; | 34 using SubscriptionId = uint32_t; |
39 using SubscriptionIdList = std::vector<SubscriptionId>; | 35 using SubscriptionIdList = std::vector<SubscriptionId>; |
40 using DevicesChangedCallback = | 36 using DevicesChangedCallback = |
41 base::Callback<void(MediaDeviceType, const MediaDeviceInfoArray&)>; | 37 base::Callback<void(MediaDeviceType, const MediaDeviceInfoArray&)>; |
42 | 38 |
43 // Returns a weak pointer to the MediaDevicesEventDispatcher for the given | 39 // Returns a weak pointer to the MediaDevicesEventDispatcher for the given |
44 // |render_frame|. | 40 // |render_frame|. |
45 static base::WeakPtr<MediaDevicesEventDispatcher> GetForRenderFrame( | 41 static base::WeakPtr<MediaDevicesEventDispatcher> GetForRenderFrame( |
46 RenderFrame* render_frame); | 42 RenderFrame* render_frame); |
47 | 43 |
48 ~MediaDevicesEventDispatcher() override; | 44 ~MediaDevicesEventDispatcher() override; |
49 | 45 |
50 // Register a callback for device-change notifications for a given device | 46 // Register a callback for device-change notifications for a given device |
51 // type. Returns a subscription ID that can be used to cancel the | 47 // type. Returns a subscription ID that can be used to cancel the |
52 // subscription. | 48 // subscription. |
53 SubscriptionId SubscribeDeviceChangeNotifications( | 49 SubscriptionId SubscribeDeviceChangeNotifications( |
54 MediaDeviceType type, | 50 MediaDeviceType type, |
55 const url::Origin& security_origin, | |
56 const DevicesChangedCallback& callback); | 51 const DevicesChangedCallback& callback); |
57 | 52 |
58 // Cancels a subscription identified with |subscription_id| to device-change | 53 // Cancels a subscription identified with |subscription_id| to device-change |
59 // notifications for device type |type|. If no subscription identified with | 54 // notifications for device type |type|. If no subscription identified with |
60 // |subscription_id| exists for device type |type|, this function returns | 55 // |subscription_id| exists for device type |type|, this function returns |
61 // without side effects. | 56 // without side effects. |
62 void UnsubscribeDeviceChangeNotifications(MediaDeviceType type, | 57 void UnsubscribeDeviceChangeNotifications(MediaDeviceType type, |
63 SubscriptionId subscription_id); | 58 SubscriptionId subscription_id); |
64 | 59 |
65 // Register a callback for device-change notifications for any device type. | 60 // Register a callback for device-change notifications for any device type. |
66 // Returns a list of subscription IDs that can be used to cancel the | 61 // Returns a list of subscription IDs that can be used to cancel the |
67 // subscriptions. | 62 // subscriptions. |
68 SubscriptionIdList SubscribeDeviceChangeNotifications( | 63 SubscriptionIdList SubscribeDeviceChangeNotifications( |
69 const url::Origin& security_origin, | |
70 const DevicesChangedCallback& callback); | 64 const DevicesChangedCallback& callback); |
71 | 65 |
72 // Cancels subscriptions identified by |subscription_ids| to device-change | 66 // Cancels subscriptions identified by |subscription_ids| to device-change |
73 // notifications for all device types. This is implemented by invoking the | 67 // notifications for all device types. This is implemented by invoking the |
74 // single-parameter version of UnsubscribeDeviceChangeNotifications() for all | 68 // single-parameter version of UnsubscribeDeviceChangeNotifications() for all |
75 // device types. | 69 // device types. |
76 void UnsubscribeDeviceChangeNotifications( | 70 void UnsubscribeDeviceChangeNotifications( |
77 const SubscriptionIdList& subscription_ids); | 71 const SubscriptionIdList& subscription_ids); |
78 | 72 |
79 // Dispatches an event notification to all registered callbacks for device | 73 // Dispatches an event notification to all registered callbacks for device |
(...skipping 22 matching lines...) Expand all Loading... |
102 ::mojom::MediaDevicesDispatcherHostPtr media_devices_dispatcher_; | 96 ::mojom::MediaDevicesDispatcherHostPtr media_devices_dispatcher_; |
103 | 97 |
104 base::ThreadChecker thread_checker_; | 98 base::ThreadChecker thread_checker_; |
105 | 99 |
106 DISALLOW_COPY_AND_ASSIGN(MediaDevicesEventDispatcher); | 100 DISALLOW_COPY_AND_ASSIGN(MediaDevicesEventDispatcher); |
107 }; | 101 }; |
108 | 102 |
109 } // namespace content | 103 } // namespace content |
110 | 104 |
111 #endif // CONTENT_RENDERER_MEDIA_MEDIA_DEVICES_EVENT_DISPATCHER_H_ | 105 #endif // CONTENT_RENDERER_MEDIA_MEDIA_DEVICES_EVENT_DISPATCHER_H_ |
OLD | NEW |