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

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

Issue 2344483003: Ask download manager to remove a download if it is overwritten by another (Closed)
Patch Set: Created 4 years, 3 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 | chrome/browser/android/download/download_manager_service.h » ('j') | 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/android/path_utils.h" 11 #include "base/android/path_utils.h"
12 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
15 #include "chrome/browser/android/download/download_controller.h" 15 #include "chrome/browser/android/download/download_controller.h"
16 #include "chrome/browser/android/download/download_manager_service.h"
16 #include "chrome/browser/infobars/infobar_service.h" 17 #include "chrome/browser/infobars/infobar_service.h"
17 #include "chrome/browser/ui/android/infobars/download_overwrite_infobar.h" 18 #include "chrome/browser/ui/android/infobars/download_overwrite_infobar.h"
18 #include "components/infobars/core/infobar.h" 19 #include "components/infobars/core/infobar.h"
20 #include "content/public/browser/browser_context.h"
19 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
20 #include "content/public/browser/web_contents.h" 22 #include "content/public/browser/web_contents.h"
21 23
22 namespace { 24 namespace {
23 25
26 void DeleteExistingDownloadFileDone(
27 bool is_off_the_record,
28 const base::Closure& callback) {
29 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
30 DownloadManagerService::GetInstance()->CheckForExternallyRemovedDownloads(
Theresa 2016/09/15 03:28:30 The check for externally removed downloads doesn't
qinmin 2016/09/15 22:18:56 I believe CheckForExternallyRemovedDownloads() doe
Theresa 2016/09/15 22:44:09 When I was adding the checks for externally downlo
qinmin 2016/09/15 23:14:00 Yes, I have tested this patch and it works as inte
Theresa 2016/09/15 23:50:32 Yes, that's what I expected. In #5 step, the downl
qinmin 2016/09/16 00:14:59 Thanks, Theresa. Yes, you are correct. The deletio
31 nullptr, nullptr, is_off_the_record);
32 callback.Run();
33 }
34
24 void DeleteExistingDownloadFile( 35 void DeleteExistingDownloadFile(
25 const base::FilePath& download_path, 36 const base::FilePath& download_path,
37 bool is_off_the_record,
26 const DownloadTargetDeterminerDelegate::FileSelectedCallback& callback) { 38 const DownloadTargetDeterminerDelegate::FileSelectedCallback& callback) {
27 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); 39 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE);
28 base::File::Info info; 40 base::File::Info info;
29 if (GetFileInfo(download_path, &info) && !info.is_directory) 41 if (GetFileInfo(download_path, &info) && !info.is_directory)
30 base::DeleteFile(download_path, false); 42 base::DeleteFile(download_path, false);
31 43
32 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, 44 content::BrowserThread::PostTask(
33 base::Bind(callback, download_path)); 45 content::BrowserThread::UI, FROM_HERE,
46 base::Bind(&DeleteExistingDownloadFileDone, is_off_the_record,
47 base::Bind(callback, download_path)));
34 } 48 }
35 49
36 void CreateNewFileDone( 50 void CreateNewFileDone(
37 const DownloadTargetDeterminerDelegate::FileSelectedCallback& callback, 51 const DownloadTargetDeterminerDelegate::FileSelectedCallback& callback,
38 const base::FilePath& target_path, bool verified) { 52 const base::FilePath& target_path, bool verified) {
39 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 53 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
40 if (verified) 54 if (verified)
41 callback.Run(target_path); 55 callback.Run(target_path);
42 else 56 else
43 callback.Run(base::FilePath()); 57 callback.Run(base::FilePath());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 file_selected_callback_(file_selected_callback) { 96 file_selected_callback_(file_selected_callback) {
83 download_item_->AddObserver(this); 97 download_item_->AddObserver(this);
84 } 98 }
85 99
86 infobars::InfoBarDelegate::InfoBarIdentifier 100 infobars::InfoBarDelegate::InfoBarIdentifier
87 ChromeDownloadManagerOverwriteInfoBarDelegate::GetIdentifier() const { 101 ChromeDownloadManagerOverwriteInfoBarDelegate::GetIdentifier() const {
88 return CHROME_DOWNLOAD_MANAGER_OVERWRITE_INFOBAR_DELEGATE; 102 return CHROME_DOWNLOAD_MANAGER_OVERWRITE_INFOBAR_DELEGATE;
89 } 103 }
90 104
91 bool ChromeDownloadManagerOverwriteInfoBarDelegate::OverwriteExistingFile() { 105 bool ChromeDownloadManagerOverwriteInfoBarDelegate::OverwriteExistingFile() {
106 if (!download_item_)
107 return true;
108
92 content::BrowserThread::PostTask( 109 content::BrowserThread::PostTask(
93 content::BrowserThread::FILE, FROM_HERE, 110 content::BrowserThread::FILE, FROM_HERE,
94 base::Bind(&DeleteExistingDownloadFile, suggested_download_path_, 111 base::Bind(&DeleteExistingDownloadFile, suggested_download_path_,
112 download_item_->GetBrowserContext()->IsOffTheRecord(),
95 file_selected_callback_)); 113 file_selected_callback_));
96 return true; 114 return true;
97 } 115 }
98 116
99 bool ChromeDownloadManagerOverwriteInfoBarDelegate::CreateNewFile() { 117 bool ChromeDownloadManagerOverwriteInfoBarDelegate::CreateNewFile() {
100 if (!download_item_) 118 if (!download_item_)
101 return true; 119 return true;
102 120
103 base::FilePath download_dir; 121 base::FilePath download_dir;
104 if (!base::android::GetDownloadsDirectory(&download_dir)) 122 if (!base::android::GetDownloadsDirectory(&download_dir))
(...skipping 23 matching lines...) Expand all
128 } 146 }
129 147
130 void ChromeDownloadManagerOverwriteInfoBarDelegate::InfoBarDismissed() { 148 void ChromeDownloadManagerOverwriteInfoBarDelegate::InfoBarDismissed() {
131 file_selected_callback_.Run(base::FilePath()); 149 file_selected_callback_.Run(base::FilePath());
132 DownloadController::RecordDownloadCancelReason( 150 DownloadController::RecordDownloadCancelReason(
133 DownloadController::CANCEL_REASON_OVERWRITE_INFOBAR_DISMISSED); 151 DownloadController::CANCEL_REASON_OVERWRITE_INFOBAR_DISMISSED);
134 } 152 }
135 153
136 } // namespace android 154 } // namespace android
137 } // namespace chrome 155 } // namespace chrome
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/android/download/download_manager_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698