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