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

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

Issue 2150903002: Reland add hooks to permission layer for permission action reporting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix nits Created 4 years, 5 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
« no previous file with comments | « no previous file | chrome/browser/permissions/permission_bubble_request_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "chrome/browser/media/media_stream_devices_controller.h" 5 #include "chrome/browser/media/media_stream_devices_controller.h"
6 6
7 #include <map> 7 #include <map>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 if (type == content::PermissionType::AUDIO_CAPTURE) 65 if (type == content::PermissionType::AUDIO_CAPTURE)
66 return request.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE; 66 return request.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE;
67 67
68 if (type == content::PermissionType::VIDEO_CAPTURE) 68 if (type == content::PermissionType::VIDEO_CAPTURE)
69 return request.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE; 69 return request.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE;
70 70
71 return false; 71 return false;
72 } 72 }
73 73
74 using PermissionActionCallback = 74 using PermissionActionCallback =
75 base::Callback<void(content::PermissionType, const GURL&)>; 75 base::Callback<void(content::PermissionType, const GURL&, Profile*)>;
76 76
77 void RecordSinglePermissionAction(const content::MediaStreamRequest& request, 77 void RecordSinglePermissionAction(const content::MediaStreamRequest& request,
78 content::PermissionType permission_type, 78 content::PermissionType permission_type,
79 Profile* profile,
79 PermissionActionCallback callback) { 80 PermissionActionCallback callback) {
80 if (ContentTypeIsRequested(permission_type, request)) { 81 if (ContentTypeIsRequested(permission_type, request)) {
81 callback.Run(permission_type, request.security_origin); 82 callback.Run(permission_type, request.security_origin, profile);
82 } 83 }
83 } 84 }
84 85
85 // Calls |action_function| for each permission requested by |request|. 86 // Calls |action_function| for each permission requested by |request|.
86 void RecordPermissionAction(const content::MediaStreamRequest& request, 87 void RecordPermissionAction(const content::MediaStreamRequest& request,
88 Profile* profile,
87 PermissionActionCallback callback) { 89 PermissionActionCallback callback) {
88 RecordSinglePermissionAction(request, content::PermissionType::AUDIO_CAPTURE, 90 RecordSinglePermissionAction(request, content::PermissionType::AUDIO_CAPTURE,
89 callback); 91 profile, callback);
90 RecordSinglePermissionAction(request, content::PermissionType::VIDEO_CAPTURE, 92 RecordSinglePermissionAction(request, content::PermissionType::VIDEO_CAPTURE,
91 callback); 93 profile, callback);
92 } 94 }
93 95
94 // This helper class helps to measure the number of media stream requests that 96 // This helper class helps to measure the number of media stream requests that
95 // occur. It ensures that only one request will be recorded per navigation, per 97 // occur. It ensures that only one request will be recorded per navigation, per
96 // frame. TODO(raymes): Remove this when https://crbug.com/526324 is fixed. 98 // frame. TODO(raymes): Remove this when https://crbug.com/526324 is fixed.
97 class MediaPermissionRequestLogger : content::WebContentsObserver { 99 class MediaPermissionRequestLogger : content::WebContentsObserver {
98 // Map of <render process id, render frame id> -> 100 // Map of <render process id, render frame id> ->
99 // MediaPermissionRequestLogger. 101 // MediaPermissionRequestLogger.
100 using RequestMap = std::map<std::pair<int, int>, 102 using RequestMap = std::map<std::pair<int, int>,
101 std::unique_ptr<MediaPermissionRequestLogger>>; 103 std::unique_ptr<MediaPermissionRequestLogger>>;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 return; 199 return;
198 } 200 }
199 #endif 201 #endif
200 202
201 // Otherwise we can run the callback immediately. 203 // Otherwise we can run the callback immediately.
202 RunCallback(old_audio_setting_, old_video_setting_, denial_reason); 204 RunCallback(old_audio_setting_, old_video_setting_, denial_reason);
203 } 205 }
204 206
205 MediaStreamDevicesController::~MediaStreamDevicesController() { 207 MediaStreamDevicesController::~MediaStreamDevicesController() {
206 if (!callback_.is_null()) { 208 if (!callback_.is_null()) {
207 RecordPermissionAction( 209 RecordPermissionAction(request_, profile_,
208 request_, base::Bind(PermissionUmaUtil::PermissionIgnored)); 210 base::Bind(PermissionUmaUtil::PermissionIgnored));
209 callback_.Run(content::MediaStreamDevices(), 211 callback_.Run(content::MediaStreamDevices(),
210 content::MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN, 212 content::MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN,
211 std::unique_ptr<content::MediaStreamUI>()); 213 std::unique_ptr<content::MediaStreamUI>());
212 } 214 }
213 } 215 }
214 216
215 // static 217 // static
216 void MediaStreamDevicesController::RegisterProfilePrefs( 218 void MediaStreamDevicesController::RegisterProfilePrefs(
217 user_prefs::PrefRegistrySyncable* prefs) { 219 user_prefs::PrefRegistrySyncable* prefs) {
218 prefs->RegisterBooleanPref(prefs::kVideoCaptureAllowed, true); 220 prefs->RegisterBooleanPref(prefs::kVideoCaptureAllowed, true);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 else if (!IsAskingForVideo()) 275 else if (!IsAskingForVideo())
274 message_id = IDS_MEDIA_CAPTURE_AUDIO_ONLY_PERMISSION_FRAGMENT; 276 message_id = IDS_MEDIA_CAPTURE_AUDIO_ONLY_PERMISSION_FRAGMENT;
275 return l10n_util::GetStringUTF16(message_id); 277 return l10n_util::GetStringUTF16(message_id);
276 } 278 }
277 279
278 GURL MediaStreamDevicesController::GetOrigin() const { 280 GURL MediaStreamDevicesController::GetOrigin() const {
279 return request_.security_origin; 281 return request_.security_origin;
280 } 282 }
281 283
282 void MediaStreamDevicesController::PermissionGranted() { 284 void MediaStreamDevicesController::PermissionGranted() {
283 RecordPermissionAction( 285 RecordPermissionAction(request_, profile_,
284 request_, base::Bind(PermissionUmaUtil::PermissionGranted)); 286 base::Bind(PermissionUmaUtil::PermissionGranted));
285 RunCallback(GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, 287 RunCallback(GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC,
286 old_audio_setting_, CONTENT_SETTING_ALLOW), 288 old_audio_setting_, CONTENT_SETTING_ALLOW),
287 GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, 289 GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA,
288 old_video_setting_, CONTENT_SETTING_ALLOW), 290 old_video_setting_, CONTENT_SETTING_ALLOW),
289 content::MEDIA_DEVICE_PERMISSION_DENIED); 291 content::MEDIA_DEVICE_PERMISSION_DENIED);
290 } 292 }
291 293
292 void MediaStreamDevicesController::PermissionDenied() { 294 void MediaStreamDevicesController::PermissionDenied() {
293 RecordPermissionAction( 295 RecordPermissionAction(request_, profile_,
294 request_, base::Bind(PermissionUmaUtil::PermissionDenied)); 296 base::Bind(PermissionUmaUtil::PermissionDenied));
295 RunCallback(GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, 297 RunCallback(GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC,
296 old_audio_setting_, CONTENT_SETTING_BLOCK), 298 old_audio_setting_, CONTENT_SETTING_BLOCK),
297 GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, 299 GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA,
298 old_video_setting_, CONTENT_SETTING_BLOCK), 300 old_video_setting_, CONTENT_SETTING_BLOCK),
299 content::MEDIA_DEVICE_PERMISSION_DENIED); 301 content::MEDIA_DEVICE_PERMISSION_DENIED);
300 } 302 }
301 303
302 void MediaStreamDevicesController::GroupedRequestFinished(bool audio_accepted, 304 void MediaStreamDevicesController::GroupedRequestFinished(bool audio_accepted,
303 bool video_accepted) { 305 bool video_accepted) {
304 RecordSinglePermissionAction( 306 RecordSinglePermissionAction(
305 request_, content::PermissionType::AUDIO_CAPTURE, 307 request_, content::PermissionType::AUDIO_CAPTURE, profile_,
306 base::Bind(audio_accepted ? PermissionUmaUtil::PermissionGranted 308 base::Bind(audio_accepted ? PermissionUmaUtil::PermissionGranted
307 : PermissionUmaUtil::PermissionDenied)); 309 : PermissionUmaUtil::PermissionDenied));
308 RecordSinglePermissionAction( 310 RecordSinglePermissionAction(
309 request_, content::PermissionType::VIDEO_CAPTURE, 311 request_, content::PermissionType::VIDEO_CAPTURE, profile_,
310 base::Bind(video_accepted ? PermissionUmaUtil::PermissionGranted 312 base::Bind(video_accepted ? PermissionUmaUtil::PermissionGranted
311 : PermissionUmaUtil::PermissionDenied)); 313 : PermissionUmaUtil::PermissionDenied));
312 314
313 ContentSetting audio_setting = 315 ContentSetting audio_setting =
314 audio_accepted ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; 316 audio_accepted ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK;
315 ContentSetting video_setting = 317 ContentSetting video_setting =
316 video_accepted ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; 318 video_accepted ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK;
317 RunCallback(GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, 319 RunCallback(GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC,
318 old_audio_setting_, audio_setting), 320 old_audio_setting_, audio_setting),
319 GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, 321 GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA,
320 old_video_setting_, video_setting), 322 old_video_setting_, video_setting),
321 content::MEDIA_DEVICE_PERMISSION_DENIED); 323 content::MEDIA_DEVICE_PERMISSION_DENIED);
322 } 324 }
323 325
324 void MediaStreamDevicesController::Cancelled() { 326 void MediaStreamDevicesController::Cancelled() {
325 RecordPermissionAction( 327 RecordPermissionAction(request_, profile_,
326 request_, base::Bind(PermissionUmaUtil::PermissionDismissed)); 328 base::Bind(PermissionUmaUtil::PermissionDismissed));
327 RunCallback(old_audio_setting_, old_video_setting_, 329 RunCallback(old_audio_setting_, old_video_setting_,
328 content::MEDIA_DEVICE_PERMISSION_DISMISSED); 330 content::MEDIA_DEVICE_PERMISSION_DISMISSED);
329 } 331 }
330 332
331 void MediaStreamDevicesController::RequestFinished() { 333 void MediaStreamDevicesController::RequestFinished() {
332 delete this; 334 delete this;
333 } 335 }
334 336
335 PermissionBubbleType MediaStreamDevicesController::GetPermissionBubbleType() 337 PermissionBubbleType MediaStreamDevicesController::GetPermissionBubbleType()
336 const { 338 const {
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 if (android_permission_blocked) 634 if (android_permission_blocked)
633 return false; 635 return false;
634 636
635 // Don't approve device requests if the tab was hidden. 637 // Don't approve device requests if the tab was hidden.
636 // TODO(qinmin): Add a test for this. http://crbug.com/396869. 638 // TODO(qinmin): Add a test for this. http://crbug.com/396869.
637 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video? 639 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video?
638 return web_contents_->GetRenderWidgetHostView()->IsShowing(); 640 return web_contents_->GetRenderWidgetHostView()->IsShowing();
639 #endif 641 #endif
640 return true; 642 return true;
641 } 643 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/permissions/permission_bubble_request_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698