| 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/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" | |
| 15 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
| 16 #include "components/content_settings/core/common/content_settings_types.h" | 15 #include "components/content_settings/core/common/content_settings_types.h" |
| 17 #include "components/google/core/browser/google_util.h" | 16 #include "components/google/core/browser/google_util.h" |
| 18 #include "components/infobars/core/infobar.h" | 17 #include "components/infobars/core/infobar.h" |
| 19 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
| 20 #include "content/public/common/origin_util.h" | 19 #include "content/public/common/origin_util.h" |
| 21 #include "url/gurl.h" | 20 #include "url/gurl.h" |
| 22 | 21 |
| 23 namespace { | 22 namespace { |
| 24 | 23 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 infobars::InfoBar* old_infobar = infobar_service->infobar_at(i); | 62 infobars::InfoBar* old_infobar = infobar_service->infobar_at(i); |
| 64 if (old_infobar->delegate()->AsMediaStreamInfoBarDelegateAndroid()) { | 63 if (old_infobar->delegate()->AsMediaStreamInfoBarDelegateAndroid()) { |
| 65 infobar_service->ReplaceInfoBar(old_infobar, std::move(infobar)); | 64 infobar_service->ReplaceInfoBar(old_infobar, std::move(infobar)); |
| 66 return true; | 65 return true; |
| 67 } | 66 } |
| 68 } | 67 } |
| 69 infobar_service->AddInfoBar(std::move(infobar)); | 68 infobar_service->AddInfoBar(std::move(infobar)); |
| 70 return true; | 69 return true; |
| 71 } | 70 } |
| 72 | 71 |
| 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 | |
| 91 infobars::InfoBarDelegate::InfoBarIdentifier | 72 infobars::InfoBarDelegate::InfoBarIdentifier |
| 92 MediaStreamInfoBarDelegateAndroid::GetIdentifier() const { | 73 MediaStreamInfoBarDelegateAndroid::GetIdentifier() const { |
| 93 return MEDIA_STREAM_INFOBAR_DELEGATE_ANDROID; | 74 return MEDIA_STREAM_INFOBAR_DELEGATE_ANDROID; |
| 94 } | 75 } |
| 95 | 76 |
| 96 MediaStreamInfoBarDelegateAndroid::MediaStreamInfoBarDelegateAndroid( | 77 MediaStreamInfoBarDelegateAndroid::MediaStreamInfoBarDelegateAndroid( |
| 97 std::unique_ptr<MediaStreamDevicesController> controller) | 78 std::unique_ptr<MediaStreamDevicesController> controller) |
| 98 : GroupedPermissionInfoBarDelegate( | 79 : GroupedPermissionInfoBarDelegate( |
| 99 controller->GetOrigin(), | 80 controller->GetOrigin(), |
| 100 GetContentSettingsTypes(controller.get())), | 81 GetContentSettingsTypes(controller.get())), |
| 101 controller_(std::move(controller)) { | 82 controller_(std::move(controller)) { |
| 102 DCHECK(controller_.get()); | 83 DCHECK(controller_.get()); |
| 103 DCHECK(controller_->IsAskingForAudio() || controller_->IsAskingForVideo()); | 84 DCHECK(controller_->IsAskingForAudio() || controller_->IsAskingForVideo()); |
| 104 } | 85 } |
| 105 | 86 |
| 106 void MediaStreamInfoBarDelegateAndroid::InfoBarDismissed() { | 87 void MediaStreamInfoBarDelegateAndroid::InfoBarDismissed() { |
| 107 // Deny the request if the infobar was closed with the 'x' button, since | 88 // Deny the request if the infobar was closed with the 'x' button, since |
| 108 // we don't want WebRTC to be waiting for an answer that will never come. | 89 // we don't want WebRTC to be waiting for an answer that will never come. |
| 109 controller_->Cancelled(); | 90 controller_->Cancelled(); |
| 110 } | 91 } |
| 111 | 92 |
| 112 MediaStreamInfoBarDelegateAndroid* | 93 MediaStreamInfoBarDelegateAndroid* |
| 113 MediaStreamInfoBarDelegateAndroid::AsMediaStreamInfoBarDelegateAndroid() { | 94 MediaStreamInfoBarDelegateAndroid::AsMediaStreamInfoBarDelegateAndroid() { |
| 114 return this; | 95 return this; |
| 115 } | 96 } |
| 116 | 97 |
| 117 bool MediaStreamInfoBarDelegateAndroid::Accept() { | 98 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); | |
| 136 if (GetPermissionCount() == 2) { | 99 if (GetPermissionCount() == 2) { |
| 137 controller_->GroupedRequestFinished( | 100 controller_->GroupedRequestFinished( |
| 138 GetAcceptState(kGroupedInfobarAudioPosition), | 101 GetAcceptState(kGroupedInfobarAudioPosition), |
| 139 GetAcceptState(kGroupedInfobarVideoPosition)); | 102 GetAcceptState(kGroupedInfobarVideoPosition)); |
| 140 } else { | 103 } else { |
| 141 DCHECK_EQ(1, GetPermissionCount()); | 104 DCHECK_EQ(1, GetPermissionCount()); |
| 142 controller_->PermissionGranted(); | 105 controller_->PermissionGranted(); |
| 143 } | 106 } |
| 144 return true; | 107 return true; |
| 145 } | 108 } |
| 146 | 109 |
| 147 bool MediaStreamInfoBarDelegateAndroid::Cancel() { | 110 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); | |
| 165 controller_->PermissionDenied(); | 111 controller_->PermissionDenied(); |
| 166 return true; | 112 return true; |
| 167 } | 113 } |
| OLD | NEW |