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 #include "content/renderer/media/media_devices_event_dispatcher.h" | 5 #include "content/renderer/media/media_devices_event_dispatcher.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 19 matching lines...) Expand all Loading... |
30 RenderFrame* render_frame) | 30 RenderFrame* render_frame) |
31 : RenderFrameObserver(render_frame), | 31 : RenderFrameObserver(render_frame), |
32 RenderFrameObserverTracker<MediaDevicesEventDispatcher>(render_frame), | 32 RenderFrameObserverTracker<MediaDevicesEventDispatcher>(render_frame), |
33 current_id_(0) {} | 33 current_id_(0) {} |
34 | 34 |
35 MediaDevicesEventDispatcher::~MediaDevicesEventDispatcher() {} | 35 MediaDevicesEventDispatcher::~MediaDevicesEventDispatcher() {} |
36 | 36 |
37 MediaDevicesEventDispatcher::SubscriptionId | 37 MediaDevicesEventDispatcher::SubscriptionId |
38 MediaDevicesEventDispatcher::SubscribeDeviceChangeNotifications( | 38 MediaDevicesEventDispatcher::SubscribeDeviceChangeNotifications( |
39 MediaDeviceType type, | 39 MediaDeviceType type, |
40 const url::Origin& security_origin, | |
41 const MediaDevicesEventDispatcher::DevicesChangedCallback& callback) { | 40 const MediaDevicesEventDispatcher::DevicesChangedCallback& callback) { |
42 DCHECK(thread_checker_.CalledOnValidThread()); | 41 DCHECK(thread_checker_.CalledOnValidThread()); |
43 DCHECK(IsValidMediaDeviceType(type)); | 42 DCHECK(IsValidMediaDeviceType(type)); |
44 | 43 |
45 SubscriptionId subscription_id = ++current_id_; | 44 SubscriptionId subscription_id = ++current_id_; |
46 GetMediaDevicesDispatcher()->SubscribeDeviceChangeNotifications( | 45 GetMediaDevicesDispatcher()->SubscribeDeviceChangeNotifications( |
47 type, subscription_id, security_origin); | 46 type, subscription_id); |
48 SubscriptionList& subscriptions = device_change_subscriptions_[type]; | 47 SubscriptionList& subscriptions = device_change_subscriptions_[type]; |
49 subscriptions.push_back(Subscription{subscription_id, callback}); | 48 subscriptions.push_back(Subscription{subscription_id, callback}); |
50 | 49 |
51 return current_id_; | 50 return current_id_; |
52 } | 51 } |
53 | 52 |
54 void MediaDevicesEventDispatcher::UnsubscribeDeviceChangeNotifications( | 53 void MediaDevicesEventDispatcher::UnsubscribeDeviceChangeNotifications( |
55 MediaDeviceType type, | 54 MediaDeviceType type, |
56 SubscriptionId subscription_id) { | 55 SubscriptionId subscription_id) { |
57 DCHECK(thread_checker_.CalledOnValidThread()); | 56 DCHECK(thread_checker_.CalledOnValidThread()); |
58 DCHECK(IsValidMediaDeviceType(type)); | 57 DCHECK(IsValidMediaDeviceType(type)); |
59 | 58 |
60 SubscriptionList& subscriptions = device_change_subscriptions_[type]; | 59 SubscriptionList& subscriptions = device_change_subscriptions_[type]; |
61 auto it = std::find_if(subscriptions.begin(), subscriptions.end(), | 60 auto it = std::find_if(subscriptions.begin(), subscriptions.end(), |
62 [subscription_id](const Subscription& subscription) { | 61 [subscription_id](const Subscription& subscription) { |
63 return subscription.first == subscription_id; | 62 return subscription.first == subscription_id; |
64 }); | 63 }); |
65 if (it == subscriptions.end()) | 64 if (it == subscriptions.end()) |
66 return; | 65 return; |
67 | 66 |
68 GetMediaDevicesDispatcher()->UnsubscribeDeviceChangeNotifications(type, | 67 GetMediaDevicesDispatcher()->UnsubscribeDeviceChangeNotifications(type, |
69 it->first); | 68 it->first); |
70 subscriptions.erase(it); | 69 subscriptions.erase(it); |
71 } | 70 } |
72 | 71 |
73 MediaDevicesEventDispatcher::SubscriptionIdList | 72 MediaDevicesEventDispatcher::SubscriptionIdList |
74 MediaDevicesEventDispatcher::SubscribeDeviceChangeNotifications( | 73 MediaDevicesEventDispatcher::SubscribeDeviceChangeNotifications( |
75 const url::Origin& security_origin, | |
76 const DevicesChangedCallback& callback) { | 74 const DevicesChangedCallback& callback) { |
77 SubscriptionIdList list; | 75 SubscriptionIdList list; |
78 SubscriptionId id; | 76 SubscriptionId id; |
79 id = SubscribeDeviceChangeNotifications(MEDIA_DEVICE_TYPE_AUDIO_INPUT, | 77 id = SubscribeDeviceChangeNotifications(MEDIA_DEVICE_TYPE_AUDIO_INPUT, |
80 security_origin, callback); | 78 callback); |
81 list.push_back(id); | 79 list.push_back(id); |
82 id = SubscribeDeviceChangeNotifications(MEDIA_DEVICE_TYPE_VIDEO_INPUT, | 80 id = SubscribeDeviceChangeNotifications(MEDIA_DEVICE_TYPE_VIDEO_INPUT, |
83 security_origin, callback); | 81 callback); |
84 list.push_back(id); | 82 list.push_back(id); |
85 id = SubscribeDeviceChangeNotifications(MEDIA_DEVICE_TYPE_AUDIO_OUTPUT, | 83 id = SubscribeDeviceChangeNotifications(MEDIA_DEVICE_TYPE_AUDIO_OUTPUT, |
86 security_origin, callback); | 84 callback); |
87 list.push_back(id); | 85 list.push_back(id); |
88 | 86 |
89 return list; | 87 return list; |
90 } | 88 } |
91 | 89 |
92 void MediaDevicesEventDispatcher::UnsubscribeDeviceChangeNotifications( | 90 void MediaDevicesEventDispatcher::UnsubscribeDeviceChangeNotifications( |
93 const SubscriptionIdList& subscription_ids) { | 91 const SubscriptionIdList& subscription_ids) { |
94 DCHECK_EQ(static_cast<size_t>(NUM_MEDIA_DEVICE_TYPES), | 92 DCHECK_EQ(static_cast<size_t>(NUM_MEDIA_DEVICE_TYPES), |
95 subscription_ids.size()); | 93 subscription_ids.size()); |
96 for (size_t i = 0; i < NUM_MEDIA_DEVICE_TYPES; ++i) | 94 for (size_t i = 0; i < NUM_MEDIA_DEVICE_TYPES; ++i) |
(...skipping 24 matching lines...) Expand all Loading... |
121 MediaDevicesEventDispatcher::GetMediaDevicesDispatcher() { | 119 MediaDevicesEventDispatcher::GetMediaDevicesDispatcher() { |
122 if (!media_devices_dispatcher_) { | 120 if (!media_devices_dispatcher_) { |
123 render_frame()->GetRemoteInterfaces()->GetInterface( | 121 render_frame()->GetRemoteInterfaces()->GetInterface( |
124 mojo::MakeRequest(&media_devices_dispatcher_)); | 122 mojo::MakeRequest(&media_devices_dispatcher_)); |
125 } | 123 } |
126 | 124 |
127 return media_devices_dispatcher_; | 125 return media_devices_dispatcher_; |
128 } | 126 } |
129 | 127 |
130 } // namespace content | 128 } // namespace content |
OLD | NEW |