Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(860)

Side by Side Diff: chrome/browser/android/download_overwrite_infobar_delegate.cc

Issue 580043002: [Android] Prompt with infobar on filename conflict (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: also handles use cases from ChromeDownloadDelegate Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_overwrite_infobar_delegate.h"
6
7 #include "base/files/file_path.h"
8 #include "base/files/file_util.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/stringprintf.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/browser/infobars/infobar_service.h"
13 #include "chrome/browser/ui/android/infobars/download_overwrite_infobar.h"
14 #include "chrome/grit/generated_resources.h"
15 #include "components/infobars/core/infobar.h"
16 #include "content/public/browser/browser_thread.h"
17 #include "content/public/browser/download_item.h"
18 #include "content/public/browser/web_contents.h"
19 #include "grit/theme_resources.h"
20 #include "ui/base/l10n/l10n_util.h"
21
22 namespace chrome {
23 namespace android {
24
25 DownloadOverwriteInfoBarDelegate::~DownloadOverwriteInfoBarDelegate() {
26 }
27
28 // static
29 infobars::InfoBar* DownloadOverwriteInfoBarDelegate::Create(
30 content::DownloadItem* download,
Peter Kasting 2015/02/18 00:51:31 This argument is only used to calculate the InfoBa
Changwan Ryu 2015/02/18 07:15:02 Done.
31 const base::FilePath& suggested_path,
32 const DownloadTargetDeterminerDelegate::FileSelectedCallback& callback) {
33 content::WebContents* web_contents = download->GetWebContents();
34 if (!web_contents)
35 return NULL;
36
37 InfoBarService* infobar_service =
38 InfoBarService::FromWebContents(web_contents);
39
40 scoped_ptr<infobars::InfoBar> infobar =
Peter Kasting 2015/02/18 00:51:31 Nit: Inline this into the next statement to avoid
Changwan Ryu 2015/02/18 07:15:02 Done.
41 DownloadOverwriteInfoBar::CreateInfoBar(
42 make_scoped_ptr(new DownloadOverwriteInfoBarDelegate(
43 download, suggested_path, callback)));
44 return infobar_service->AddInfoBar(infobar.Pass());
45 }
46
47 bool DownloadOverwriteInfoBarDelegate::AcceptOverwrite() {
Peter Kasting 2015/02/18 00:51:31 If these two button-handler functions will always
Changwan Ryu 2015/02/18 07:15:02 Done.
48 file_selected_callback_.Run(suggested_download_path_);
49 return true;
50 }
51
52 void DownloadOverwriteInfoBarDelegate::CreateNewFileInternal(
53 const base::FilePath& suggested_download_path,
54 const DownloadTargetDeterminerDelegate::FileSelectedCallback& callback) {
55 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
56 int uniquifier = base::GetUniquePathNumber(suggested_download_path,
57 base::FilePath::StringType());
58 base::FilePath new_path;
59 if (uniquifier > 0) {
Peter Kasting 2015/02/18 00:51:31 What if uniquifer <= 0? Then it seems like you pa
Changwan Ryu 2015/02/18 07:15:02 Fixed to overwrite the existing file.
60 new_path = suggested_download_path.InsertBeforeExtensionASCII(
61 base::StringPrintf(" (%d)", uniquifier));
62 }
63 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
64 base::Bind(callback, new_path));
65 }
66
67 bool DownloadOverwriteInfoBarDelegate::CreateNewFile() {
68 content::BrowserThread::PostTask(
69 content::BrowserThread::FILE, FROM_HERE,
70 base::Bind(&DownloadOverwriteInfoBarDelegate::CreateNewFileInternal,
71 suggested_download_path_, file_selected_callback_));
72 return true;
73 }
74
75 std::string DownloadOverwriteInfoBarDelegate::GetFileName() const {
76 return suggested_download_path_.BaseName().value();
77 }
78
79 std::string DownloadOverwriteInfoBarDelegate::GetDirName() const {
80 return suggested_download_path_.DirName().BaseName().value();
81 }
82
83 std::string DownloadOverwriteInfoBarDelegate::GetDirFullPath() const {
84 return suggested_download_path_.DirName().value();
85 }
86
87 void DownloadOverwriteInfoBarDelegate::InfoBarDismissed() {
88 file_selected_callback_.Run(base::FilePath());
89 }
90
91 bool DownloadOverwriteInfoBarDelegate::ShouldExpire(
92 const NavigationDetails& details) const {
93 return false;
94 }
95
96 DownloadOverwriteInfoBarDelegate::DownloadOverwriteInfoBarDelegate(
97 content::DownloadItem* download,
Peter Kasting 2015/02/18 00:51:31 This argument seems to be unused.
Changwan Ryu 2015/02/18 07:15:02 Removed
98 const base::FilePath& suggested_download_path,
99 const DownloadTargetDeterminerDelegate::FileSelectedCallback&
100 file_selected_callback)
101 : suggested_download_path_(suggested_download_path),
102 file_selected_callback_(file_selected_callback) {
103 }
104
105 } // namespace android
106 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698