OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 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/ui/android/infobars/duplicate_download_infobar.h" | |
6 | |
7 #include <utility> | |
8 | |
9 #include "base/android/jni_android.h" | |
10 #include "base/android/jni_string.h" | |
11 #include "base/memory/ptr_util.h" | |
12 #include "chrome/browser/android/download/duplicate_download_infobar_delegate.h" | |
13 #include "jni/DuplicateDownloadInfoBar_jni.h" | |
14 | |
15 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.
| |
16 using chrome::android::DuplicateDownloadInfoBarDelegate; | |
17 | |
18 // static | |
19 std::unique_ptr<infobars::InfoBar> DuplicateDownloadInfoBar::CreateInfoBar( | |
20 std::unique_ptr<DuplicateDownloadInfoBarDelegate> delegate) { | |
21 return base::WrapUnique(new DuplicateDownloadInfoBar(std::move(delegate))); | |
22 } | |
23 | |
24 DuplicateDownloadInfoBar::~DuplicateDownloadInfoBar() { | |
25 } | |
26 | |
27 DuplicateDownloadInfoBar::DuplicateDownloadInfoBar( | |
28 std::unique_ptr<DuplicateDownloadInfoBarDelegate> delegate) | |
29 : InfoBarAndroid(std::move(delegate)) {} | |
30 | |
31 base::android::ScopedJavaLocalRef<jobject> | |
32 DuplicateDownloadInfoBar::CreateRenderInfoBar(JNIEnv* env) { | |
33 DuplicateDownloadInfoBarDelegate* delegate = GetDelegate(); | |
34 | |
35 ScopedJavaLocalRef<jstring> j_file_path = | |
36 base::android::ConvertUTF8ToJavaString(env, delegate->GetFilePath()); | |
37 ScopedJavaLocalRef<jstring> j_page_url = | |
38 base::android::ConvertUTF8ToJavaString(env, delegate->GetPageURL()); | |
39 base::android::ScopedJavaLocalRef<jobject> java_infobar( | |
40 Java_DuplicateDownloadInfoBar_createInfoBar( | |
41 env, j_file_path, delegate->IsOfflinePage(), j_page_url)); | |
42 return java_infobar; | |
43 } | |
44 | |
45 void DuplicateDownloadInfoBar::ProcessButton(int action) { | |
46 if (!owner()) | |
47 return; // We're closing; don't call anything, it might access the owner. | |
48 | |
49 DuplicateDownloadInfoBarDelegate* delegate = GetDelegate(); | |
50 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.
| |
51 if (delegate->Download()) | |
52 RemoveSelf(); | |
53 } else if (action == InfoBarAndroid::ACTION_CANCEL) { | |
54 if (delegate->Cancel()) | |
55 RemoveSelf(); | |
56 } else { | |
57 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.
| |
58 } | |
59 } | |
60 | |
61 DuplicateDownloadInfoBarDelegate* DuplicateDownloadInfoBar::GetDelegate() { | |
62 return static_cast<DuplicateDownloadInfoBarDelegate*>(delegate()); | |
63 } | |
OLD | NEW |