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

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: Rebased to latest code base. 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
173 // WillDestroyCurrentMessageLoop explicitly because the notification happens
174 // too late. (see http://crbug.com/247525#c14).
167 virtual void WillDestroyCurrentMessageLoop() OVERRIDE; 175 virtual void WillDestroyCurrentMessageLoop() OVERRIDE;
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
190 // Initializes the device managers on IO thread. Auto-starts the device 196 // Initializes the device managers on IO thread. Auto-starts the device
191 // thread and registers this as a listener with the device managers. 197 // thread and registers this as a listener with the device managers.
192 void InitializeDeviceManagersOnIOThread(); 198 void InitializeDeviceManagersOnIOThread();
193 199
194 // Helper for sending up-to-date device lists to media observer when a 200 // Helper for sending up-to-date device lists to media observer when a
195 // capture device is plugged in or unplugged. 201 // capture device is plugged in or unplugged.
196 void NotifyDevicesChanged(MediaStreamType stream_type, 202 void NotifyDevicesChanged(MediaStreamType stream_type,
197 const StreamDeviceInfoArray& devices); 203 const StreamDeviceInfoArray& devices);
198 204
199
200 void HandleAccessRequestResponse(const std::string& label, 205 void HandleAccessRequestResponse(const std::string& label,
201 const MediaStreamDevices& devices); 206 const MediaStreamDevices& devices);
202 void StopStreamFromUI(const std::string& label); 207 void StopStreamFromUI(const std::string& label);
203 208
209 void DoCancelRequest(const std::string& label);
210
211 void DoStopStreamDevice(int render_process_id,
212 int render_view_id,
213 const std::string& device_id);
214
215 void DoEnumerateDevices(const std::string& label);
216
204 // Helpers. 217 // Helpers.
205 // Checks if all devices that was requested in the request identififed by 218 // Checks if all devices that was requested in the request identififed by
206 // |label| has been opened and set the request state accordingly. 219 // |label| has been opened and set the request state accordingly.
207 void HandleRequestDone(const std::string& label, 220 void HandleRequestDone(const std::string& label,
208 DeviceRequest* request); 221 DeviceRequest* request);
209 void StopDevice(const StreamDeviceInfo& device_info); 222 void StopDevice(const StreamDeviceInfo& device_info);
210 // Returns true if a request for devices has been completed and the devices 223 // Returns true if a request for devices has been completed and the devices
211 // has either been opened or an error has occurred. 224 // has either been opened or an error has occurred.
212 bool RequestDone(const DeviceRequest& request) const; 225 bool RequestDone(const DeviceRequest& request) const;
213 MediaStreamProvider* GetDeviceManager(MediaStreamType stream_type); 226 MediaStreamProvider* GetDeviceManager(MediaStreamType stream_type);
214 void StartEnumeration(DeviceRequest* request); 227 void StartEnumeration(DeviceRequest* request);
215 std::string AddRequest(DeviceRequest* request); 228 std::string AddRequest(DeviceRequest* request);
216 void RemoveRequest(DeviceRequests::iterator it); 229 DeviceRequest* FindRequest(const std::string& label);
230 void DeleteRequest(const std::string& label);
217 void ClearEnumerationCache(EnumerationCache* cache); 231 void ClearEnumerationCache(EnumerationCache* cache);
218 void PostRequestToUI(const std::string& label); 232 void PostRequestToUI(const std::string& label);
219 void HandleRequest(const std::string& label); 233 void HandleRequest(const std::string& label);
234 bool SetupTabCaptureRequest(DeviceRequest* request);
235 bool SetupScreenCaptureRequest(DeviceRequest* request);
220 // Returns true if a device with |device_id| has already been requested by 236 // 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 237 // |render_process_id| and |render_view_id| of type |type|. If it has been
222 // requested, |device_info| contain information about the the device. 238 // requested, |device_info| contain information about the device.
223 bool FindExistingRequestedDeviceInfo(int render_process_id, 239 bool FindExistingRequestedDeviceInfo(int render_process_id,
224 int render_view_id, 240 int render_view_id,
241 const GURL& security_origin,
225 MediaStreamRequestType type, 242 MediaStreamRequestType type,
226 const std::string& device_id, 243 const std::string& device_id,
244 MediaStreamType device_type,
227 StreamDeviceInfo* device_info, 245 StreamDeviceInfo* device_info,
228 MediaRequestState* request_state) const; 246 MediaRequestState* request_state) const;
229 247
230 // Sends cached device list to a client corresponding to the request 248 void FinalizeGenerateStream(const std::string& label,
231 // identified by |label|. 249 DeviceRequest* request);
232 void SendCachedDeviceList(EnumerationCache* cache, const std::string& label); 250 void FinalizeRequestFailed(const std::string& label,
251 DeviceRequest* request);
252 void FinalizeOpenDevice(const std::string& label,
253 DeviceRequest* request);
254 void FinalizeMediaAccessRequest(const std::string& label,
255 DeviceRequest* request,
256 const MediaStreamDevices& devices);
257 void FinalizeEnumerateDevices(const std::string& label,
258 DeviceRequest* request);
233 259
234 // Helpers to start and stop monitoring devices. 260 // Helpers to start and stop monitoring devices.
235 void StartMonitoring(); 261 void StartMonitoring();
236 void StopMonitoring(); 262 void StopMonitoring();
237 263
238 // Finds and returns the raw device id corresponding to the given 264 bool TranslateRequestedSourceIdToDeviceId(MediaStreamRequest* request);
239 // |device_guid|. Returns true if there was a raw device id that matched the 265 void TranslateDeviceIdToSourceId(const MediaStreamRequest& request,
240 // given |device_guid|, false if nothing matched it. 266 MediaStreamDevice* device);
241 bool TranslateGUIDToRawId( 267
268 // Finds and returns the device id corresponding to the given
269 // |source_id|. Returns true if there was a raw device id that matched the
270 // given |source_id|, false if nothing matched it.
271 bool TranslateSourceIdToDeviceId(
242 MediaStreamType stream_type, 272 MediaStreamType stream_type,
243 const GURL& security_origin, 273 const GURL& security_origin,
244 const std::string& device_guid, 274 const std::string& source_id,
245 std::string* raw_device_id); 275 std::string* device_id);
246 276
247 // Device thread shared by VideoCaptureManager and AudioInputDeviceManager. 277 // Device thread shared by VideoCaptureManager and AudioInputDeviceManager.
248 scoped_ptr<base::Thread> device_thread_; 278 scoped_ptr<base::Thread> device_thread_;
249 279
250 media::AudioManager* const audio_manager_; // not owned 280 media::AudioManager* const audio_manager_; // not owned
251 scoped_refptr<AudioInputDeviceManager> audio_input_device_manager_; 281 scoped_refptr<AudioInputDeviceManager> audio_input_device_manager_;
252 scoped_refptr<VideoCaptureManager> video_capture_manager_; 282 scoped_refptr<VideoCaptureManager> video_capture_manager_;
253 283
254 // Indicator of device monitoring state. 284 // Indicator of device monitoring state.
255 bool monitoring_started_; 285 bool monitoring_started_;
(...skipping 21 matching lines...) Expand all
277 307
278 bool use_fake_ui_; 308 bool use_fake_ui_;
279 scoped_ptr<FakeMediaStreamUIProxy> fake_ui_; 309 scoped_ptr<FakeMediaStreamUIProxy> fake_ui_;
280 310
281 DISALLOW_COPY_AND_ASSIGN(MediaStreamManager); 311 DISALLOW_COPY_AND_ASSIGN(MediaStreamManager);
282 }; 312 };
283 313
284 } // namespace content 314 } // namespace content
285 315
286 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_ 316 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698