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

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

Issue 2478583004: implementation for new duplicate download UI (Closed)
Patch Set: Created 4 years, 1 month 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 2016 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/chrome_duplicate_download_infobar_dele gate.h"
6
7 #include <memory>
8
9 #include "base/android/path_utils.h"
10 #include "base/memory/ptr_util.h"
11 #include "base/strings/stringprintf.h"
12 #include "chrome/browser/android/download/download_controller.h"
13 #include "chrome/browser/download/download_path_reservation_tracker.h"
14 #include "chrome/browser/infobars/infobar_service.h"
15 #include "chrome/browser/ui/android/infobars/duplicate_download_infobar.h"
16 #include "components/infobars/core/infobar.h"
17 #include "content/public/browser/browser_thread.h"
18
19 namespace {
20
21 void CreateNewFileDone(
22 const DownloadTargetDeterminerDelegate::FileSelectedCallback& callback,
23 const base::FilePath& target_path, bool verified) {
24 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
25 if (verified)
26 callback.Run(target_path);
27 else
28 callback.Run(base::FilePath());
29 }
30
31 } // namespace
32
33 namespace chrome {
34 namespace android {
35
36 ChromeDuplicateDownloadInfoBarDelegate::
37 ~ChromeDuplicateDownloadInfoBarDelegate() {
38 if (download_item_)
39 download_item_->RemoveObserver(this);
40 }
41
42 // static
43 void ChromeDuplicateDownloadInfoBarDelegate::Create(
44 InfoBarService* infobar_service,
45 content::DownloadItem* download_item,
46 const base::FilePath& file_path,
47 const DownloadTargetDeterminerDelegate::FileSelectedCallback& callback) {
48 infobar_service->AddInfoBar(DuplicateDownloadInfoBar::CreateInfoBar(
49 base::WrapUnique(new ChromeDuplicateDownloadInfoBarDelegate(
50 download_item, file_path, callback))));
51 }
52
53 void ChromeDuplicateDownloadInfoBarDelegate::OnDownloadDestroyed(
54 content::DownloadItem* download_item) {
55 DCHECK_EQ(download_item, download_item_);
56 download_item_ = nullptr;
57 }
58
59 ChromeDuplicateDownloadInfoBarDelegate::ChromeDuplicateDownloadInfoBarDelegate(
60 content::DownloadItem* download_item,
61 const base::FilePath& file_path,
62 const DownloadTargetDeterminerDelegate::FileSelectedCallback&
63 file_selected_callback)
64 : download_item_(download_item),
65 file_path_(file_path),
66 file_selected_callback_(file_selected_callback) {
67 download_item_->AddObserver(this);
68 }
69
70 infobars::InfoBarDelegate::InfoBarIdentifier
71 ChromeDuplicateDownloadInfoBarDelegate::GetIdentifier() const {
72 return CHROME_DUPLICATE_DOWNLOAD_INFOBAR_DELEGATE;
73 }
74
75 bool ChromeDuplicateDownloadInfoBarDelegate::Download() {
76 if (!download_item_)
77 return true;
78
79 base::FilePath download_dir;
80 if (!base::android::GetDownloadsDirectory(&download_dir))
81 return true;
82
83 DownloadPathReservationTracker::GetReservedPath(
84 download_item_,
85 file_path_,
86 download_dir,
87 true,
88 DownloadPathReservationTracker::UNIQUIFY,
89 base::Bind(&CreateNewFileDone, file_selected_callback_));
90 return true;
91 }
92
93 bool ChromeDuplicateDownloadInfoBarDelegate::Cancel() {
94 if (!download_item_)
95 return true;
96
97 file_selected_callback_.Run(base::FilePath());
98 // TODO(qinmin): rename this histogram enum.
99 DownloadController::RecordDownloadCancelReason(
100 DownloadController::CANCEL_REASON_OVERWRITE_INFOBAR_DISMISSED);
101 return true;
102 }
103
104 std::string ChromeDuplicateDownloadInfoBarDelegate::GetFilePath() const {
105 return file_path_.value();
106 }
107
108 void ChromeDuplicateDownloadInfoBarDelegate::InfoBarDismissed() {
109 Cancel();
110 }
111
112 } // namespace android
113 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698