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

Side by Side Diff: content/browser/renderer_host/media/media_stream_manager.h

Issue 34393006: Refactor MediaStreamManager to never output real device id. It now always output sourceId in the fo… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix screen capture. Created 7 years, 1 month 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 | Annotate | Revision Log
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 // MediaStreamManager is used to open/enumerate media capture devices (video 5 // MediaStreamManager is used to open/enumerate media capture devices (video
6 // supported now). Call flow: 6 // supported now). Call flow:
7 // 1. GenerateStream is called when a render process wants to use a capture 7 // 1. GenerateStream is called when a render process wants to use a capture
8 // device. 8 // device.
9 // 2. MediaStreamManager will ask MediaStreamUIController for permission to 9 // 2. MediaStreamManager will ask MediaStreamUIController for permission to
10 // use devices and for which device to use. 10 // use devices and for which device to use.
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 MediaStreamType type, 134 MediaStreamType type,
135 const GURL& security_origin); 135 const GURL& security_origin);
136 136
137 // Implements MediaStreamProviderListener. 137 // Implements MediaStreamProviderListener.
138 virtual void Opened(MediaStreamType stream_type, 138 virtual void Opened(MediaStreamType stream_type,
139 int capture_session_id) OVERRIDE; 139 int capture_session_id) OVERRIDE;
140 virtual void Closed(MediaStreamType stream_type, 140 virtual void Closed(MediaStreamType stream_type,
141 int capture_session_id) OVERRIDE; 141 int capture_session_id) OVERRIDE;
142 virtual void DevicesEnumerated(MediaStreamType stream_type, 142 virtual void DevicesEnumerated(MediaStreamType stream_type,
143 const StreamDeviceInfoArray& devices) OVERRIDE; 143 const StreamDeviceInfoArray& devices) OVERRIDE;
144 virtual void Error(MediaStreamType stream_type,
145 int capture_session_id,
146 MediaStreamProviderError error) OVERRIDE;
147 144
148 // Implements base::SystemMonitor::DevicesChangedObserver. 145 // Implements base::SystemMonitor::DevicesChangedObserver.
149 virtual void OnDevicesChanged( 146 virtual void OnDevicesChanged(
150 base::SystemMonitor::DeviceType device_type) OVERRIDE; 147 base::SystemMonitor::DeviceType device_type) OVERRIDE;
151 148
152 // Used by unit test to make sure fake devices are used instead of a real 149 // Used by unit test to make sure fake devices are used instead of a real
153 // devices, which is needed for server based testing or certain tests (which 150 // devices, which is needed for server based testing or certain tests (which
154 // can pass --use-fake-device-for-media-stream). 151 // can pass --use-fake-device-for-media-stream).
155 void UseFakeDevice(); 152 void UseFakeDevice();
156 153
157 // Called by the tests to specify a fake UI that should be used for next 154 // Called by the tests to specify a fake UI that should be used for next
158 // generated stream (or when using --use-fake-ui-for-media-stream). 155 // generated stream (or when using --use-fake-ui-for-media-stream).
159 void UseFakeUI(scoped_ptr<FakeMediaStreamUIProxy> fake_ui); 156 void UseFakeUI(scoped_ptr<FakeMediaStreamUIProxy> fake_ui);
160 157
158 // Used by test to find a StreamDeviceInfo that currently has been
159 // requested and match the input arguments. If such a StreamDeviceInfo is
160 // found it is copied to |device_info|.
161 const StreamDeviceInfo* FindRequestedDeviceInfoForTest(
162 const std::string& source_id,
163 int render_process_id,
164 int render_view_id,
165 MediaStreamRequestType type);
166
161 // This object gets deleted on the UI thread after the IO thread has been 167 // This object gets deleted on the UI thread after the IO thread has been
162 // destroyed. So we need to know when IO thread is being destroyed so that 168 // destroyed. So we need to know when IO thread is being destroyed so that
163 // we can delete VideoCaptureManager and AudioInputDeviceManager. 169 // we can delete VideoCaptureManager and AudioInputDeviceManager. Normally
164 // We also must call this function explicitly in tests which use 170 // this is handled by
165 // TestBrowserThreadBundle, because the notification happens too late in that 171 // base::MessageLoop::DestructionObserver::WillDestroyCurrentMessageLoop.
166 // case (see http://crbug.com/247525#c14). 172 // But for some tests which use TestBrowserThreadBundle, we need to call
167 virtual void WillDestroyCurrentMessageLoop() OVERRIDE; 173 // WillDestroyCurrentMessageLoop explicitly because the notification happens
174 // too late. (see http://crbug.com/247525#c14).
175 void WillDestroyCurrentMessageLoopForTest();
tommi (sloooow) - chröme 2013/10/29 17:21:17 Prefer to not have this here. Also, the first par
168 176
169 protected: 177 protected:
170 // Used for testing. 178 // Used for testing.
171 MediaStreamManager(); 179 MediaStreamManager();
172 180
173 private: 181 private:
174 friend class MockMediaStreamDispatcherHost;
175
176 // Contains all data needed to keep track of requests. 182 // Contains all data needed to keep track of requests.
177 class DeviceRequest; 183 class DeviceRequest;
178 184
179 // Cache enumerated device list. 185 // Cache enumerated device list.
180 struct EnumerationCache { 186 struct EnumerationCache {
181 EnumerationCache(); 187 EnumerationCache();
182 ~EnumerationCache(); 188 ~EnumerationCache();
183 189
184 bool valid; 190 bool valid;
185 StreamDeviceInfoArray devices; 191 StreamDeviceInfoArray devices;
186 }; 192 };
187 193
188 typedef std::map<std::string, DeviceRequest*> DeviceRequests; 194 typedef std::map<std::string, DeviceRequest*> DeviceRequests;
189 195
196 // This object gets deleted on the UI thread after the IO thread has been
197 // destroyed. So we need to know when the IO thread is being destroyed so
198 // that we can delete VideoCaptureManager and AudioInputDeviceManager.
199 virtual void WillDestroyCurrentMessageLoop() OVERRIDE;
200
190 // Initializes the device managers on IO thread. Auto-starts the device 201 // Initializes the device managers on IO thread. Auto-starts the device
191 // thread and registers this as a listener with the device managers. 202 // thread and registers this as a listener with the device managers.
192 void InitializeDeviceManagersOnIOThread(); 203 void InitializeDeviceManagersOnIOThread();
193 204
194 // Helper for sending up-to-date device lists to media observer when a 205 // Helper for sending up-to-date device lists to media observer when a
195 // capture device is plugged in or unplugged. 206 // capture device is plugged in or unplugged.
196 void NotifyDevicesChanged(MediaStreamType stream_type, 207 void NotifyDevicesChanged(MediaStreamType stream_type,
197 const StreamDeviceInfoArray& devices); 208 const StreamDeviceInfoArray& devices);
198 209
199
200 void HandleAccessRequestResponse(const std::string& label, 210 void HandleAccessRequestResponse(const std::string& label,
201 const MediaStreamDevices& devices); 211 const MediaStreamDevices& devices);
202 void StopStreamFromUI(const std::string& label); 212 void StopStreamFromUI(const std::string& label);
203 213
214 void DoCancelRequest(const std::string& label);
215
216 void DoStopStreamDevice(int render_process_id,
217 int render_view_id,
218 const std::string& device_id);
219
220 void DoEnumerateDevices(const std::string& label);
221
204 // Helpers. 222 // Helpers.
205 // Checks if all devices that was requested in the request identififed by 223 // Checks if all devices that was requested in the request identififed by
206 // |label| has been opened and set the request state accordingly. 224 // |label| has been opened and set the request state accordingly.
207 void HandleRequestDone(const std::string& label, 225 void HandleRequestDone(const std::string& label,
208 DeviceRequest* request); 226 DeviceRequest* request);
209 void StopDevice(const StreamDeviceInfo& device_info); 227 void StopDevice(const StreamDeviceInfo& device_info);
210 // Returns true if a request for devices has been completed and the devices 228 // Returns true if a request for devices has been completed and the devices
211 // has either been opened or an error has occurred. 229 // has either been opened or an error has occurred.
212 bool RequestDone(const DeviceRequest& request) const; 230 bool RequestDone(const DeviceRequest& request) const;
213 MediaStreamProvider* GetDeviceManager(MediaStreamType stream_type); 231 MediaStreamProvider* GetDeviceManager(MediaStreamType stream_type);
214 void StartEnumeration(DeviceRequest* request); 232 void StartEnumeration(DeviceRequest* request);
215 std::string AddRequest(DeviceRequest* request); 233 std::string AddRequest(DeviceRequest* request);
216 void RemoveRequest(DeviceRequests::iterator it); 234 DeviceRequest* FindRequest(const std::string& label);
235 void DeleteRequest(const std::string& label);
217 void ClearEnumerationCache(EnumerationCache* cache); 236 void ClearEnumerationCache(EnumerationCache* cache);
218 void PostRequestToUI(const std::string& label); 237 void PostRequestToUI(const std::string& label);
219 void HandleRequest(const std::string& label); 238 void HandleRequest(const std::string& label);
239 bool SetupTabCaptureRequest(DeviceRequest* request);
240 bool SetupScreenCaptureRequest(DeviceRequest* request);
220 // Returns true if a device with |device_id| has already been requested by 241 // Returns true if a device with |device_id| has already been requested by
221 // |render_process_id| and |render_view_id| of type |type|. If it has been 242 // |render_process_id| and |render_view_id| of type |type|. If it has been
222 // requested, |device_info| contain information about the the device. 243 // requested, |device_info| contain information about the device.
223 bool FindExistingRequestedDeviceInfo(int render_process_id, 244 bool FindExistingRequestedDeviceInfo(int render_process_id,
224 int render_view_id, 245 int render_view_id,
246 const GURL& security_origin,
225 MediaStreamRequestType type, 247 MediaStreamRequestType type,
226 const std::string& device_id, 248 const std::string& device_id,
249 MediaStreamType device_type,
227 StreamDeviceInfo* device_info, 250 StreamDeviceInfo* device_info,
228 MediaRequestState* request_state) const; 251 MediaRequestState* request_state) const;
229 252
230 // Sends cached device list to a client corresponding to the request 253 void FinalizeGenerateStream(const std::string& label,
231 // identified by |label|. 254 DeviceRequest* request);
232 void SendCachedDeviceList(EnumerationCache* cache, const std::string& label); 255 void FinalizeRequestFailed(const std::string& label,
256 DeviceRequest* request);
257 void FinalizeOpenDevice(const std::string& label,
258 DeviceRequest* request);
259 void FinalizeMediaAccessRequest(const std::string& label,
260 DeviceRequest* request,
261 const MediaStreamDevices& devices);
262 void FinalizeEnumerateDevices(const std::string& label,
263 DeviceRequest* request);
233 264
234 // Helpers to start and stop monitoring devices. 265 // Helpers to start and stop monitoring devices.
235 void StartMonitoring(); 266 void StartMonitoring();
236 void StopMonitoring(); 267 void StopMonitoring();
237 268
238 // Finds and returns the raw device id corresponding to the given 269 bool TranslateRequestedSourceIdToDeviceId(MediaStreamRequest* request);
239 // |device_guid|. Returns true if there was a raw device id that matched the 270 // Finds and returns the device id corresponding to the given
240 // given |device_guid|, false if nothing matched it. 271 // |source_id|. Returns true if there was a raw device id that matched the
241 bool TranslateGUIDToRawId( 272 // given |source_id|, false if nothing matched it.
273 bool TranslateSourceIdToDeviceId(
242 MediaStreamType stream_type, 274 MediaStreamType stream_type,
243 const GURL& security_origin, 275 const GURL& security_origin,
244 const std::string& device_guid, 276 const std::string& source_id,
245 std::string* raw_device_id); 277 std::string* device_id);
246 278
247 // Device thread shared by VideoCaptureManager and AudioInputDeviceManager. 279 // Device thread shared by VideoCaptureManager and AudioInputDeviceManager.
248 scoped_ptr<base::Thread> device_thread_; 280 scoped_ptr<base::Thread> device_thread_;
249 281
250 media::AudioManager* const audio_manager_; // not owned 282 media::AudioManager* const audio_manager_; // not owned
251 scoped_refptr<AudioInputDeviceManager> audio_input_device_manager_; 283 scoped_refptr<AudioInputDeviceManager> audio_input_device_manager_;
252 scoped_refptr<VideoCaptureManager> video_capture_manager_; 284 scoped_refptr<VideoCaptureManager> video_capture_manager_;
253 285
254 // Indicator of device monitoring state. 286 // Indicator of device monitoring state.
255 bool monitoring_started_; 287 bool monitoring_started_;
(...skipping 21 matching lines...) Expand all
277 309
278 bool use_fake_ui_; 310 bool use_fake_ui_;
279 scoped_ptr<FakeMediaStreamUIProxy> fake_ui_; 311 scoped_ptr<FakeMediaStreamUIProxy> fake_ui_;
280 312
281 DISALLOW_COPY_AND_ASSIGN(MediaStreamManager); 313 DISALLOW_COPY_AND_ASSIGN(MediaStreamManager);
282 }; 314 };
283 315
284 } // namespace content 316 } // namespace content
285 317
286 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_ 318 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698