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

Side by Side Diff: chrome/browser/android/media/media_throttle_infobar_delegate.cc

Issue 2794283003: Remove MediaThrottler and MediaThrottleInfoBar (Closed)
Patch Set: Add comment Created 3 years, 8 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
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/android/media/media_throttle_infobar_delegate.h"
6
7 #include <stddef.h>
8 #include <utility>
9
10 #include "base/metrics/histogram_macros.h"
11 #include "chrome/browser/android/android_theme_resources.h"
12 #include "chrome/browser/infobars/infobar_service.h"
13 #include "chrome/grit/generated_resources.h"
14 #include "chrome/grit/theme_resources.h"
15 #include "components/infobars/core/infobar.h"
16 #include "components/strings/grit/components_strings.h"
17 #include "content/public/browser/web_contents.h"
18 #include "ui/base/l10n/l10n_util.h"
19 #include "url/gurl.h"
20
21 // static
22 void MediaThrottleInfoBarDelegate::Create(
23 content::WebContents* web_contents,
24 const DecodeRequestGrantedCallback& callback) {
25 InfoBarService* infobar_service =
26 InfoBarService::FromWebContents(web_contents);
27 std::unique_ptr<infobars::InfoBar> new_infobar(
28 infobar_service->CreateConfirmInfoBar(
29 std::unique_ptr<ConfirmInfoBarDelegate>(
30 new MediaThrottleInfoBarDelegate(callback))));
31
32 for (size_t i = 0; i < infobar_service->infobar_count(); ++i) {
33 infobars::InfoBar* old_infobar = infobar_service->infobar_at(i);
34 MediaThrottleInfoBarDelegate* delegate =
35 old_infobar->delegate()->AsMediaThrottleInfoBarDelegate();
36 if (delegate != nullptr) {
37 infobar_service->ReplaceInfoBar(old_infobar, std::move(new_infobar));
38 return;
39 }
40 }
41
42 infobar_service->AddInfoBar(std::move(new_infobar));
43 }
44
45 MediaThrottleInfoBarDelegate::MediaThrottleInfoBarDelegate(
46 const DecodeRequestGrantedCallback& callback)
47 : infobar_response_(UMA_THROTTLE_INFOBAR_NO_RESPONSE),
48 decode_granted_callback_(callback) {
49 }
50
51 MediaThrottleInfoBarDelegate::~MediaThrottleInfoBarDelegate() {
52 UMA_HISTOGRAM_ENUMERATION("Media.Android.ThrottleInfobarResponse",
53 infobar_response_,
54 UMA_THROTTLE_INFOBAR_RESPONSE_COUNT);
55 }
56
57 infobars::InfoBarDelegate::InfoBarIdentifier
58 MediaThrottleInfoBarDelegate::GetIdentifier() const {
59 return MEDIA_THROTTLE_INFOBAR_DELEGATE;
60 }
61
62 MediaThrottleInfoBarDelegate*
63 MediaThrottleInfoBarDelegate::AsMediaThrottleInfoBarDelegate() {
64 return this;
65 }
66
67 base::string16 MediaThrottleInfoBarDelegate::GetMessageText() const {
68 return l10n_util::GetStringUTF16(IDS_MEDIA_THROTTLE_INFOBAR_TEXT);
69 }
70
71 int MediaThrottleInfoBarDelegate::GetIconId() const {
72 return IDR_ANDROID_INFOBAR_WARNING;
73 }
74
75 base::string16 MediaThrottleInfoBarDelegate::GetButtonLabel(
76 InfoBarButton button) const {
77 return l10n_util::GetStringUTF16((button == BUTTON_OK) ?
78 IDS_MEDIA_THROTTLE_INFOBAR_BLOCK_BUTTON :
DaleCurtis 2017/04/04 23:38:29 Can delete these from https://cs.chromium.org/chro
tguilbert 2017/04/06 20:50:58 Done.
79 IDS_MEDIA_THROTTLE_INFOBAR_ALLOW_BUTTON);
80 }
81
82 bool MediaThrottleInfoBarDelegate::Accept() {
83 infobar_response_ = UMA_THROTTLE_INFOBAR_WAIT;
84 decode_granted_callback_.Run(false);
85 return true;
86 }
87
88 bool MediaThrottleInfoBarDelegate::Cancel() {
89 infobar_response_ = UMA_THROTTLE_INFOBAR_TRY_AGAIN;
90 decode_granted_callback_.Run(true);
91 return true;
92 }
93
94 void MediaThrottleInfoBarDelegate::InfoBarDismissed() {
95 infobar_response_ = UMA_THROTTLE_INFOBAR_DISMISSED;
96 decode_granted_callback_.Run(false);
97 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698