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/chrome_download_manager_overwrite_info bar_delegate.h" | |
6 | |
7 #include "base/android/jni_android.h" | |
8 #include "base/android/jni_string.h" | |
9 #include "base/files/file_util.h" | |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "base/strings/stringprintf.h" | |
12 #include "chrome/browser/infobars/infobar_service.h" | |
13 #include "chrome/browser/ui/android/infobars/download_overwrite_infobar.h" | |
14 #include "components/infobars/core/infobar.h" | |
15 #include "content/public/browser/browser_thread.h" | |
16 #include "content/public/browser/web_contents.h" | |
17 | |
18 namespace chrome { | |
19 namespace android { | |
20 | |
21 ChromeDownloadManagerOverwriteInfoBarDelegate:: | |
22 ~ChromeDownloadManagerOverwriteInfoBarDelegate() { | |
23 } | |
24 | |
25 // static | |
26 void ChromeDownloadManagerOverwriteInfoBarDelegate::Create( | |
27 InfoBarService* infobar_service, | |
28 const base::FilePath& suggested_path, | |
29 const DownloadTargetDeterminerDelegate::FileSelectedCallback& callback) { | |
30 infobar_service->AddInfoBar(DownloadOverwriteInfoBar::CreateInfoBar( | |
31 make_scoped_ptr(new ChromeDownloadManagerOverwriteInfoBarDelegate( | |
32 suggested_path, callback)))); | |
33 } | |
34 | |
35 void ChromeDownloadManagerOverwriteInfoBarDelegate::OverwriteExistingFile() { | |
36 file_selected_callback_.Run(suggested_download_path_); | |
37 } | |
38 | |
39 void ChromeDownloadManagerOverwriteInfoBarDelegate::CreateNewFile() { | |
40 content::BrowserThread::PostTask( | |
41 content::BrowserThread::FILE, FROM_HERE, | |
42 base::Bind( | |
43 &ChromeDownloadManagerOverwriteInfoBarDelegate::CreateNewFileInternal, | |
44 suggested_download_path_, file_selected_callback_)); | |
45 } | |
46 | |
47 ChromeDownloadManagerOverwriteInfoBarDelegate:: | |
Ted C
2015/03/04 16:24:24
same ordering comment as the other file.
Changwan Ryu
2015/03/04 16:41:33
Done.
| |
48 ChromeDownloadManagerOverwriteInfoBarDelegate( | |
49 const base::FilePath& suggested_download_path, | |
50 const DownloadTargetDeterminerDelegate::FileSelectedCallback& | |
51 file_selected_callback) | |
52 : suggested_download_path_(suggested_download_path), | |
53 file_selected_callback_(file_selected_callback) { | |
54 } | |
55 | |
56 std::string ChromeDownloadManagerOverwriteInfoBarDelegate::GetFileName() const { | |
57 return suggested_download_path_.BaseName().value(); | |
58 } | |
59 | |
60 std::string ChromeDownloadManagerOverwriteInfoBarDelegate::GetDirName() const { | |
61 return suggested_download_path_.DirName().BaseName().value(); | |
62 } | |
63 | |
64 std::string ChromeDownloadManagerOverwriteInfoBarDelegate::GetDirFullPath() | |
65 const { | |
66 return suggested_download_path_.DirName().value(); | |
67 } | |
68 | |
69 void ChromeDownloadManagerOverwriteInfoBarDelegate::InfoBarDismissed() { | |
70 file_selected_callback_.Run(base::FilePath()); | |
71 } | |
72 | |
73 void ChromeDownloadManagerOverwriteInfoBarDelegate::CreateNewFileInternal( | |
74 const base::FilePath& suggested_download_path, | |
75 const DownloadTargetDeterminerDelegate::FileSelectedCallback& callback) { | |
76 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | |
77 int uniquifier = base::GetUniquePathNumber(suggested_download_path, | |
78 base::FilePath::StringType()); | |
79 base::FilePath new_path = suggested_download_path; | |
80 if (uniquifier > 0) { | |
81 new_path = suggested_download_path.InsertBeforeExtensionASCII( | |
82 base::StringPrintf(" (%d)", uniquifier)); | |
83 } | |
84 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | |
85 base::Bind(callback, new_path)); | |
86 } | |
87 | |
88 } // namespace android | |
89 } // namespace chrome | |
OLD | NEW |