Chromium Code Reviews| Index: chrome/browser/ui/android/infobars/duplicate_download_infobar.cc |
| diff --git a/chrome/browser/ui/android/infobars/duplicate_download_infobar.cc b/chrome/browser/ui/android/infobars/duplicate_download_infobar.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..94c5d3e873064e1941b3bf8db54f485b0ff0d209 |
| --- /dev/null |
| +++ b/chrome/browser/ui/android/infobars/duplicate_download_infobar.cc |
| @@ -0,0 +1,63 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/ui/android/infobars/duplicate_download_infobar.h" |
| + |
| +#include <utility> |
| + |
| +#include "base/android/jni_android.h" |
| +#include "base/android/jni_string.h" |
| +#include "base/memory/ptr_util.h" |
| +#include "chrome/browser/android/download/duplicate_download_infobar_delegate.h" |
| +#include "jni/DuplicateDownloadInfoBar_jni.h" |
| + |
| +using base::android::ScopedJavaLocalRef; |
|
Peter Kasting
2016/11/05 00:26:57
Nit: Half the uses of this below already fully-qua
qinmin
2016/11/08 00:30:50
Done.
|
| +using chrome::android::DuplicateDownloadInfoBarDelegate; |
| + |
| +// static |
| +std::unique_ptr<infobars::InfoBar> DuplicateDownloadInfoBar::CreateInfoBar( |
| + std::unique_ptr<DuplicateDownloadInfoBarDelegate> delegate) { |
| + return base::WrapUnique(new DuplicateDownloadInfoBar(std::move(delegate))); |
| +} |
| + |
| +DuplicateDownloadInfoBar::~DuplicateDownloadInfoBar() { |
| +} |
| + |
| +DuplicateDownloadInfoBar::DuplicateDownloadInfoBar( |
| + std::unique_ptr<DuplicateDownloadInfoBarDelegate> delegate) |
| + : InfoBarAndroid(std::move(delegate)) {} |
| + |
| +base::android::ScopedJavaLocalRef<jobject> |
| +DuplicateDownloadInfoBar::CreateRenderInfoBar(JNIEnv* env) { |
| + DuplicateDownloadInfoBarDelegate* delegate = GetDelegate(); |
| + |
| + ScopedJavaLocalRef<jstring> j_file_path = |
| + base::android::ConvertUTF8ToJavaString(env, delegate->GetFilePath()); |
| + ScopedJavaLocalRef<jstring> j_page_url = |
| + base::android::ConvertUTF8ToJavaString(env, delegate->GetPageURL()); |
| + base::android::ScopedJavaLocalRef<jobject> java_infobar( |
| + Java_DuplicateDownloadInfoBar_createInfoBar( |
| + env, j_file_path, delegate->IsOfflinePage(), j_page_url)); |
| + return java_infobar; |
| +} |
| + |
| +void DuplicateDownloadInfoBar::ProcessButton(int action) { |
| + if (!owner()) |
| + return; // We're closing; don't call anything, it might access the owner. |
| + |
| + DuplicateDownloadInfoBarDelegate* delegate = GetDelegate(); |
| + if (action == InfoBarAndroid::ACTION_OK) { |
|
Peter Kasting
2016/11/05 00:26:57
Nit: A simpler to write this code might be:
con
qinmin
2016/11/08 00:30:50
Done.
|
| + if (delegate->Download()) |
| + RemoveSelf(); |
| + } else if (action == InfoBarAndroid::ACTION_CANCEL) { |
| + if (delegate->Cancel()) |
| + RemoveSelf(); |
| + } else { |
| + CHECK(false); |
|
Peter Kasting
2016/11/05 00:26:57
Nit: Prefer DCHECK to CHECK in cases where you're
qinmin
2016/11/08 00:30:50
Done.
|
| + } |
| +} |
| + |
| +DuplicateDownloadInfoBarDelegate* DuplicateDownloadInfoBar::GetDelegate() { |
| + return static_cast<DuplicateDownloadInfoBarDelegate*>(delegate()); |
| +} |