Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(445)

Side by Side Diff: chrome/browser/media/media_capture_devices_dispatcher.h

Issue 1095393004: Refactor: Make MediaCaptureDevicesDispatcher have pluggable handlers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and address review comments of ps#2 Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
Sergey Ulanov 2015/06/01 23:39:18 You can forward-declare MediaAccessHandler. Don't
changbin 2015/06/02 14:20:09 Done.
18 #include "chrome/browser/media/permission_bubble_media_access_handler.h"
Sergey Ulanov 2015/06/01 23:39:18 Don't need this.
16 #include "content/public/browser/media_observer.h" 19 #include "content/public/browser/media_observer.h"
17 #include "content/public/browser/notification_observer.h"
18 #include "content/public/browser/notification_registrar.h"
19 #include "content/public/browser/web_contents_delegate.h" 20 #include "content/public/browser/web_contents_delegate.h"
20 #include "content/public/common/media_stream_request.h" 21 #include "content/public/common/media_stream_request.h"
21 22
22 class DesktopStreamsRegistry; 23 class DesktopStreamsRegistry;
23 class MediaStreamCaptureIndicator; 24 class MediaStreamCaptureIndicator;
24 class Profile; 25 class Profile;
25 26
26 namespace extensions { 27 namespace extensions {
27 class Extension; 28 class Extension;
28 } 29 }
29 30
30 namespace user_prefs { 31 namespace user_prefs {
31 class PrefRegistrySyncable; 32 class PrefRegistrySyncable;
32 } 33 }
33 34
34 // This singleton is used to receive updates about media events from the content 35 // This singleton is used to receive updates about media events from the content
35 // layer. 36 // layer.
36 class MediaCaptureDevicesDispatcher : public content::MediaObserver, 37 class MediaCaptureDevicesDispatcher : public content::MediaObserver {
37 public content::NotificationObserver {
38 public: 38 public:
39 class Observer { 39 class Observer {
40 public: 40 public:
41 // Handle an information update consisting of a up-to-date audio capture 41 // Handle an information update consisting of a up-to-date audio capture
42 // device lists. This happens when a microphone is plugged in or unplugged. 42 // device lists. This happens when a microphone is plugged in or unplugged.
43 virtual void OnUpdateAudioDevices( 43 virtual void OnUpdateAudioDevices(
44 const content::MediaStreamDevices& devices) {} 44 const content::MediaStreamDevices& devices) {}
45 45
46 // Handle an information update consisting of a up-to-date video capture 46 // Handle an information update consisting of a up-to-date video capture
47 // device lists. This happens when a camera is plugged in or unplugged. 47 // device lists. This happens when a camera is plugged in or unplugged.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 const content::MediaResponseCallback& callback, 84 const content::MediaResponseCallback& callback,
85 const extensions::Extension* extension); 85 const extensions::Extension* extension);
86 86
87 // Method called from WebCapturerDelegate implementations to check media 87 // Method called from WebCapturerDelegate implementations to check media
88 // access permission. Note that this does not query the user. 88 // access permission. Note that this does not query the user.
89 bool CheckMediaAccessPermission(content::WebContents* web_contents, 89 bool CheckMediaAccessPermission(content::WebContents* web_contents,
90 const GURL& security_origin, 90 const GURL& security_origin,
91 content::MediaStreamType type); 91 content::MediaStreamType type);
92 92
93 // Same as above but for an |extension|, which may not be NULL. 93 // Same as above but for an |extension|, which may not be NULL.
94 #if defined(ENABLE_EXTENSIONS)
95 bool CheckMediaAccessPermission(content::WebContents* web_contents, 94 bool CheckMediaAccessPermission(content::WebContents* web_contents,
96 const GURL& security_origin, 95 const GURL& security_origin,
97 content::MediaStreamType type, 96 content::MediaStreamType type,
98 const extensions::Extension* extension); 97 const extensions::Extension* extension);
99 #endif
100 98
101 // Helper to get the default devices which can be used by the media request. 99 // Helper to get the default devices which can be used by the media request.
102 // Uses the first available devices if the default devices are not available. 100 // Uses the first available devices if the default devices are not available.
103 // If the return list is empty, it means there is no available device on the 101 // If the return list is empty, it means there is no available device on the
104 // OS. 102 // OS.
105 // Called on the UI thread. 103 // Called on the UI thread.
106 void GetDefaultDevicesForProfile(Profile* profile, 104 void GetDefaultDevicesForProfile(Profile* profile,
107 bool audio, 105 bool audio,
108 bool video, 106 bool video,
109 content::MediaStreamDevices* devices); 107 content::MediaStreamDevices* devices);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 141
144 bool IsDesktopCaptureInProgress(); 142 bool IsDesktopCaptureInProgress();
145 143
146 // Only for testing. 144 // Only for testing.
147 void SetTestAudioCaptureDevices(const content::MediaStreamDevices& devices); 145 void SetTestAudioCaptureDevices(const content::MediaStreamDevices& devices);
148 void SetTestVideoCaptureDevices(const content::MediaStreamDevices& devices); 146 void SetTestVideoCaptureDevices(const content::MediaStreamDevices& devices);
149 147
150 private: 148 private:
151 friend struct DefaultSingletonTraits<MediaCaptureDevicesDispatcher>; 149 friend struct DefaultSingletonTraits<MediaCaptureDevicesDispatcher>;
152 150
153 struct PendingAccessRequest {
154 PendingAccessRequest(const content::MediaStreamRequest& request,
155 const content::MediaResponseCallback& callback);
156 ~PendingAccessRequest();
157
158 // TODO(gbillock): make the MediaStreamDevicesController owned by
159 // this object when we're using bubbles.
160 content::MediaStreamRequest request;
161 content::MediaResponseCallback callback;
162 };
163 typedef std::deque<PendingAccessRequest> RequestsQueue;
164 typedef std::map<content::WebContents*, RequestsQueue> RequestsQueues;
165
166 MediaCaptureDevicesDispatcher(); 151 MediaCaptureDevicesDispatcher();
167 ~MediaCaptureDevicesDispatcher() override; 152 ~MediaCaptureDevicesDispatcher() override;
168 153
169 // content::NotificationObserver implementation.
170 void Observe(int type,
171 const content::NotificationSource& source,
172 const content::NotificationDetails& details) override;
173
174 // Helpers for ProcessMediaAccessRequest().
175 void ProcessDesktopCaptureAccessRequest(
176 content::WebContents* web_contents,
177 const content::MediaStreamRequest& request,
178 const content::MediaResponseCallback& callback,
179 const extensions::Extension* extension);
180 void ProcessScreenCaptureAccessRequest(
181 content::WebContents* web_contents,
182 const content::MediaStreamRequest& request,
183 const content::MediaResponseCallback& callback,
184 const extensions::Extension* extension);
185 void ProcessTabCaptureAccessRequest(
186 content::WebContents* web_contents,
187 const content::MediaStreamRequest& request,
188 const content::MediaResponseCallback& callback,
189 const extensions::Extension* extension);
190 #if defined(ENABLE_EXTENSIONS)
191 void ProcessMediaAccessRequestFromPlatformAppOrExtension(
192 content::WebContents* web_contents,
193 const content::MediaStreamRequest& request,
194 const content::MediaResponseCallback& callback,
195 const extensions::Extension* extension);
196 #endif
197 void ProcessRegularMediaAccessRequest(
198 content::WebContents* web_contents,
199 const content::MediaStreamRequest& request,
200 const content::MediaResponseCallback& callback);
201 void ProcessQueuedAccessRequest(content::WebContents* web_contents);
202 void OnAccessRequestResponse(content::WebContents* web_contents,
203 const content::MediaStreamDevices& devices,
204 content::MediaStreamRequestResult result,
205 scoped_ptr<content::MediaStreamUI> ui);
206
207 // Called by the MediaObserver() functions, executed on UI thread. 154 // Called by the MediaObserver() functions, executed on UI thread.
208 void NotifyAudioDevicesChangedOnUIThread(); 155 void NotifyAudioDevicesChangedOnUIThread();
209 void NotifyVideoDevicesChangedOnUIThread(); 156 void NotifyVideoDevicesChangedOnUIThread();
210 void UpdateMediaRequestStateOnUIThread( 157 void UpdateMediaRequestStateOnUIThread(
211 int render_process_id, 158 int render_process_id,
212 int render_frame_id, 159 int render_frame_id,
213 int page_request_id, 160 int page_request_id,
214 const GURL& security_origin, 161 const GURL& security_origin,
215 content::MediaStreamType stream_type, 162 content::MediaStreamType stream_type,
216 content::MediaRequestState state); 163 content::MediaRequestState state);
217 void OnCreatingAudioStreamOnUIThread(int render_process_id, 164 void OnCreatingAudioStreamOnUIThread(int render_process_id,
218 int render_frame_id); 165 int render_frame_id);
219 166
220 // Only for testing, a list of cached audio capture devices. 167 // Only for testing, a list of cached audio capture devices.
221 content::MediaStreamDevices test_audio_devices_; 168 content::MediaStreamDevices test_audio_devices_;
222 169
223 // Only for testing, a list of cached video capture devices. 170 // Only for testing, a list of cached video capture devices.
224 content::MediaStreamDevices test_video_devices_; 171 content::MediaStreamDevices test_video_devices_;
225 172
226 // A list of observers for the device update notifications. 173 // A list of observers for the device update notifications.
227 ObserverList<Observer> observers_; 174 ObserverList<Observer> observers_;
228 175
229 // Flag used by unittests to disable device enumeration. 176 // Flag used by unittests to disable device enumeration.
230 bool is_device_enumeration_disabled_; 177 bool is_device_enumeration_disabled_;
231 178
232 RequestsQueues pending_requests_;
233
234 scoped_refptr<MediaStreamCaptureIndicator> media_stream_capture_indicator_; 179 scoped_refptr<MediaStreamCaptureIndicator> media_stream_capture_indicator_;
235 180
236 scoped_ptr<DesktopStreamsRegistry> desktop_streams_registry_; 181 scoped_ptr<DesktopStreamsRegistry> desktop_streams_registry_;
237 182
238 content::NotificationRegistrar notifications_registrar_; 183 // Handlers for processing media access requests.
239 184 ScopedVector<MediaAccessHandler> media_access_handlers_;
240 // Tracks MEDIA_DESKTOP_VIDEO_CAPTURE sessions which reach the
241 // MEDIA_REQUEST_STATE_DONE state. Sessions are remove when
242 // MEDIA_REQUEST_STATE_CLOSING is encountered.
243 struct DesktopCaptureSession {
244 int render_process_id;
245 int render_frame_id;
246 int page_request_id;
247 };
248 typedef std::list<DesktopCaptureSession> DesktopCaptureSessions;
249 DesktopCaptureSessions desktop_capture_sessions_;
250 185
251 DISALLOW_COPY_AND_ASSIGN(MediaCaptureDevicesDispatcher); 186 DISALLOW_COPY_AND_ASSIGN(MediaCaptureDevicesDispatcher);
252 }; 187 };
253 188
254 #endif // CHROME_BROWSER_MEDIA_MEDIA_CAPTURE_DEVICES_DISPATCHER_H_ 189 #endif // CHROME_BROWSER_MEDIA_MEDIA_CAPTURE_DEVICES_DISPATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698