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/download_overwrite_infobar_delegate_na tive_initiated.h> | |
6 #include "base/files/file_util.h" | |
7 #include "base/memory/scoped_ptr.h" | |
8 #include "base/strings/stringprintf.h" | |
9 #include "chrome/browser/infobars/infobar_service.h" | |
10 #include "chrome/browser/ui/android/infobars/download_overwrite_infobar.h" | |
11 #include "components/infobars/core/infobar.h" | |
12 #include "content/public/browser/browser_thread.h" | |
13 #include "content/public/browser/web_contents.h" | |
14 | |
15 namespace chrome { | |
16 namespace android { | |
17 | |
18 DownloadOverwriteInfoBarDelegateNativeInitiated:: | |
19 ~DownloadOverwriteInfoBarDelegateNativeInitiated() { | |
20 } | |
21 | |
22 // static | |
23 void DownloadOverwriteInfoBarDelegateNativeInitiated::Create( | |
24 InfoBarService* infobar_service, | |
25 const base::FilePath& suggested_path, | |
26 const DownloadTargetDeterminerDelegate::FileSelectedCallback& callback) { | |
27 infobar_service->AddInfoBar(DownloadOverwriteInfoBar::CreateInfoBar( | |
28 make_scoped_ptr(new DownloadOverwriteInfoBarDelegateNativeInitiated( | |
29 suggested_path, callback)))); | |
30 } | |
31 | |
32 void DownloadOverwriteInfoBarDelegateNativeInitiated::OverwriteExistingFile() { | |
33 file_selected_callback_.Run(suggested_download_path_); | |
34 } | |
35 | |
36 void DownloadOverwriteInfoBarDelegateNativeInitiated::CreateNewFile() { | |
37 content::BrowserThread::PostTask( | |
38 content::BrowserThread::FILE, FROM_HERE, | |
39 base::Bind(&DownloadOverwriteInfoBarDelegateNativeInitiated:: | |
40 CreateNewFileInternal, | |
41 suggested_download_path_, file_selected_callback_)); | |
42 } | |
43 | |
44 std::string DownloadOverwriteInfoBarDelegateNativeInitiated::GetFileName() | |
45 const { | |
Peter Kasting
2015/02/25 06:24:57
Nit: Arguable, but I think this wrapping would be
Changwan Ryu
2015/03/02 14:46:37
Hmm... I tried it but git cl format reverses the c
| |
46 return suggested_download_path_.BaseName().value(); | |
47 } | |
48 | |
49 std::string DownloadOverwriteInfoBarDelegateNativeInitiated::GetDirName() | |
50 const { | |
51 return suggested_download_path_.DirName().BaseName().value(); | |
52 } | |
53 | |
54 std::string DownloadOverwriteInfoBarDelegateNativeInitiated::GetDirFullPath() | |
55 const { | |
56 return suggested_download_path_.DirName().value(); | |
57 } | |
58 | |
59 DownloadOverwriteInfoBarDelegateNativeInitiated:: | |
60 DownloadOverwriteInfoBarDelegateNativeInitiated( | |
61 const base::FilePath& suggested_download_path, | |
62 const DownloadTargetDeterminerDelegate::FileSelectedCallback& | |
63 file_selected_callback) | |
64 : suggested_download_path_(suggested_download_path), | |
65 file_selected_callback_(file_selected_callback) { | |
66 } | |
67 | |
68 bool DownloadOverwriteInfoBarDelegateNativeInitiated::ShouldExpire( | |
69 const infobars::InfoBarDelegate::NavigationDetails& details) const { | |
70 return false; | |
Peter Kasting
2015/02/25 06:24:57
Seems like method implementations like this which
Changwan Ryu
2015/03/02 14:46:36
Done.
| |
71 } | |
72 | |
73 void DownloadOverwriteInfoBarDelegateNativeInitiated::InfoBarDismissed() { | |
74 file_selected_callback_.Run(base::FilePath()); | |
75 } | |
76 | |
77 void DownloadOverwriteInfoBarDelegateNativeInitiated::CreateNewFileInternal( | |
78 const base::FilePath& suggested_download_path, | |
79 const DownloadTargetDeterminerDelegate::FileSelectedCallback& callback) { | |
80 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | |
81 int uniquifier = base::GetUniquePathNumber(suggested_download_path, | |
82 base::FilePath::StringType()); | |
83 base::FilePath new_path = suggested_download_path; | |
84 if (uniquifier > 0) { | |
85 new_path = suggested_download_path.InsertBeforeExtensionASCII( | |
86 base::StringPrintf(" (%d)", uniquifier)); | |
87 } | |
88 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | |
89 base::Bind(callback, new_path)); | |
90 } | |
91 | |
92 } // namespace android | |
93 } // namespace chrome | |
OLD | NEW |