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

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: grouping inherited methods 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 bool is_off_the_record,
48 const DownloadTargetDeterminerDelegate::FileSelectedCallback& callback) {
49 infobar_service->AddInfoBar(DuplicateDownloadInfoBar::CreateInfoBar(
50 base::WrapUnique(new ChromeDuplicateDownloadInfoBarDelegate(
51 download_item, file_path, is_off_the_record, callback))));
52 }
53
54 void ChromeDuplicateDownloadInfoBarDelegate::OnDownloadDestroyed(
55 content::DownloadItem* download_item) {
56 DCHECK_EQ(download_item, download_item_);
57 download_item_ = nullptr;
58 }
59
60 ChromeDuplicateDownloadInfoBarDelegate::ChromeDuplicateDownloadInfoBarDelegate(
61 content::DownloadItem* download_item,
62 const base::FilePath& file_path,
63 bool is_off_the_record,
64 const DownloadTargetDeterminerDelegate::FileSelectedCallback&
65 file_selected_callback)
66 : download_item_(download_item),
67 file_path_(file_path),
68 is_off_the_record_(is_off_the_record),
69 file_selected_callback_(file_selected_callback) {
70 download_item_->AddObserver(this);
71 }
72
73 infobars::InfoBarDelegate::InfoBarIdentifier
74 ChromeDuplicateDownloadInfoBarDelegate::GetIdentifier() const {
75 return CHROME_DUPLICATE_DOWNLOAD_INFOBAR_DELEGATE;
76 }
77
78 bool ChromeDuplicateDownloadInfoBarDelegate::Accept() {
79 if (!download_item_)
80 return true;
81
82 base::FilePath download_dir;
83 if (!base::android::GetDownloadsDirectory(&download_dir))
84 return true;
85
86 DownloadPathReservationTracker::GetReservedPath(
87 download_item_,
88 file_path_,
89 download_dir,
90 true,
91 DownloadPathReservationTracker::UNIQUIFY,
92 base::Bind(&CreateNewFileDone, file_selected_callback_));
93 return true;
94 }
95
96 bool ChromeDuplicateDownloadInfoBarDelegate::Cancel() {
97 if (!download_item_)
98 return true;
99
100 file_selected_callback_.Run(base::FilePath());
101 // TODO(qinmin): rename this histogram enum.
102 DownloadController::RecordDownloadCancelReason(
103 DownloadController::CANCEL_REASON_OVERWRITE_INFOBAR_DISMISSED);
104 return true;
105 }
106
107 std::string ChromeDuplicateDownloadInfoBarDelegate::GetFilePath() const {
108 return file_path_.value();
109 }
110
111 void ChromeDuplicateDownloadInfoBarDelegate::InfoBarDismissed() {
112 Cancel();
113 }
114
115 bool ChromeDuplicateDownloadInfoBarDelegate::IsOffTheRecord() const {
116 return is_off_the_record_;
117 }
118
119 } // namespace android
120 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698