OLD | NEW |
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_infobar_delegate_android.h" | 5 #include "chrome/browser/media/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.h" | 11 #include "base/metrics/histogram.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 "chrome/grit/generated_resources.h" | 16 #include "chrome/grit/generated_resources.h" |
16 #include "components/content_settings/core/common/content_settings_types.h" | 17 #include "components/content_settings/core/common/content_settings_types.h" |
17 #include "components/google/core/browser/google_util.h" | 18 #include "components/google/core/browser/google_util.h" |
18 #include "components/infobars/core/infobar.h" | 19 #include "components/infobars/core/infobar.h" |
19 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
20 #include "content/public/common/origin_util.h" | 21 #include "content/public/common/origin_util.h" |
21 #include "grit/components_strings.h" | 22 #include "grit/components_strings.h" |
22 #include "grit/theme_resources.h" | 23 #include "grit/theme_resources.h" |
23 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 infobars::InfoBar* old_infobar = infobar_service->infobar_at(i); | 67 infobars::InfoBar* old_infobar = infobar_service->infobar_at(i); |
67 if (old_infobar->delegate()->AsMediaStreamInfoBarDelegateAndroid()) { | 68 if (old_infobar->delegate()->AsMediaStreamInfoBarDelegateAndroid()) { |
68 infobar_service->ReplaceInfoBar(old_infobar, std::move(infobar)); | 69 infobar_service->ReplaceInfoBar(old_infobar, std::move(infobar)); |
69 return true; | 70 return true; |
70 } | 71 } |
71 } | 72 } |
72 infobar_service->AddInfoBar(std::move(infobar)); | 73 infobar_service->AddInfoBar(std::move(infobar)); |
73 return true; | 74 return true; |
74 } | 75 } |
75 | 76 |
| 77 void MediaStreamInfoBarDelegateAndroid::RecordPermissionAcceptedUma( |
| 78 int position, |
| 79 bool persist) { |
| 80 PermissionUmaUtil::PermissionPromptAcceptedWithPersistenceToggle( |
| 81 controller_->GetPermissionTypeForContentSettingsType( |
| 82 GetContentSettingType(position)), |
| 83 persist); |
| 84 } |
| 85 |
| 86 void MediaStreamInfoBarDelegateAndroid::RecordPermissionDeniedUma( |
| 87 int position, |
| 88 bool persist) { |
| 89 PermissionUmaUtil::PermissionPromptDeniedWithPersistenceToggle( |
| 90 controller_->GetPermissionTypeForContentSettingsType( |
| 91 GetContentSettingType(position)), |
| 92 persist); |
| 93 } |
| 94 |
76 infobars::InfoBarDelegate::InfoBarIdentifier | 95 infobars::InfoBarDelegate::InfoBarIdentifier |
77 MediaStreamInfoBarDelegateAndroid::GetIdentifier() const { | 96 MediaStreamInfoBarDelegateAndroid::GetIdentifier() const { |
78 return MEDIA_STREAM_INFOBAR_DELEGATE_ANDROID; | 97 return MEDIA_STREAM_INFOBAR_DELEGATE_ANDROID; |
79 } | 98 } |
80 | 99 |
81 MediaStreamInfoBarDelegateAndroid::MediaStreamInfoBarDelegateAndroid( | 100 MediaStreamInfoBarDelegateAndroid::MediaStreamInfoBarDelegateAndroid( |
82 std::unique_ptr<MediaStreamDevicesController> controller) | 101 std::unique_ptr<MediaStreamDevicesController> controller) |
83 : GroupedPermissionInfoBarDelegate( | 102 : GroupedPermissionInfoBarDelegate( |
84 controller->GetOrigin(), | 103 controller->GetOrigin(), |
85 GetContentSettingsTypes(controller.get())), | 104 GetContentSettingsTypes(controller.get())), |
86 controller_(std::move(controller)) { | 105 controller_(std::move(controller)) { |
87 DCHECK(controller_.get()); | 106 DCHECK(controller_.get()); |
88 DCHECK(controller_->IsAskingForAudio() || controller_->IsAskingForVideo()); | 107 DCHECK(controller_->IsAskingForAudio() || controller_->IsAskingForVideo()); |
89 } | 108 } |
90 | 109 |
91 void MediaStreamInfoBarDelegateAndroid::InfoBarDismissed() { | 110 void MediaStreamInfoBarDelegateAndroid::InfoBarDismissed() { |
92 // Deny the request if the infobar was closed with the 'x' button, since | 111 // Deny the request if the infobar was closed with the 'x' button, since |
93 // we don't want WebRTC to be waiting for an answer that will never come. | 112 // we don't want WebRTC to be waiting for an answer that will never come. |
94 controller_->Cancelled(); | 113 controller_->Cancelled(); |
95 } | 114 } |
96 | 115 |
97 MediaStreamInfoBarDelegateAndroid* | 116 MediaStreamInfoBarDelegateAndroid* |
98 MediaStreamInfoBarDelegateAndroid::AsMediaStreamInfoBarDelegateAndroid() { | 117 MediaStreamInfoBarDelegateAndroid::AsMediaStreamInfoBarDelegateAndroid() { |
99 return this; | 118 return this; |
100 } | 119 } |
101 | 120 |
102 bool MediaStreamInfoBarDelegateAndroid::Accept() { | 121 bool MediaStreamInfoBarDelegateAndroid::Accept() { |
| 122 bool persist_permission = true; |
| 123 if (ShouldShowPersistenceToggle()) { |
| 124 persist_permission = persist(); |
| 125 |
| 126 // TODO(dominickn): fold these metrics calls into |
| 127 // PermissionUmaUtil::PermissionGranted. See crbug.com/638076. |
| 128 if (GetPermissionCount() == 2) { |
| 129 RecordPermissionAcceptedUma(kGroupedInfobarAudioPosition, |
| 130 persist_permission); |
| 131 RecordPermissionAcceptedUma(kGroupedInfobarVideoPosition, |
| 132 persist_permission); |
| 133 } else { |
| 134 DCHECK_EQ(1, GetPermissionCount()); |
| 135 RecordPermissionAcceptedUma(0, persist_permission); |
| 136 } |
| 137 } |
| 138 |
| 139 controller_->set_persist(persist_permission); |
103 if (GetPermissionCount() == 2) { | 140 if (GetPermissionCount() == 2) { |
104 controller_->GroupedRequestFinished( | 141 controller_->GroupedRequestFinished( |
105 GetAcceptState(kGroupedInfobarAudioPosition), | 142 GetAcceptState(kGroupedInfobarAudioPosition), |
106 GetAcceptState(kGroupedInfobarVideoPosition)); | 143 GetAcceptState(kGroupedInfobarVideoPosition)); |
107 } else { | 144 } else { |
108 DCHECK_EQ(1, GetPermissionCount()); | 145 DCHECK_EQ(1, GetPermissionCount()); |
109 controller_->PermissionGranted(); | 146 controller_->PermissionGranted(); |
110 } | 147 } |
111 return true; | 148 return true; |
112 } | 149 } |
113 | 150 |
114 bool MediaStreamInfoBarDelegateAndroid::Cancel() { | 151 bool MediaStreamInfoBarDelegateAndroid::Cancel() { |
| 152 bool persist_permission = true; |
| 153 if (ShouldShowPersistenceToggle()) { |
| 154 persist_permission = persist(); |
| 155 |
| 156 // TODO(dominickn): fold these metrics calls into |
| 157 // PermissionUmaUtil::PermissionGranted. See crbug.com/638076. |
| 158 if (GetPermissionCount() == 2) { |
| 159 RecordPermissionDeniedUma(kGroupedInfobarAudioPosition, |
| 160 persist_permission); |
| 161 RecordPermissionDeniedUma(kGroupedInfobarVideoPosition, |
| 162 persist_permission); |
| 163 } else { |
| 164 DCHECK_EQ(1, GetPermissionCount()); |
| 165 RecordPermissionDeniedUma(0, persist_permission); |
| 166 } |
| 167 } |
| 168 controller_->set_persist(persist_permission); |
115 controller_->PermissionDenied(); | 169 controller_->PermissionDenied(); |
116 return true; | 170 return true; |
117 } | 171 } |
OLD | NEW |