| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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/android/media/media_throttle_infobar_delegate.h" | 5 #include "chrome/browser/android/media/media_throttle_infobar_delegate.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> |
| 8 | 9 |
| 9 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| 10 #include "chrome/browser/infobars/infobar_service.h" | 11 #include "chrome/browser/infobars/infobar_service.h" |
| 11 #include "chrome/grit/generated_resources.h" | 12 #include "chrome/grit/generated_resources.h" |
| 12 #include "components/infobars/core/infobar.h" | 13 #include "components/infobars/core/infobar.h" |
| 13 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
| 14 #include "grit/components_strings.h" | 15 #include "grit/components_strings.h" |
| 15 #include "grit/theme_resources.h" | 16 #include "grit/theme_resources.h" |
| 16 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
| 17 #include "url/gurl.h" | 18 #include "url/gurl.h" |
| 18 | 19 |
| 19 // static | 20 // static |
| 20 void MediaThrottleInfoBarDelegate::Create( | 21 void MediaThrottleInfoBarDelegate::Create( |
| 21 content::WebContents* web_contents, | 22 content::WebContents* web_contents, |
| 22 const DecodeRequestGrantedCallback& callback) { | 23 const DecodeRequestGrantedCallback& callback) { |
| 23 InfoBarService* infobar_service = | 24 InfoBarService* infobar_service = |
| 24 InfoBarService::FromWebContents(web_contents); | 25 InfoBarService::FromWebContents(web_contents); |
| 25 scoped_ptr<infobars::InfoBar> new_infobar( | 26 scoped_ptr<infobars::InfoBar> new_infobar( |
| 26 infobar_service->CreateConfirmInfoBar(scoped_ptr<ConfirmInfoBarDelegate>( | 27 infobar_service->CreateConfirmInfoBar(scoped_ptr<ConfirmInfoBarDelegate>( |
| 27 new MediaThrottleInfoBarDelegate(callback)))); | 28 new MediaThrottleInfoBarDelegate(callback)))); |
| 28 | 29 |
| 29 for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { | 30 for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { |
| 30 infobars::InfoBar* old_infobar = infobar_service->infobar_at(i); | 31 infobars::InfoBar* old_infobar = infobar_service->infobar_at(i); |
| 31 MediaThrottleInfoBarDelegate* delegate = | 32 MediaThrottleInfoBarDelegate* delegate = |
| 32 old_infobar->delegate()->AsMediaThrottleInfoBarDelegate(); | 33 old_infobar->delegate()->AsMediaThrottleInfoBarDelegate(); |
| 33 if (delegate != nullptr) { | 34 if (delegate != nullptr) { |
| 34 infobar_service->ReplaceInfoBar(old_infobar, new_infobar.Pass()); | 35 infobar_service->ReplaceInfoBar(old_infobar, std::move(new_infobar)); |
| 35 return; | 36 return; |
| 36 } | 37 } |
| 37 } | 38 } |
| 38 | 39 |
| 39 infobar_service->AddInfoBar(new_infobar.Pass()); | 40 infobar_service->AddInfoBar(std::move(new_infobar)); |
| 40 } | 41 } |
| 41 | 42 |
| 42 MediaThrottleInfoBarDelegate::MediaThrottleInfoBarDelegate( | 43 MediaThrottleInfoBarDelegate::MediaThrottleInfoBarDelegate( |
| 43 const DecodeRequestGrantedCallback& callback) | 44 const DecodeRequestGrantedCallback& callback) |
| 44 : infobar_response_(UMA_THROTTLE_INFOBAR_NO_RESPONSE), | 45 : infobar_response_(UMA_THROTTLE_INFOBAR_NO_RESPONSE), |
| 45 decode_granted_callback_(callback) { | 46 decode_granted_callback_(callback) { |
| 46 } | 47 } |
| 47 | 48 |
| 48 MediaThrottleInfoBarDelegate::~MediaThrottleInfoBarDelegate() { | 49 MediaThrottleInfoBarDelegate::~MediaThrottleInfoBarDelegate() { |
| 49 UMA_HISTOGRAM_ENUMERATION("Media.Android.ThrottleInfobarResponse", | 50 UMA_HISTOGRAM_ENUMERATION("Media.Android.ThrottleInfobarResponse", |
| (...skipping 30 matching lines...) Expand all Loading... |
| 80 bool MediaThrottleInfoBarDelegate::Cancel() { | 81 bool MediaThrottleInfoBarDelegate::Cancel() { |
| 81 infobar_response_ = UMA_THROTTLE_INFOBAR_TRY_AGAIN; | 82 infobar_response_ = UMA_THROTTLE_INFOBAR_TRY_AGAIN; |
| 82 decode_granted_callback_.Run(true); | 83 decode_granted_callback_.Run(true); |
| 83 return true; | 84 return true; |
| 84 } | 85 } |
| 85 | 86 |
| 86 void MediaThrottleInfoBarDelegate::InfoBarDismissed() { | 87 void MediaThrottleInfoBarDelegate::InfoBarDismissed() { |
| 87 infobar_response_ = UMA_THROTTLE_INFOBAR_DISMISSED; | 88 infobar_response_ = UMA_THROTTLE_INFOBAR_DISMISSED; |
| 88 decode_granted_callback_.Run(false); | 89 decode_granted_callback_.Run(false); |
| 89 } | 90 } |
| OLD | NEW |