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

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

Issue 2463393003: Record permission prompt gesture metrics on Android. (Closed)
Patch Set: Address comments Created 4 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
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"
(...skipping 15 matching lines...) Expand all
26 26
27 namespace { 27 namespace {
28 28
29 void DoNothing(bool update_content_setting, PermissionAction decision) {} 29 void DoNothing(bool update_content_setting, PermissionAction decision) {}
30 30
31 } // namespace 31 } // namespace
32 32
33 // static 33 // static
34 bool MediaStreamInfoBarDelegateAndroid::Create( 34 bool MediaStreamInfoBarDelegateAndroid::Create(
35 content::WebContents* web_contents, 35 content::WebContents* web_contents,
36 bool user_gesture,
36 std::unique_ptr<MediaStreamDevicesController> controller) { 37 std::unique_ptr<MediaStreamDevicesController> controller) {
37 InfoBarService* infobar_service = 38 InfoBarService* infobar_service =
38 InfoBarService::FromWebContents(web_contents); 39 InfoBarService::FromWebContents(web_contents);
39 if (!infobar_service) { 40 if (!infobar_service) {
40 // Deny the request if there is no place to show the infobar, e.g. when 41 // Deny the request if there is no place to show the infobar, e.g. when
41 // the request comes from a background extension page. 42 // the request comes from a background extension page.
42 controller->Cancelled(); 43 controller->Cancelled();
43 return false; 44 return false;
44 } 45 }
45 46
46 std::unique_ptr<infobars::InfoBar> infobar( 47 std::unique_ptr<infobars::InfoBar> infobar(
47 CreatePermissionInfoBar(std::unique_ptr<PermissionInfoBarDelegate>( 48 CreatePermissionInfoBar(std::unique_ptr<PermissionInfoBarDelegate>(
48 new MediaStreamInfoBarDelegateAndroid( 49 new MediaStreamInfoBarDelegateAndroid(
49 Profile::FromBrowserContext(web_contents->GetBrowserContext()), 50 Profile::FromBrowserContext(web_contents->GetBrowserContext()),
51 user_gesture,
50 std::move(controller))))); 52 std::move(controller)))));
51 for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { 53 for (size_t i = 0; i < infobar_service->infobar_count(); ++i) {
52 infobars::InfoBar* old_infobar = infobar_service->infobar_at(i); 54 infobars::InfoBar* old_infobar = infobar_service->infobar_at(i);
53 if (old_infobar->delegate()->AsMediaStreamInfoBarDelegateAndroid()) { 55 if (old_infobar->delegate()->AsMediaStreamInfoBarDelegateAndroid()) {
54 infobar_service->ReplaceInfoBar(old_infobar, std::move(infobar)); 56 infobar_service->ReplaceInfoBar(old_infobar, std::move(infobar));
55 return true; 57 return true;
56 } 58 }
57 } 59 }
58 infobar_service->AddInfoBar(std::move(infobar)); 60 infobar_service->AddInfoBar(std::move(infobar));
59 return true; 61 return true;
60 } 62 }
61 63
62 infobars::InfoBarDelegate::InfoBarIdentifier 64 infobars::InfoBarDelegate::InfoBarIdentifier
63 MediaStreamInfoBarDelegateAndroid::GetIdentifier() const { 65 MediaStreamInfoBarDelegateAndroid::GetIdentifier() const {
64 return MEDIA_STREAM_INFOBAR_DELEGATE_ANDROID; 66 return MEDIA_STREAM_INFOBAR_DELEGATE_ANDROID;
65 } 67 }
66 68
67 infobars::InfoBarDelegate::Type 69 infobars::InfoBarDelegate::Type
68 MediaStreamInfoBarDelegateAndroid::GetInfoBarType() const { 70 MediaStreamInfoBarDelegateAndroid::GetInfoBarType() const {
69 return PAGE_ACTION_TYPE; 71 return PAGE_ACTION_TYPE;
70 } 72 }
71 73
72 int MediaStreamInfoBarDelegateAndroid::GetIconId() const { 74 int MediaStreamInfoBarDelegateAndroid::GetIconId() const {
73 return controller_->IsAskingForVideo() ? IDR_INFOBAR_MEDIA_STREAM_CAMERA 75 return controller_->IsAskingForVideo() ? IDR_INFOBAR_MEDIA_STREAM_CAMERA
74 : IDR_INFOBAR_MEDIA_STREAM_MIC; 76 : IDR_INFOBAR_MEDIA_STREAM_MIC;
75 } 77 }
76 78
77 MediaStreamInfoBarDelegateAndroid::MediaStreamInfoBarDelegateAndroid( 79 MediaStreamInfoBarDelegateAndroid::MediaStreamInfoBarDelegateAndroid(
78 Profile* profile, 80 Profile* profile,
81 bool user_gesture,
79 std::unique_ptr<MediaStreamDevicesController> controller) 82 std::unique_ptr<MediaStreamDevicesController> controller)
80 : PermissionInfoBarDelegate( 83 : PermissionInfoBarDelegate(
81 controller->GetOrigin(), 84 controller->GetOrigin(),
82 // The content setting type and permission type here are only passed 85 // The content setting type and permission type here are only passed
83 // in to fit into PermissionInfoBarDelegate, even though media infobar 86 // in to fit into PermissionInfoBarDelegate, even though media infobar
84 // controls both mic and camera. This is a temporary state for easy 87 // controls both mic and camera. This is a temporary state for easy
85 // refactoring. 88 // refactoring.
86 // TODO(lshang): Merge MediaStreamInfoBarDelegateAndroid into 89 // TODO(lshang): Merge MediaStreamInfoBarDelegateAndroid into
87 // GroupedPermissionInfoBarDelegate. See crbug.com/606138. 90 // GroupedPermissionInfoBarDelegate. See crbug.com/606138.
88 content::PermissionType::AUDIO_CAPTURE, 91 content::PermissionType::AUDIO_CAPTURE,
89 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, 92 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC,
90 false, 93 user_gesture,
91 profile, 94 profile,
92 // This is only passed in to fit into PermissionInfoBarDelegate. 95 // This is only passed in to fit into PermissionInfoBarDelegate.
93 // Infobar accepted/denied/dismissed is handled by controller, not via 96 // Infobar accepted/denied/dismissed is handled by controller, not via
94 // callbacks. 97 // callbacks.
95 base::Bind(&DoNothing)), 98 base::Bind(&DoNothing)),
96 controller_(std::move(controller)) { 99 controller_(std::move(controller)) {
97 DCHECK(controller_.get()); 100 DCHECK(controller_.get());
98 DCHECK(controller_->IsAskingForAudio() || controller_->IsAskingForVideo()); 101 DCHECK(controller_->IsAskingForAudio() || controller_->IsAskingForVideo());
99 } 102 }
100 103
(...skipping 29 matching lines...) Expand all
130 133
131 int MediaStreamInfoBarDelegateAndroid::GetMessageResourceId() const { 134 int MediaStreamInfoBarDelegateAndroid::GetMessageResourceId() const {
132 if (!controller_->IsAskingForAudio()) 135 if (!controller_->IsAskingForAudio())
133 return IDS_MEDIA_CAPTURE_VIDEO_ONLY; 136 return IDS_MEDIA_CAPTURE_VIDEO_ONLY;
134 else if (!controller_->IsAskingForVideo()) 137 else if (!controller_->IsAskingForVideo())
135 return IDS_MEDIA_CAPTURE_AUDIO_ONLY; 138 return IDS_MEDIA_CAPTURE_AUDIO_ONLY;
136 return IDS_MEDIA_CAPTURE_AUDIO_AND_VIDEO; 139 return IDS_MEDIA_CAPTURE_AUDIO_AND_VIDEO;
137 } 140 }
138 141
139 bool MediaStreamInfoBarDelegateAndroid::Accept() { 142 bool MediaStreamInfoBarDelegateAndroid::Accept() {
143 // TODO(dominickn): fold these metrics calls into
144 // PermissionUmaUtil::PermissionGranted. See crbug.com/638076.
145 PermissionUmaUtil::RecordPermissionPromptAccepted(
146 controller_->GetPermissionRequestType(),
147 PermissionUtil::GetGestureType(user_gesture()));
148
140 bool persist_permission = true; 149 bool persist_permission = true;
141 if (ShouldShowPersistenceToggle()) { 150 if (ShouldShowPersistenceToggle()) {
142 persist_permission = persist(); 151 persist_permission = persist();
143 152
144 // TODO(dominickn): fold these metrics calls into
145 // PermissionUmaUtil::PermissionGranted. See crbug.com/638076.
146 if (controller_->IsAskingForAudio()) { 153 if (controller_->IsAskingForAudio()) {
147 PermissionUmaUtil::PermissionPromptAcceptedWithPersistenceToggle( 154 PermissionUmaUtil::PermissionPromptAcceptedWithPersistenceToggle(
148 content::PermissionType::AUDIO_CAPTURE, persist_permission); 155 content::PermissionType::AUDIO_CAPTURE, persist_permission);
149 } 156 }
150 if (controller_->IsAskingForVideo()) { 157 if (controller_->IsAskingForVideo()) {
151 PermissionUmaUtil::PermissionPromptAcceptedWithPersistenceToggle( 158 PermissionUmaUtil::PermissionPromptAcceptedWithPersistenceToggle(
152 content::PermissionType::VIDEO_CAPTURE, persist_permission); 159 content::PermissionType::VIDEO_CAPTURE, persist_permission);
153 } 160 }
154 } 161 }
155 162
156 controller_->set_persist(persist_permission); 163 controller_->set_persist(persist_permission);
157 controller_->PermissionGranted(); 164 controller_->PermissionGranted();
158 return true; 165 return true;
159 } 166 }
160 167
161 bool MediaStreamInfoBarDelegateAndroid::Cancel() { 168 bool MediaStreamInfoBarDelegateAndroid::Cancel() {
169 // TODO(dominickn): fold these metrics calls into
170 // PermissionUmaUtil::PermissionDenied. See crbug.com/638076.
171 PermissionUmaUtil::RecordPermissionPromptDenied(
172 controller_->GetPermissionRequestType(),
173 PermissionUtil::GetGestureType(user_gesture()));
174
162 bool persist_permission = true; 175 bool persist_permission = true;
163 if (ShouldShowPersistenceToggle()) { 176 if (ShouldShowPersistenceToggle()) {
164 persist_permission = persist(); 177 persist_permission = persist();
165 178
166 // TODO(dominickn): fold these metrics calls into
167 // PermissionUmaUtil::PermissionGranted. See crbug.com/638076.
168 if (controller_->IsAskingForAudio()) { 179 if (controller_->IsAskingForAudio()) {
169 PermissionUmaUtil::PermissionPromptDeniedWithPersistenceToggle( 180 PermissionUmaUtil::PermissionPromptDeniedWithPersistenceToggle(
170 content::PermissionType::AUDIO_CAPTURE, persist_permission); 181 content::PermissionType::AUDIO_CAPTURE, persist_permission);
171 } 182 }
172 if (controller_->IsAskingForVideo()) { 183 if (controller_->IsAskingForVideo()) {
173 PermissionUmaUtil::PermissionPromptDeniedWithPersistenceToggle( 184 PermissionUmaUtil::PermissionPromptDeniedWithPersistenceToggle(
174 content::PermissionType::VIDEO_CAPTURE, persist_permission); 185 content::PermissionType::VIDEO_CAPTURE, persist_permission);
175 } 186 }
176 } 187 }
177 controller_->set_persist(persist_permission); 188 controller_->set_persist(persist_permission);
(...skipping 10 matching lines...) Expand all
188 } 199 }
189 200
190 std::vector<int> MediaStreamInfoBarDelegateAndroid::content_settings() const { 201 std::vector<int> MediaStreamInfoBarDelegateAndroid::content_settings() const {
191 std::vector<int> types; 202 std::vector<int> types;
192 if (controller_->IsAskingForAudio()) 203 if (controller_->IsAskingForAudio())
193 types.push_back(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); 204 types.push_back(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC);
194 if (controller_->IsAskingForVideo()) 205 if (controller_->IsAskingForVideo())
195 types.push_back(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); 206 types.push_back(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA);
196 return types; 207 return types;
197 } 208 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698