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

Side by Side Diff: content/browser/renderer_host/media/media_stream_device_settings.cc

Issue 10542092: Refactor the content interface for RequestMediaAccessPermission. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 6 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 | 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 #include "content/browser/renderer_host/media/media_stream_device_settings.h" 5 #include "content/browser/renderer_host/media/media_stream_device_settings.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/stl_util.h" 11 #include "base/stl_util.h"
12 #include "content/browser/renderer_host/media/media_stream_settings_requester.h" 12 #include "content/browser/renderer_host/media/media_stream_settings_requester.h"
13 #include "content/browser/renderer_host/render_view_host_delegate.h"
14 #include "content/browser/renderer_host/render_view_host_impl.h"
13 #include "content/common/media/media_stream_options.h" 15 #include "content/common/media/media_stream_options.h"
14 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/content_browser_client.h" 17 #include "content/public/browser/content_browser_client.h"
16 #include "content/public/common/media_stream_request.h" 18 #include "content/public/common/media_stream_request.h"
17 #include "googleurl/src/gurl.h" 19 #include "googleurl/src/gurl.h"
18 20
19 using content::BrowserThread; 21 using content::BrowserThread;
20 using content::MediaStreamDevice; 22 using content::MediaStreamDevice;
21 using content::MediaStreamRequest; 23 using content::MediaStreamRequest;
22 24
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 101
100 // Request options. 102 // Request options.
101 StreamOptions options; 103 StreamOptions options;
102 // Map containing available devices for the requested capture types. 104 // Map containing available devices for the requested capture types.
103 DeviceMap devices_full; 105 DeviceMap devices_full;
104 // Whether or not a task was posted to make the call to 106 // Whether or not a task was posted to make the call to
105 // RequestMediaAccessPermission, to make sure that we never post twice to it. 107 // RequestMediaAccessPermission, to make sure that we never post twice to it.
106 bool posted_task; 108 bool posted_task;
107 }; 109 };
108 110
111 namespace {
112
113 // Sends the request to the appropriate WebContents.
114 void DoDeviceRequest(
115 const MediaStreamDeviceSettingsRequest* request,
116 const content::MediaResponseCallback& callback) {
117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
118
119 // Send the permission request to the web contents.
120 content::RenderViewHostImpl* host =
121 content::RenderViewHostImpl::FromID(request->render_process_id,
122 request->render_view_id);
123
124 // Tab may have gone away.
125 if (!host || !host->GetDelegate())
126 callback.Run(content::MediaStreamDevices());
127
128 host->GetDelegate()->RequestMediaAccessPermission(request, callback);
129 }
130
131 } // namespace
132
109 MediaStreamDeviceSettings::MediaStreamDeviceSettings( 133 MediaStreamDeviceSettings::MediaStreamDeviceSettings(
110 SettingsRequester* requester) 134 SettingsRequester* requester)
111 : requester_(requester), 135 : requester_(requester),
112 use_fake_ui_(false) { 136 use_fake_ui_(false) {
113 DCHECK(requester_); 137 DCHECK(requester_);
114 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 138 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
115 } 139 }
116 140
117 MediaStreamDeviceSettings::~MediaStreamDeviceSettings() { 141 MediaStreamDeviceSettings::~MediaStreamDeviceSettings() {
118 STLDeleteValues(&requests_); 142 STLDeleteValues(&requests_);
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 for (DeviceMap::iterator it = request->devices_full.begin(); 339 for (DeviceMap::iterator it = request->devices_full.begin();
316 it != request->devices_full.end(); ++it) { 340 it != request->devices_full.end(); ++it) {
317 request->devices[it->first].clear(); 341 request->devices[it->first].clear();
318 for (StreamDeviceInfoArray::iterator device = it->second.begin(); 342 for (StreamDeviceInfoArray::iterator device = it->second.begin();
319 device != it->second.end(); ++device) { 343 device != it->second.end(); ++device) {
320 request->devices[it->first].push_back(MediaStreamDevice( 344 request->devices[it->first].push_back(MediaStreamDevice(
321 it->first, device->device_id, device->name)); 345 it->first, device->device_id, device->name));
322 } 346 }
323 } 347 }
324 348
325 // Send the permission request to the content client.
326 scoped_refptr<ResponseCallbackHelper> helper = 349 scoped_refptr<ResponseCallbackHelper> helper =
327 new ResponseCallbackHelper(AsWeakPtr()); 350 new ResponseCallbackHelper(AsWeakPtr());
328 content::MediaResponseCallback callback = 351 content::MediaResponseCallback callback =
329 base::Bind(&ResponseCallbackHelper::PostResponse, 352 base::Bind(&ResponseCallbackHelper::PostResponse,
330 helper.get(), label); 353 helper.get(), label);
354
331 BrowserThread::PostTask( 355 BrowserThread::PostTask(
332 BrowserThread::UI, FROM_HERE, 356 BrowserThread::UI, FROM_HERE,
333 base::Bind( 357 base::Bind(&DoDeviceRequest, request, callback));
334 &content::ContentBrowserClient::RequestMediaAccessPermission,
335 base::Unretained(content::GetContentClient()->browser()),
336 request, callback));
337
338 } 358 }
339 359
340 } // namespace media_stream 360 } // namespace media_stream
OLDNEW
« no previous file with comments | « chrome/browser/ui/media_stream_infobar_delegate.h ('k') | content/browser/renderer_host/render_view_host_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698