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

Side by Side Diff: chrome/browser/media/media_access_handler.cc

Issue 2746873004: Move ChromeOS login media access logic into a MediaAccessHandler (Closed)
Patch Set: ChromeOSLoginMediaAccessHandler Created 3 years, 8 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
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/media/media_access_handler.h"
6
7 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h"
8 #include "chrome/browser/media/webrtc/media_stream_capture_indicator.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "content/public/browser/web_contents.h"
11
12 // static
13 void MediaAccessHandler::CheckDevicesAndRunCallback(
14 content::WebContents* web_contents,
15 const content::MediaStreamRequest& request,
16 const content::MediaResponseCallback& callback,
17 bool audio_allowed,
18 bool video_allowed) {
19 // TODO(vrk): This code is largely duplicated in
20 // MediaStreamDevicesController::GetDevices(). Move this code into a shared
21 // method
22 // between the two classes.
emaxx 2017/04/06 02:41:47 nit: Reformat the comment.
raymes 2017/04/10 00:16:49 Done.
23 bool get_default_audio_device = audio_allowed;
24 bool get_default_video_device = video_allowed;
25
26 content::MediaStreamDevices devices;
27
28 // Set an initial error result. If neither audio or video is allowed, we'll
29 // never try to get any device below but will just create |ui| and return an
30 // empty list with "invalid state" result. If at least one is allowed, we'll
31 // try to get device(s), and if failure, we want to return "no hardware"
32 // result.
33 // TODO(grunell): The invalid state result should be changed to a new denied
34 // result + a dcheck to ensure at least one of audio or video types is
35 // capture.
36 content::MediaStreamRequestResult result =
37 (audio_allowed || video_allowed) ? content::MEDIA_DEVICE_NO_HARDWARE
38 : content::MEDIA_DEVICE_INVALID_STATE;
39
40 // Get the exact audio or video device if an id is specified.
41 // We only set any error result here and before running the callback change
42 // it to OK if we have any device.
43 if (audio_allowed && !request.requested_audio_device_id.empty()) {
44 const content::MediaStreamDevice* audio_device =
45 MediaCaptureDevicesDispatcher::GetInstance()->GetRequestedAudioDevice(
46 request.requested_audio_device_id);
47 if (audio_device) {
48 devices.push_back(*audio_device);
49 get_default_audio_device = false;
50 }
51 }
52 if (video_allowed && !request.requested_video_device_id.empty()) {
53 const content::MediaStreamDevice* video_device =
54 MediaCaptureDevicesDispatcher::GetInstance()->GetRequestedVideoDevice(
55 request.requested_video_device_id);
56 if (video_device) {
57 devices.push_back(*video_device);
58 get_default_video_device = false;
59 }
60 }
61
62 Profile* profile =
63 Profile::FromBrowserContext(web_contents->GetBrowserContext());
64
65 // If either or both audio and video devices were requested but not
66 // specified by id, get the default devices.
67 if (get_default_audio_device || get_default_video_device) {
68 MediaCaptureDevicesDispatcher::GetInstance()->GetDefaultDevicesForProfile(
69 profile, get_default_audio_device, get_default_video_device, &devices);
70 }
71
72 std::unique_ptr<content::MediaStreamUI> ui;
73 if (!devices.empty()) {
74 result = content::MEDIA_DEVICE_OK;
75 ui = MediaCaptureDevicesDispatcher::GetInstance()
76 ->GetMediaStreamCaptureIndicator()
77 ->RegisterMediaStream(web_contents, devices);
78 }
79
80 callback.Run(devices, result, std::move(ui));
emaxx 2017/04/06 02:41:47 nit: #include <utility>
raymes 2017/04/10 00:16:49 Done.
81 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698