Chromium Code Reviews| 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 <deque> | 8 #include <deque> |
| 9 #include <list> | 9 #include <list> |
| 10 #include <map> | 10 #include <map> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/scoped_vector.h" | |
| 14 #include "base/memory/singleton.h" | 15 #include "base/memory/singleton.h" |
| 15 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
| 17 #include "chrome/browser/media/media_access_handler.h" | |
| 18 #include "chrome/browser/media/permission_bubble_media_access_handler.h" | |
| 16 #include "content/public/browser/media_observer.h" | 19 #include "content/public/browser/media_observer.h" |
| 17 #include "content/public/browser/notification_observer.h" | 20 #include "content/public/browser/notification_observer.h" |
| 18 #include "content/public/browser/notification_registrar.h" | 21 #include "content/public/browser/notification_registrar.h" |
| 19 #include "content/public/browser/web_contents_delegate.h" | 22 #include "content/public/browser/web_contents_delegate.h" |
| 20 #include "content/public/common/media_stream_request.h" | 23 #include "content/public/common/media_stream_request.h" |
| 21 | 24 |
| 22 class DesktopStreamsRegistry; | 25 class DesktopStreamsRegistry; |
| 23 class MediaStreamCaptureIndicator; | 26 class MediaStreamCaptureIndicator; |
| 24 class Profile; | 27 class Profile; |
| 25 | 28 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 149 | 152 |
| 150 bool IsDesktopCaptureInProgress(); | 153 bool IsDesktopCaptureInProgress(); |
| 151 | 154 |
| 152 // Only for testing. | 155 // Only for testing. |
| 153 void SetTestAudioCaptureDevices(const content::MediaStreamDevices& devices); | 156 void SetTestAudioCaptureDevices(const content::MediaStreamDevices& devices); |
| 154 void SetTestVideoCaptureDevices(const content::MediaStreamDevices& devices); | 157 void SetTestVideoCaptureDevices(const content::MediaStreamDevices& devices); |
| 155 | 158 |
| 156 private: | 159 private: |
| 157 friend struct DefaultSingletonTraits<MediaCaptureDevicesDispatcher>; | 160 friend struct DefaultSingletonTraits<MediaCaptureDevicesDispatcher>; |
| 158 | 161 |
| 159 struct PendingAccessRequest { | |
| 160 PendingAccessRequest(const content::MediaStreamRequest& request, | |
| 161 const content::MediaResponseCallback& callback); | |
| 162 ~PendingAccessRequest(); | |
| 163 | |
| 164 // TODO(gbillock): make the MediaStreamDevicesController owned by | |
| 165 // this object when we're using bubbles. | |
| 166 content::MediaStreamRequest request; | |
| 167 content::MediaResponseCallback callback; | |
| 168 }; | |
| 169 typedef std::deque<PendingAccessRequest> RequestsQueue; | |
| 170 typedef std::map<content::WebContents*, RequestsQueue> RequestsQueues; | |
| 171 | |
| 172 MediaCaptureDevicesDispatcher(); | 162 MediaCaptureDevicesDispatcher(); |
| 173 ~MediaCaptureDevicesDispatcher() override; | 163 ~MediaCaptureDevicesDispatcher() override; |
| 174 | 164 |
| 175 // content::NotificationObserver implementation. | 165 // content::NotificationObserver implementation. |
| 176 void Observe(int type, | 166 void Observe(int type, |
| 177 const content::NotificationSource& source, | 167 const content::NotificationSource& source, |
| 178 const content::NotificationDetails& details) override; | 168 const content::NotificationDetails& details) override; |
| 179 | 169 |
| 180 // Helpers for ProcessMediaAccessRequest(). | |
| 181 void ProcessDesktopCaptureAccessRequest( | |
| 182 content::WebContents* web_contents, | |
| 183 const content::MediaStreamRequest& request, | |
| 184 const content::MediaResponseCallback& callback, | |
| 185 const extensions::Extension* extension); | |
| 186 void ProcessScreenCaptureAccessRequest( | |
| 187 content::WebContents* web_contents, | |
| 188 const content::MediaStreamRequest& request, | |
| 189 const content::MediaResponseCallback& callback, | |
| 190 const extensions::Extension* extension); | |
| 191 void ProcessTabCaptureAccessRequest( | |
| 192 content::WebContents* web_contents, | |
| 193 const content::MediaStreamRequest& request, | |
| 194 const content::MediaResponseCallback& callback, | |
| 195 const extensions::Extension* extension); | |
| 196 #if defined(ENABLE_EXTENSIONS) | |
| 197 void ProcessMediaAccessRequestFromPlatformAppOrExtension( | |
| 198 content::WebContents* web_contents, | |
| 199 const content::MediaStreamRequest& request, | |
| 200 const content::MediaResponseCallback& callback, | |
| 201 const extensions::Extension* extension); | |
| 202 #endif | |
| 203 void ProcessRegularMediaAccessRequest( | |
| 204 content::WebContents* web_contents, | |
| 205 const content::MediaStreamRequest& request, | |
| 206 const content::MediaResponseCallback& callback); | |
| 207 void ProcessQueuedAccessRequest(content::WebContents* web_contents); | |
| 208 void OnAccessRequestResponse(content::WebContents* web_contents, | |
| 209 const content::MediaStreamDevices& devices, | |
| 210 content::MediaStreamRequestResult result, | |
| 211 scoped_ptr<content::MediaStreamUI> ui); | |
| 212 | |
| 213 // Called by the MediaObserver() functions, executed on UI thread. | 170 // Called by the MediaObserver() functions, executed on UI thread. |
| 214 void NotifyAudioDevicesChangedOnUIThread(); | 171 void NotifyAudioDevicesChangedOnUIThread(); |
| 215 void NotifyVideoDevicesChangedOnUIThread(); | 172 void NotifyVideoDevicesChangedOnUIThread(); |
| 216 void UpdateMediaRequestStateOnUIThread( | 173 void UpdateMediaRequestStateOnUIThread( |
| 217 int render_process_id, | 174 int render_process_id, |
| 218 int render_frame_id, | 175 int render_frame_id, |
| 219 int page_request_id, | 176 int page_request_id, |
| 220 const GURL& security_origin, | 177 const GURL& security_origin, |
| 221 content::MediaStreamType stream_type, | 178 content::MediaStreamType stream_type, |
| 222 content::MediaRequestState state); | 179 content::MediaRequestState state); |
| 223 void OnCreatingAudioStreamOnUIThread(int render_process_id, | 180 void OnCreatingAudioStreamOnUIThread(int render_process_id, |
| 224 int render_frame_id); | 181 int render_frame_id); |
| 225 | 182 |
| 226 // Only for testing, a list of cached audio capture devices. | 183 // Only for testing, a list of cached audio capture devices. |
| 227 content::MediaStreamDevices test_audio_devices_; | 184 content::MediaStreamDevices test_audio_devices_; |
| 228 | 185 |
| 229 // Only for testing, a list of cached video capture devices. | 186 // Only for testing, a list of cached video capture devices. |
| 230 content::MediaStreamDevices test_video_devices_; | 187 content::MediaStreamDevices test_video_devices_; |
| 231 | 188 |
| 232 // A list of observers for the device update notifications. | 189 // A list of observers for the device update notifications. |
| 233 ObserverList<Observer> observers_; | 190 ObserverList<Observer> observers_; |
| 234 | 191 |
| 235 // Flag used by unittests to disable device enumeration. | 192 // Flag used by unittests to disable device enumeration. |
| 236 bool is_device_enumeration_disabled_; | 193 bool is_device_enumeration_disabled_; |
| 237 | 194 |
| 238 RequestsQueues pending_requests_; | 195 RequestsQueues pending_requests_; |
|
Sergey Ulanov
2015/05/07 01:05:48
Move this to PermissionBubbleMediaAccessHandler
changbin
2015/05/22 05:10:58
Done.
| |
| 239 | 196 |
| 240 scoped_refptr<MediaStreamCaptureIndicator> media_stream_capture_indicator_; | 197 scoped_refptr<MediaStreamCaptureIndicator> media_stream_capture_indicator_; |
| 241 | 198 |
| 242 scoped_ptr<DesktopStreamsRegistry> desktop_streams_registry_; | 199 scoped_ptr<DesktopStreamsRegistry> desktop_streams_registry_; |
| 243 | 200 |
| 244 content::NotificationRegistrar notifications_registrar_; | 201 content::NotificationRegistrar notifications_registrar_; |
| 245 | 202 |
| 246 // Tracks MEDIA_DESKTOP_VIDEO_CAPTURE sessions which reach the | 203 // Tracks MEDIA_DESKTOP_VIDEO_CAPTURE sessions which reach the |
| 247 // MEDIA_REQUEST_STATE_DONE state. Sessions are remove when | 204 // MEDIA_REQUEST_STATE_DONE state. Sessions are remove when |
| 248 // MEDIA_REQUEST_STATE_CLOSING is encountered. | 205 // MEDIA_REQUEST_STATE_CLOSING is encountered. |
| 249 struct DesktopCaptureSession { | 206 struct DesktopCaptureSession { |
| 250 int render_process_id; | 207 int render_process_id; |
| 251 int render_frame_id; | 208 int render_frame_id; |
| 252 int page_request_id; | 209 int page_request_id; |
| 253 }; | 210 }; |
| 254 typedef std::list<DesktopCaptureSession> DesktopCaptureSessions; | 211 typedef std::list<DesktopCaptureSession> DesktopCaptureSessions; |
| 255 DesktopCaptureSessions desktop_capture_sessions_; | 212 DesktopCaptureSessions desktop_capture_sessions_; |
| 256 | 213 |
| 214 // Handlers for processing media access requests. | |
| 215 ScopedVector<MediaAccessHandler> media_access_handlers_; | |
| 216 | |
| 257 DISALLOW_COPY_AND_ASSIGN(MediaCaptureDevicesDispatcher); | 217 DISALLOW_COPY_AND_ASSIGN(MediaCaptureDevicesDispatcher); |
| 258 }; | 218 }; |
| 259 | 219 |
| 260 #endif // CHROME_BROWSER_MEDIA_MEDIA_CAPTURE_DEVICES_DISPATCHER_H_ | 220 #endif // CHROME_BROWSER_MEDIA_MEDIA_CAPTURE_DEVICES_DISPATCHER_H_ |
| OLD | NEW |