Chromium Code Reviews| 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 // we don't want WebRTC to be waiting for an answer that will never come. | 94 // we don't want WebRTC to be waiting for an answer that will never come. |
| 94 controller_->Cancelled(); | 95 controller_->Cancelled(); |
| 95 } | 96 } |
| 96 | 97 |
| 97 MediaStreamInfoBarDelegateAndroid* | 98 MediaStreamInfoBarDelegateAndroid* |
| 98 MediaStreamInfoBarDelegateAndroid::AsMediaStreamInfoBarDelegateAndroid() { | 99 MediaStreamInfoBarDelegateAndroid::AsMediaStreamInfoBarDelegateAndroid() { |
| 99 return this; | 100 return this; |
| 100 } | 101 } |
| 101 | 102 |
| 102 bool MediaStreamInfoBarDelegateAndroid::Accept() { | 103 bool MediaStreamInfoBarDelegateAndroid::Accept() { |
| 104 bool persist_permission = true; | |
| 105 if (ShouldShowPersistenceToggle()) { | |
| 106 persist_permission = persist(); | |
| 107 | |
| 108 // TODO(dominickn): fold these metrics calls into | |
| 109 // PermissionUmaUtil::PermissionGranted. See crbug.com/638076. | |
| 110 if (GetPermissionCount() == 2) { | |
| 111 PermissionUmaUtil::PermissionPromptAcceptedWithPersistenceToggle( | |
| 112 controller_->GetPermissionTypeForContentSettingsType( | |
| 113 GetContentSettingType(kGroupedInfobarAudioPosition)), | |
| 114 persist_permission); | |
|
xhwang
2016/08/23 18:03:58
Can you have a helper function? This code is a bit
dominickn
2016/08/23 20:13:16
Done.
| |
| 115 | |
| 116 PermissionUmaUtil::PermissionPromptAcceptedWithPersistenceToggle( | |
| 117 controller_->GetPermissionTypeForContentSettingsType( | |
| 118 GetContentSettingType(kGroupedInfobarVideoPosition)), | |
| 119 persist_permission); | |
| 120 } else { | |
| 121 DCHECK_EQ(1, GetPermissionCount()); | |
| 122 PermissionUmaUtil::PermissionPromptAcceptedWithPersistenceToggle( | |
| 123 controller_->GetPermissionTypeForContentSettingsType( | |
| 124 GetContentSettingType(0)), | |
| 125 persist_permission); | |
| 126 } | |
| 127 } | |
| 128 | |
| 129 controller_->set_persist(persist_permission); | |
| 103 if (GetPermissionCount() == 2) { | 130 if (GetPermissionCount() == 2) { |
| 104 controller_->GroupedRequestFinished( | 131 controller_->GroupedRequestFinished( |
| 105 GetAcceptState(kGroupedInfobarAudioPosition), | 132 GetAcceptState(kGroupedInfobarAudioPosition), |
| 106 GetAcceptState(kGroupedInfobarVideoPosition)); | 133 GetAcceptState(kGroupedInfobarVideoPosition)); |
| 107 } else { | 134 } else { |
| 108 DCHECK_EQ(1, GetPermissionCount()); | 135 DCHECK_EQ(1, GetPermissionCount()); |
| 109 controller_->PermissionGranted(); | 136 controller_->PermissionGranted(); |
| 110 } | 137 } |
| 111 return true; | 138 return true; |
| 112 } | 139 } |
| 113 | 140 |
| 114 bool MediaStreamInfoBarDelegateAndroid::Cancel() { | 141 bool MediaStreamInfoBarDelegateAndroid::Cancel() { |
| 142 bool persist_permission = true; | |
| 143 if (ShouldShowPersistenceToggle()) { | |
| 144 persist_permission = persist(); | |
| 145 | |
| 146 // TODO(dominickn): fold these metrics calls into | |
| 147 // PermissionUmaUtil::PermissionGranted. See crbug.com/638076. | |
| 148 if (GetPermissionCount() == 2) { | |
| 149 PermissionUmaUtil::PermissionPromptDeniedWithPersistenceToggle( | |
| 150 controller_->GetPermissionTypeForContentSettingsType( | |
| 151 GetContentSettingType(kGroupedInfobarAudioPosition)), | |
| 152 persist_permission); | |
| 153 | |
| 154 PermissionUmaUtil::PermissionPromptDeniedWithPersistenceToggle( | |
| 155 controller_->GetPermissionTypeForContentSettingsType( | |
| 156 GetContentSettingType(kGroupedInfobarVideoPosition)), | |
| 157 persist_permission); | |
| 158 } else { | |
| 159 DCHECK_EQ(1, GetPermissionCount()); | |
| 160 PermissionUmaUtil::PermissionPromptDeniedWithPersistenceToggle( | |
| 161 controller_->GetPermissionTypeForContentSettingsType( | |
| 162 GetContentSettingType(0)), | |
| 163 persist_permission); | |
| 164 } | |
| 165 } | |
| 166 controller_->set_persist(persist_permission); | |
| 115 controller_->PermissionDenied(); | 167 controller_->PermissionDenied(); |
| 116 return true; | 168 return true; |
| 117 } | 169 } |
| OLD | NEW |