OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROME_BROWSER_MEDIA_MEDIA_CAPTURE_DEVICES_DISPATCHER_H_ | 5 #ifndef CHROME_BROWSER_MEDIA_MEDIA_CAPTURE_DEVICES_DISPATCHER_H_ |
6 #define CHROME_BROWSER_MEDIA_MEDIA_CAPTURE_DEVICES_DISPATCHER_H_ | 6 #define CHROME_BROWSER_MEDIA_MEDIA_CAPTURE_DEVICES_DISPATCHER_H_ |
7 | 7 |
8 #include <queue> | |
9 | |
8 #include "base/callback.h" | 10 #include "base/callback.h" |
9 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
10 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
11 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
12 #include "content/public/browser/media_observer.h" | 14 #include "content/public/browser/media_observer.h" |
15 #include "content/public/browser/notification_observer.h" | |
16 #include "content/public/browser/notification_registrar.h" | |
13 #include "content/public/browser/web_contents_delegate.h" | 17 #include "content/public/browser/web_contents_delegate.h" |
14 #include "content/public/common/media_stream_request.h" | 18 #include "content/public/common/media_stream_request.h" |
15 | 19 |
16 namespace extensions { | 20 namespace extensions { |
17 class Extension; | 21 class Extension; |
18 } | 22 } |
19 | 23 |
20 class AudioStreamIndicator; | 24 class AudioStreamIndicator; |
21 class MediaStreamCaptureIndicator; | 25 class MediaStreamCaptureIndicator; |
22 class PrefRegistrySyncable; | 26 class PrefRegistrySyncable; |
23 class Profile; | 27 class Profile; |
24 | 28 |
25 // This singleton is used to receive updates about media events from the content | 29 // This singleton is used to receive updates about media events from the content |
26 // layer. | 30 // layer. |
27 class MediaCaptureDevicesDispatcher : public content::MediaObserver { | 31 class MediaCaptureDevicesDispatcher : public content::MediaObserver, |
32 public content::NotificationObserver { | |
28 public: | 33 public: |
29 class Observer { | 34 class Observer { |
30 public: | 35 public: |
31 // Handle an information update consisting of a up-to-date audio capture | 36 // Handle an information update consisting of a up-to-date audio capture |
32 // device lists. This happens when a microphone is plugged in or unplugged. | 37 // device lists. This happens when a microphone is plugged in or unplugged. |
33 virtual void OnUpdateAudioDevices( | 38 virtual void OnUpdateAudioDevices( |
34 const content::MediaStreamDevices& devices) {} | 39 const content::MediaStreamDevices& devices) {} |
35 | 40 |
36 // Handle an information update consisting of a up-to-date video capture | 41 // Handle an information update consisting of a up-to-date video capture |
37 // device lists. This happens when a camera is plugged in or unplugged. | 42 // device lists. This happens when a camera is plugged in or unplugged. |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 int stream_id, | 109 int stream_id, |
105 bool is_playing_and_audible) OVERRIDE; | 110 bool is_playing_and_audible) OVERRIDE; |
106 | 111 |
107 scoped_refptr<MediaStreamCaptureIndicator> GetMediaStreamCaptureIndicator(); | 112 scoped_refptr<MediaStreamCaptureIndicator> GetMediaStreamCaptureIndicator(); |
108 | 113 |
109 scoped_refptr<AudioStreamIndicator> GetAudioStreamIndicator(); | 114 scoped_refptr<AudioStreamIndicator> GetAudioStreamIndicator(); |
110 | 115 |
111 private: | 116 private: |
112 friend struct DefaultSingletonTraits<MediaCaptureDevicesDispatcher>; | 117 friend struct DefaultSingletonTraits<MediaCaptureDevicesDispatcher>; |
113 | 118 |
119 struct PendingAccessRequest { | |
120 PendingAccessRequest(content::MediaStreamRequest request, | |
tommi (sloooow) - chröme
2013/04/23 11:20:47
const &
Sergey Ulanov
2013/04/29 18:17:56
Done.
| |
121 content::MediaResponseCallback callback); | |
tommi (sloooow) - chröme
2013/04/23 11:20:47
const &
Sergey Ulanov
2013/04/29 18:17:56
Done.
| |
122 ~PendingAccessRequest(); | |
123 | |
124 content::MediaStreamRequest request; | |
125 content::MediaResponseCallback callback; | |
126 }; | |
127 typedef std::queue<PendingAccessRequest> RequestsQueue; | |
128 | |
114 MediaCaptureDevicesDispatcher(); | 129 MediaCaptureDevicesDispatcher(); |
115 virtual ~MediaCaptureDevicesDispatcher(); | 130 virtual ~MediaCaptureDevicesDispatcher(); |
116 | 131 |
132 // content::NotificationObserver implementation. | |
133 virtual void Observe(int type, | |
134 const content::NotificationSource& source, | |
135 const content::NotificationDetails& details) OVERRIDE; | |
136 | |
117 // Helpers for ProcessMediaAccessRequest(). | 137 // Helpers for ProcessMediaAccessRequest(). |
118 void ProcessScreenCaptureAccessRequest( | 138 void ProcessScreenCaptureAccessRequest( |
119 content::WebContents* web_contents, | 139 content::WebContents* web_contents, |
120 const content::MediaStreamRequest& request, | 140 const content::MediaStreamRequest& request, |
121 const content::MediaResponseCallback& callback); | 141 const content::MediaResponseCallback& callback); |
122 void ProcessMediaAccessRequestFromExtension( | 142 void ProcessMediaAccessRequestFromExtension( |
123 content::WebContents* web_contents, | 143 content::WebContents* web_contents, |
124 const content::MediaStreamRequest& request, | 144 const content::MediaStreamRequest& request, |
125 const content::MediaResponseCallback& callback, | 145 const content::MediaResponseCallback& callback, |
126 const extensions::Extension* extension); | 146 const extensions::Extension* extension); |
147 void ProcessRegularMediaAccessRequest( | |
148 content::WebContents* web_contents, | |
149 const content::MediaStreamRequest& request, | |
150 const content::MediaResponseCallback& callback); | |
151 void ProcessQueuedAccessRequest(content::WebContents* web_contents, | |
152 PendingAccessRequest& request); | |
153 void OnAccessRequestResponse(content::WebContents* web_contents, | |
154 const content::MediaStreamDevices& devices, | |
155 scoped_ptr<content::MediaStreamUI> ui); | |
127 | 156 |
128 // Called by the MediaObserver() functions, executed on UI thread. | 157 // Called by the MediaObserver() functions, executed on UI thread. |
129 void UpdateAudioDevicesOnUIThread(const content::MediaStreamDevices& devices); | 158 void UpdateAudioDevicesOnUIThread(const content::MediaStreamDevices& devices); |
130 void UpdateVideoDevicesOnUIThread(const content::MediaStreamDevices& devices); | 159 void UpdateVideoDevicesOnUIThread(const content::MediaStreamDevices& devices); |
131 void UpdateMediaRequestStateOnUIThread( | 160 void UpdateMediaRequestStateOnUIThread( |
132 int render_process_id, | 161 int render_process_id, |
133 int render_view_id, | 162 int render_view_id, |
134 const content::MediaStreamDevice& device, | 163 const content::MediaStreamDevice& device, |
135 content::MediaRequestState state); | 164 content::MediaRequestState state); |
136 | 165 |
137 // A list of cached audio capture devices. | 166 // A list of cached audio capture devices. |
138 content::MediaStreamDevices audio_devices_; | 167 content::MediaStreamDevices audio_devices_; |
139 | 168 |
140 // A list of cached video capture devices. | 169 // A list of cached video capture devices. |
141 content::MediaStreamDevices video_devices_; | 170 content::MediaStreamDevices video_devices_; |
142 | 171 |
143 // A list of observers for the device update notifications. | 172 // A list of observers for the device update notifications. |
144 ObserverList<Observer> observers_; | 173 ObserverList<Observer> observers_; |
145 | 174 |
146 // Flag to indicate if device enumeration has been done/doing. | 175 // Flag to indicate if device enumeration has been done/doing. |
147 // Only accessed on UI thread. | 176 // Only accessed on UI thread. |
148 bool devices_enumerated_; | 177 bool devices_enumerated_; |
149 | 178 |
179 std::map<content::WebContents*, RequestsQueue> pending_requests_; | |
180 | |
150 scoped_refptr<MediaStreamCaptureIndicator> media_stream_capture_indicator_; | 181 scoped_refptr<MediaStreamCaptureIndicator> media_stream_capture_indicator_; |
151 | 182 |
152 scoped_refptr<AudioStreamIndicator> audio_stream_indicator_; | 183 scoped_refptr<AudioStreamIndicator> audio_stream_indicator_; |
184 | |
185 content::NotificationRegistrar notifications_registrar_; | |
186 | |
187 DISALLOW_COPY_AND_ASSIGN(MediaCaptureDevicesDispatcher); | |
153 }; | 188 }; |
154 | 189 |
155 #endif // CHROME_BROWSER_MEDIA_MEDIA_CAPTURE_DEVICES_DISPATCHER_H_ | 190 #endif // CHROME_BROWSER_MEDIA_MEDIA_CAPTURE_DEVICES_DISPATCHER_H_ |
OLD | NEW |