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

Side by Side Diff: chrome/browser/android/download/chrome_download_manager_overwrite_infobar_delegate.cc

Issue 1882413004: Fix an issue that download file is not deleted when clicking Replace button (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2704
Patch Set: Created 4 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/android/download/chrome_download_manager_overwrite_info bar_delegate.h" 5 #include "chrome/browser/android/download/chrome_download_manager_overwrite_info bar_delegate.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
10 #include "base/android/jni_string.h" 10 #include "base/android/jni_string.h"
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
14 #include "chrome/browser/infobars/infobar_service.h" 14 #include "chrome/browser/infobars/infobar_service.h"
15 #include "chrome/browser/ui/android/infobars/download_overwrite_infobar.h" 15 #include "chrome/browser/ui/android/infobars/download_overwrite_infobar.h"
16 #include "components/infobars/core/infobar.h" 16 #include "components/infobars/core/infobar.h"
17 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
18 #include "content/public/browser/web_contents.h" 18 #include "content/public/browser/web_contents.h"
19 19
20 namespace {
21
22 void DeleteExistingDownloadFile(
23 const base::FilePath& download_path,
24 const DownloadTargetDeterminerDelegate::FileSelectedCallback& callback) {
25 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE);
26 base::File::Info info;
27 if (GetFileInfo(download_path, &info) && !info.is_directory)
28 base::DeleteFile(download_path, false);
29
30 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
31 base::Bind(callback, download_path));
32 }
33
34 } // namespace
35
20 namespace chrome { 36 namespace chrome {
21 namespace android { 37 namespace android {
22 38
23 ChromeDownloadManagerOverwriteInfoBarDelegate:: 39 ChromeDownloadManagerOverwriteInfoBarDelegate::
24 ~ChromeDownloadManagerOverwriteInfoBarDelegate() { 40 ~ChromeDownloadManagerOverwriteInfoBarDelegate() {
25 } 41 }
26 42
27 // static 43 // static
28 void ChromeDownloadManagerOverwriteInfoBarDelegate::Create( 44 void ChromeDownloadManagerOverwriteInfoBarDelegate::Create(
29 InfoBarService* infobar_service, 45 InfoBarService* infobar_service,
(...skipping 12 matching lines...) Expand all
42 : suggested_download_path_(suggested_download_path), 58 : suggested_download_path_(suggested_download_path),
43 file_selected_callback_(file_selected_callback) { 59 file_selected_callback_(file_selected_callback) {
44 } 60 }
45 61
46 infobars::InfoBarDelegate::InfoBarIdentifier 62 infobars::InfoBarDelegate::InfoBarIdentifier
47 ChromeDownloadManagerOverwriteInfoBarDelegate::GetIdentifier() const { 63 ChromeDownloadManagerOverwriteInfoBarDelegate::GetIdentifier() const {
48 return CHROME_DOWNLOAD_MANAGER_OVERWRITE_INFOBAR_DELEGATE; 64 return CHROME_DOWNLOAD_MANAGER_OVERWRITE_INFOBAR_DELEGATE;
49 } 65 }
50 66
51 bool ChromeDownloadManagerOverwriteInfoBarDelegate::OverwriteExistingFile() { 67 bool ChromeDownloadManagerOverwriteInfoBarDelegate::OverwriteExistingFile() {
52 file_selected_callback_.Run(suggested_download_path_); 68 content::BrowserThread::PostTask(
69 content::BrowserThread::FILE, FROM_HERE,
70 base::Bind(&DeleteExistingDownloadFile, suggested_download_path_,
71 file_selected_callback_));
53 return true; 72 return true;
54 } 73 }
55 74
56 bool ChromeDownloadManagerOverwriteInfoBarDelegate::CreateNewFile() { 75 bool ChromeDownloadManagerOverwriteInfoBarDelegate::CreateNewFile() {
57 content::BrowserThread::PostTask( 76 content::BrowserThread::PostTask(
58 content::BrowserThread::FILE, FROM_HERE, 77 content::BrowserThread::FILE, FROM_HERE,
59 base::Bind( 78 base::Bind(
60 &ChromeDownloadManagerOverwriteInfoBarDelegate::CreateNewFileInternal, 79 &ChromeDownloadManagerOverwriteInfoBarDelegate::CreateNewFileInternal,
61 suggested_download_path_, file_selected_callback_)); 80 suggested_download_path_, file_selected_callback_));
62 return true; 81 return true;
(...skipping 26 matching lines...) Expand all
89 if (uniquifier > 0) { 108 if (uniquifier > 0) {
90 new_path = suggested_download_path.InsertBeforeExtensionASCII( 109 new_path = suggested_download_path.InsertBeforeExtensionASCII(
91 base::StringPrintf(" (%d)", uniquifier)); 110 base::StringPrintf(" (%d)", uniquifier));
92 } 111 }
93 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, 112 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
94 base::Bind(callback, new_path)); 113 base::Bind(callback, new_path));
95 } 114 }
96 115
97 } // namespace android 116 } // namespace android
98 } // namespace chrome 117 } // namespace chrome
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698