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

Side by Side Diff: chrome/browser/media/webrtc/media_stream_infobar_delegate_android.cc

Issue 2254763002: Enable the optional permission prompt persistence toggle on grouped infobars (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@permission-infobardelegate-clean
Patch Set: DCHECK -> CHECK Created 4 years, 3 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
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/webrtc/media_stream_infobar_delegate_android.h" 5 #include "chrome/browser/media/webrtc/media_stream_infobar_delegate_android.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/metrics/histogram_macros.h" 11 #include "base/metrics/histogram_macros.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "chrome/browser/infobars/infobar_service.h" 13 #include "chrome/browser/infobars/infobar_service.h"
14 #include "chrome/browser/permissions/permission_uma_util.h"
14 #include "chrome/common/url_constants.h" 15 #include "chrome/common/url_constants.h"
15 #include "components/content_settings/core/common/content_settings_types.h" 16 #include "components/content_settings/core/common/content_settings_types.h"
16 #include "components/google/core/browser/google_util.h" 17 #include "components/google/core/browser/google_util.h"
17 #include "components/infobars/core/infobar.h" 18 #include "components/infobars/core/infobar.h"
18 #include "content/public/browser/web_contents.h" 19 #include "content/public/browser/web_contents.h"
19 #include "content/public/common/origin_util.h" 20 #include "content/public/common/origin_util.h"
20 #include "url/gurl.h" 21 #include "url/gurl.h"
21 22
22 namespace { 23 namespace {
23 24
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 infobars::InfoBar* old_infobar = infobar_service->infobar_at(i); 63 infobars::InfoBar* old_infobar = infobar_service->infobar_at(i);
63 if (old_infobar->delegate()->AsMediaStreamInfoBarDelegateAndroid()) { 64 if (old_infobar->delegate()->AsMediaStreamInfoBarDelegateAndroid()) {
64 infobar_service->ReplaceInfoBar(old_infobar, std::move(infobar)); 65 infobar_service->ReplaceInfoBar(old_infobar, std::move(infobar));
65 return true; 66 return true;
66 } 67 }
67 } 68 }
68 infobar_service->AddInfoBar(std::move(infobar)); 69 infobar_service->AddInfoBar(std::move(infobar));
69 return true; 70 return true;
70 } 71 }
71 72
73 void MediaStreamInfoBarDelegateAndroid::RecordPermissionAcceptedUma(
74 int position,
75 bool persist) {
76 PermissionUmaUtil::PermissionPromptAcceptedWithPersistenceToggle(
77 controller_->GetPermissionTypeForContentSettingsType(
78 GetContentSettingType(position)),
79 persist);
80 }
81
82 void MediaStreamInfoBarDelegateAndroid::RecordPermissionDeniedUma(
83 int position,
84 bool persist) {
85 PermissionUmaUtil::PermissionPromptDeniedWithPersistenceToggle(
86 controller_->GetPermissionTypeForContentSettingsType(
87 GetContentSettingType(position)),
88 persist);
89 }
90
72 infobars::InfoBarDelegate::InfoBarIdentifier 91 infobars::InfoBarDelegate::InfoBarIdentifier
73 MediaStreamInfoBarDelegateAndroid::GetIdentifier() const { 92 MediaStreamInfoBarDelegateAndroid::GetIdentifier() const {
74 return MEDIA_STREAM_INFOBAR_DELEGATE_ANDROID; 93 return MEDIA_STREAM_INFOBAR_DELEGATE_ANDROID;
75 } 94 }
76 95
77 MediaStreamInfoBarDelegateAndroid::MediaStreamInfoBarDelegateAndroid( 96 MediaStreamInfoBarDelegateAndroid::MediaStreamInfoBarDelegateAndroid(
78 std::unique_ptr<MediaStreamDevicesController> controller) 97 std::unique_ptr<MediaStreamDevicesController> controller)
79 : GroupedPermissionInfoBarDelegate( 98 : GroupedPermissionInfoBarDelegate(
80 controller->GetOrigin(), 99 controller->GetOrigin(),
81 GetContentSettingsTypes(controller.get())), 100 GetContentSettingsTypes(controller.get())),
82 controller_(std::move(controller)) { 101 controller_(std::move(controller)) {
83 DCHECK(controller_.get()); 102 DCHECK(controller_.get());
84 DCHECK(controller_->IsAskingForAudio() || controller_->IsAskingForVideo()); 103 DCHECK(controller_->IsAskingForAudio() || controller_->IsAskingForVideo());
85 } 104 }
86 105
87 void MediaStreamInfoBarDelegateAndroid::InfoBarDismissed() { 106 void MediaStreamInfoBarDelegateAndroid::InfoBarDismissed() {
88 // Deny the request if the infobar was closed with the 'x' button, since 107 // Deny the request if the infobar was closed with the 'x' button, since
89 // we don't want WebRTC to be waiting for an answer that will never come. 108 // we don't want WebRTC to be waiting for an answer that will never come.
90 controller_->Cancelled(); 109 controller_->Cancelled();
91 } 110 }
92 111
93 MediaStreamInfoBarDelegateAndroid* 112 MediaStreamInfoBarDelegateAndroid*
94 MediaStreamInfoBarDelegateAndroid::AsMediaStreamInfoBarDelegateAndroid() { 113 MediaStreamInfoBarDelegateAndroid::AsMediaStreamInfoBarDelegateAndroid() {
95 return this; 114 return this;
96 } 115 }
97 116
98 bool MediaStreamInfoBarDelegateAndroid::Accept() { 117 bool MediaStreamInfoBarDelegateAndroid::Accept() {
118 bool persist_permission = true;
119 if (ShouldShowPersistenceToggle()) {
120 persist_permission = persist();
121
122 // TODO(dominickn): fold these metrics calls into
123 // PermissionUmaUtil::PermissionGranted. See crbug.com/638076.
124 if (GetPermissionCount() == 2) {
125 RecordPermissionAcceptedUma(kGroupedInfobarAudioPosition,
126 persist_permission);
127 RecordPermissionAcceptedUma(kGroupedInfobarVideoPosition,
128 persist_permission);
129 } else {
130 DCHECK_EQ(1, GetPermissionCount());
131 RecordPermissionAcceptedUma(0, persist_permission);
132 }
133 }
134
135 controller_->set_persist(persist_permission);
99 if (GetPermissionCount() == 2) { 136 if (GetPermissionCount() == 2) {
100 controller_->GroupedRequestFinished( 137 controller_->GroupedRequestFinished(
101 GetAcceptState(kGroupedInfobarAudioPosition), 138 GetAcceptState(kGroupedInfobarAudioPosition),
102 GetAcceptState(kGroupedInfobarVideoPosition)); 139 GetAcceptState(kGroupedInfobarVideoPosition));
103 } else { 140 } else {
104 DCHECK_EQ(1, GetPermissionCount()); 141 DCHECK_EQ(1, GetPermissionCount());
105 controller_->PermissionGranted(); 142 controller_->PermissionGranted();
106 } 143 }
107 return true; 144 return true;
108 } 145 }
109 146
110 bool MediaStreamInfoBarDelegateAndroid::Cancel() { 147 bool MediaStreamInfoBarDelegateAndroid::Cancel() {
148 bool persist_permission = true;
149 if (ShouldShowPersistenceToggle()) {
150 persist_permission = persist();
151
152 // TODO(dominickn): fold these metrics calls into
153 // PermissionUmaUtil::PermissionGranted. See crbug.com/638076.
154 if (GetPermissionCount() == 2) {
155 RecordPermissionDeniedUma(kGroupedInfobarAudioPosition,
156 persist_permission);
157 RecordPermissionDeniedUma(kGroupedInfobarVideoPosition,
158 persist_permission);
159 } else {
160 DCHECK_EQ(1, GetPermissionCount());
161 RecordPermissionDeniedUma(0, persist_permission);
162 }
163 }
164 controller_->set_persist(persist_permission);
111 controller_->PermissionDenied(); 165 controller_->PermissionDenied();
112 return true; 166 return true;
113 } 167 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698