OLD | NEW |
| (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/download/android_download_manager_overwrite_inf
obar_delegate.h" | |
6 | |
7 #include <memory> | |
8 | |
9 #include "base/android/jni_string.h" | |
10 #include "base/files/file_util.h" | |
11 #include "base/memory/ptr_util.h" | |
12 #include "base/strings/stringprintf.h" | |
13 #include "chrome/browser/android/download/chrome_download_delegate.h" | |
14 #include "chrome/browser/infobars/infobar_service.h" | |
15 #include "chrome/browser/ui/android/infobars/download_overwrite_infobar.h" | |
16 #include "components/infobars/core/infobar.h" | |
17 #include "content/public/browser/browser_thread.h" | |
18 #include "content/public/browser/web_contents.h" | |
19 | |
20 using base::android::ScopedJavaLocalRef; | |
21 | |
22 namespace chrome { | |
23 namespace android { | |
24 | |
25 AndroidDownloadManagerOverwriteInfoBarDelegate:: | |
26 ~AndroidDownloadManagerOverwriteInfoBarDelegate() { | |
27 } | |
28 | |
29 // static | |
30 void AndroidDownloadManagerOverwriteInfoBarDelegate::Create( | |
31 InfoBarService* infobar_service, | |
32 const std::string& file_name, | |
33 const std::string& dir_name, | |
34 const std::string& dir_full_path, | |
35 jobject chrome_download_delegate, | |
36 jobject download_info) { | |
37 infobar_service->AddInfoBar(DownloadOverwriteInfoBar::CreateInfoBar( | |
38 base::WrapUnique(new AndroidDownloadManagerOverwriteInfoBarDelegate( | |
39 file_name, dir_name, dir_full_path, chrome_download_delegate, | |
40 download_info)))); | |
41 } | |
42 | |
43 AndroidDownloadManagerOverwriteInfoBarDelegate:: | |
44 AndroidDownloadManagerOverwriteInfoBarDelegate( | |
45 const std::string& file_name, | |
46 const std::string& dir_name, | |
47 const std::string& dir_full_path, | |
48 jobject chrome_download_delegate, | |
49 jobject download_info) | |
50 : file_name_(file_name), | |
51 dir_name_(dir_name), | |
52 dir_full_path_(dir_full_path) { | |
53 JNIEnv* env = base::android::AttachCurrentThread(); | |
54 chrome_download_delegate_.Reset(env, chrome_download_delegate); | |
55 download_info_.Reset(env, download_info); | |
56 } | |
57 | |
58 infobars::InfoBarDelegate::InfoBarIdentifier | |
59 AndroidDownloadManagerOverwriteInfoBarDelegate::GetIdentifier() const { | |
60 return ANDROID_DOWNLOAD_MANAGER_OVERWRITE_INFOBAR_DELEGATE; | |
61 } | |
62 | |
63 bool AndroidDownloadManagerOverwriteInfoBarDelegate::OverwriteExistingFile() { | |
64 bool tab_closed = ChromeDownloadDelegate::EnqueueDownloadManagerRequest( | |
65 chrome_download_delegate_.obj(), true, download_info_.obj()); | |
66 return !tab_closed; | |
67 } | |
68 | |
69 bool AndroidDownloadManagerOverwriteInfoBarDelegate::CreateNewFile() { | |
70 bool tab_closed = ChromeDownloadDelegate::EnqueueDownloadManagerRequest( | |
71 chrome_download_delegate_.obj(), false, download_info_.obj()); | |
72 return !tab_closed; | |
73 } | |
74 | |
75 std::string AndroidDownloadManagerOverwriteInfoBarDelegate::GetFileName() | |
76 const { | |
77 return file_name_; | |
78 } | |
79 | |
80 std::string AndroidDownloadManagerOverwriteInfoBarDelegate::GetDirName() const { | |
81 return dir_name_; | |
82 } | |
83 | |
84 std::string AndroidDownloadManagerOverwriteInfoBarDelegate::GetDirFullPath() | |
85 const { | |
86 return dir_full_path_; | |
87 } | |
88 | |
89 } // namespace android | |
90 } // namespace chrome | |
OLD | NEW |