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

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: do null check on webcontents 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_context.h"
18 #include "content/public/browser/browser_thread.h"
19
20 namespace {
21
22 void CreateNewFileDone(
23 const DownloadTargetDeterminerDelegate::FileSelectedCallback& callback,
24 const base::FilePath& target_path, bool verified) {
25 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
26 if (verified)
27 callback.Run(target_path);
28 else
29 callback.Run(base::FilePath());
30 }
31
32 } // namespace
33
34 namespace chrome {
35 namespace android {
36
37 ChromeDuplicateDownloadInfoBarDelegate::
38 ~ChromeDuplicateDownloadInfoBarDelegate() {
39 if (download_item_)
40 download_item_->RemoveObserver(this);
41 }
42
43 // static
44 void ChromeDuplicateDownloadInfoBarDelegate::Create(
45 InfoBarService* infobar_service,
46 content::DownloadItem* download_item,
47 const base::FilePath& file_path,
48 const DownloadTargetDeterminerDelegate::FileSelectedCallback& callback) {
49 infobar_service->AddInfoBar(DuplicateDownloadInfoBar::CreateInfoBar(
50 base::WrapUnique(new ChromeDuplicateDownloadInfoBarDelegate(
51 download_item, file_path, 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 const DownloadTargetDeterminerDelegate::FileSelectedCallback&
64 file_selected_callback)
65 : download_item_(download_item),
66 file_path_(file_path),
67 is_off_the_record_(download_item->GetBrowserContext()->IsOffTheRecord()),
68 file_selected_callback_(file_selected_callback) {
69 download_item_->AddObserver(this);
70 }
71
72 infobars::InfoBarDelegate::InfoBarIdentifier
73 ChromeDuplicateDownloadInfoBarDelegate::GetIdentifier() const {
74 return CHROME_DUPLICATE_DOWNLOAD_INFOBAR_DELEGATE;
75 }
76
77 bool ChromeDuplicateDownloadInfoBarDelegate::Accept() {
78 if (!download_item_)
79 return true;
80
81 base::FilePath download_dir;
82 if (!base::android::GetDownloadsDirectory(&download_dir))
83 return true;
84
85 DownloadPathReservationTracker::GetReservedPath(
86 download_item_,
87 file_path_,
88 download_dir,
89 true,
90 DownloadPathReservationTracker::UNIQUIFY,
91 base::Bind(&CreateNewFileDone, file_selected_callback_));
92 return true;
93 }
94
95 bool ChromeDuplicateDownloadInfoBarDelegate::Cancel() {
96 if (!download_item_)
97 return true;
98
99 file_selected_callback_.Run(base::FilePath());
100 // TODO(qinmin): rename this histogram enum.
101 DownloadController::RecordDownloadCancelReason(
102 DownloadController::CANCEL_REASON_OVERWRITE_INFOBAR_DISMISSED);
103 return true;
104 }
105
106 std::string ChromeDuplicateDownloadInfoBarDelegate::GetFilePath() const {
107 return file_path_.value();
108 }
109
110 void ChromeDuplicateDownloadInfoBarDelegate::InfoBarDismissed() {
111 Cancel();
112 }
113
114 bool ChromeDuplicateDownloadInfoBarDelegate::IsOffTheRecord() const {
115 return is_off_the_record_;
116 }
117
118 } // namespace android
119 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698