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

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: addressed pkasting@'s comments 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/web_contents.h"
18 #include "grit/theme_resources.h"
19 #include "ui/base/l10n/l10n_util.h"
Peter Kasting 2015/02/18 21:32:28 Many of these #includes (e.g. utf_string_conversio
Changwan Ryu 2015/02/19 07:41:15 Done.
20
21 namespace chrome {
22 namespace android {
23
24 DownloadOverwriteInfoBarDelegate::~DownloadOverwriteInfoBarDelegate() {
25 }
26
27 // static
28 void DownloadOverwriteInfoBarDelegate::Create(
29 InfoBarService* infobar_service,
30 const base::FilePath& suggested_path,
31 const DownloadTargetDeterminerDelegate::FileSelectedCallback& callback) {
32 infobar_service->AddInfoBar(
33 DownloadOverwriteInfoBar::CreateInfoBar(make_scoped_ptr(
34 new DownloadOverwriteInfoBarDelegate(suggested_path, callback))));
35 }
36
37 void DownloadOverwriteInfoBarDelegate::OverwriteExistingFile() {
38 file_selected_callback_.Run(suggested_download_path_);
39 }
40
41 void DownloadOverwriteInfoBarDelegate::CreateNewFile() {
42 content::BrowserThread::PostTask(
43 content::BrowserThread::FILE, FROM_HERE,
44 base::Bind(&DownloadOverwriteInfoBarDelegate::CreateNewFileInternal,
45 suggested_download_path_, file_selected_callback_));
46 }
47
48 std::string DownloadOverwriteInfoBarDelegate::GetFileName() const {
49 return suggested_download_path_.BaseName().value();
50 }
51
52 std::string DownloadOverwriteInfoBarDelegate::GetDirName() const {
53 return suggested_download_path_.DirName().BaseName().value();
54 }
55
56 std::string DownloadOverwriteInfoBarDelegate::GetDirFullPath() const {
57 return suggested_download_path_.DirName().value();
58 }
59
60 DownloadOverwriteInfoBarDelegate::DownloadOverwriteInfoBarDelegate(
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 DownloadOverwriteInfoBarDelegate::ShouldExpire(
69 const NavigationDetails& details) const {
70 return false;
71 }
72
73 void DownloadOverwriteInfoBarDelegate::InfoBarDismissed() {
74 file_selected_callback_.Run(base::FilePath());
75 }
76
77 void DownloadOverwriteInfoBarDelegate::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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698