OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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_duplicate_download_infobar_dele
gate.h" | 5 #include "chrome/browser/android/download/chrome_duplicate_download_infobar_dele
gate.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/android/path_utils.h" | 9 #include "base/android/path_utils.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
11 #include "chrome/browser/android/download/download_controller.h" | 11 #include "chrome/browser/android/download/download_controller.h" |
12 #include "chrome/browser/download/download_path_reservation_tracker.h" | 12 #include "chrome/browser/download/download_path_reservation_tracker.h" |
13 #include "chrome/browser/infobars/infobar_service.h" | 13 #include "chrome/browser/infobars/infobar_service.h" |
14 #include "chrome/browser/ui/android/infobars/duplicate_download_infobar.h" | 14 #include "chrome/browser/ui/android/infobars/duplicate_download_infobar.h" |
15 #include "components/infobars/core/infobar.h" | 15 #include "components/infobars/core/infobar.h" |
16 #include "content/public/browser/browser_context.h" | 16 #include "content/public/browser/browser_context.h" |
17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 void CreateNewFileDone( | 21 void CreateNewFileDone( |
22 const DownloadTargetDeterminerDelegate::FileSelectedCallback& callback, | 22 const DownloadTargetDeterminerDelegate::ConfirmationCallback& callback, |
23 const base::FilePath& target_path, bool verified) { | 23 PathValidationResult result, |
| 24 const base::FilePath& target_path) { |
24 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 25 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
25 if (verified) | 26 if (result == PathValidationResult::SUCCESS) |
26 callback.Run(target_path); | 27 callback.Run(DownloadConfirmationResult::CONFIRMED, target_path); |
27 else | 28 else |
28 callback.Run(base::FilePath()); | 29 callback.Run(DownloadConfirmationResult::FAILED, base::FilePath()); |
29 } | 30 } |
30 | 31 |
31 } // namespace | 32 } // namespace |
32 | 33 |
33 namespace chrome { | 34 namespace chrome { |
34 namespace android { | 35 namespace android { |
35 | 36 |
36 ChromeDuplicateDownloadInfoBarDelegate:: | 37 ChromeDuplicateDownloadInfoBarDelegate:: |
37 ~ChromeDuplicateDownloadInfoBarDelegate() { | 38 ~ChromeDuplicateDownloadInfoBarDelegate() { |
38 if (download_item_) | 39 if (download_item_) |
39 download_item_->RemoveObserver(this); | 40 download_item_->RemoveObserver(this); |
40 } | 41 } |
41 | 42 |
42 // static | 43 // static |
43 void ChromeDuplicateDownloadInfoBarDelegate::Create( | 44 void ChromeDuplicateDownloadInfoBarDelegate::Create( |
44 InfoBarService* infobar_service, | 45 InfoBarService* infobar_service, |
45 content::DownloadItem* download_item, | 46 content::DownloadItem* download_item, |
46 const base::FilePath& file_path, | 47 const base::FilePath& file_path, |
47 const DownloadTargetDeterminerDelegate::FileSelectedCallback& callback) { | 48 const DownloadTargetDeterminerDelegate::ConfirmationCallback& callback) { |
48 infobar_service->AddInfoBar(DuplicateDownloadInfoBar::CreateInfoBar( | 49 infobar_service->AddInfoBar(DuplicateDownloadInfoBar::CreateInfoBar( |
49 base::WrapUnique(new ChromeDuplicateDownloadInfoBarDelegate( | 50 base::WrapUnique(new ChromeDuplicateDownloadInfoBarDelegate( |
50 download_item, file_path, callback)))); | 51 download_item, file_path, callback)))); |
51 } | 52 } |
52 | 53 |
53 void ChromeDuplicateDownloadInfoBarDelegate::OnDownloadDestroyed( | 54 void ChromeDuplicateDownloadInfoBarDelegate::OnDownloadDestroyed( |
54 content::DownloadItem* download_item) { | 55 content::DownloadItem* download_item) { |
55 DCHECK_EQ(download_item, download_item_); | 56 DCHECK_EQ(download_item, download_item_); |
56 download_item_ = nullptr; | 57 download_item_ = nullptr; |
57 } | 58 } |
58 | 59 |
59 ChromeDuplicateDownloadInfoBarDelegate::ChromeDuplicateDownloadInfoBarDelegate( | 60 ChromeDuplicateDownloadInfoBarDelegate::ChromeDuplicateDownloadInfoBarDelegate( |
60 content::DownloadItem* download_item, | 61 content::DownloadItem* download_item, |
61 const base::FilePath& file_path, | 62 const base::FilePath& file_path, |
62 const DownloadTargetDeterminerDelegate::FileSelectedCallback& | 63 const DownloadTargetDeterminerDelegate::ConfirmationCallback& |
63 file_selected_callback) | 64 file_selected_callback) |
64 : download_item_(download_item), | 65 : download_item_(download_item), |
65 file_path_(file_path), | 66 file_path_(file_path), |
66 is_off_the_record_(download_item->GetBrowserContext()->IsOffTheRecord()), | 67 is_off_the_record_(download_item->GetBrowserContext()->IsOffTheRecord()), |
67 file_selected_callback_(file_selected_callback) { | 68 file_selected_callback_(file_selected_callback) { |
68 download_item_->AddObserver(this); | 69 download_item_->AddObserver(this); |
69 } | 70 } |
70 | 71 |
71 infobars::InfoBarDelegate::InfoBarIdentifier | 72 infobars::InfoBarDelegate::InfoBarIdentifier |
72 ChromeDuplicateDownloadInfoBarDelegate::GetIdentifier() const { | 73 ChromeDuplicateDownloadInfoBarDelegate::GetIdentifier() const { |
(...skipping 15 matching lines...) Expand all Loading... |
88 true, | 89 true, |
89 DownloadPathReservationTracker::UNIQUIFY, | 90 DownloadPathReservationTracker::UNIQUIFY, |
90 base::Bind(&CreateNewFileDone, file_selected_callback_)); | 91 base::Bind(&CreateNewFileDone, file_selected_callback_)); |
91 return true; | 92 return true; |
92 } | 93 } |
93 | 94 |
94 bool ChromeDuplicateDownloadInfoBarDelegate::Cancel() { | 95 bool ChromeDuplicateDownloadInfoBarDelegate::Cancel() { |
95 if (!download_item_) | 96 if (!download_item_) |
96 return true; | 97 return true; |
97 | 98 |
98 file_selected_callback_.Run(base::FilePath()); | 99 file_selected_callback_.Run(DownloadConfirmationResult::CANCELED, |
| 100 base::FilePath()); |
99 // TODO(qinmin): rename this histogram enum. | 101 // TODO(qinmin): rename this histogram enum. |
100 DownloadController::RecordDownloadCancelReason( | 102 DownloadController::RecordDownloadCancelReason( |
101 DownloadController::CANCEL_REASON_OVERWRITE_INFOBAR_DISMISSED); | 103 DownloadController::CANCEL_REASON_OVERWRITE_INFOBAR_DISMISSED); |
102 return true; | 104 return true; |
103 } | 105 } |
104 | 106 |
105 std::string ChromeDuplicateDownloadInfoBarDelegate::GetFilePath() const { | 107 std::string ChromeDuplicateDownloadInfoBarDelegate::GetFilePath() const { |
106 return file_path_.value(); | 108 return file_path_.value(); |
107 } | 109 } |
108 | 110 |
109 void ChromeDuplicateDownloadInfoBarDelegate::InfoBarDismissed() { | 111 void ChromeDuplicateDownloadInfoBarDelegate::InfoBarDismissed() { |
110 Cancel(); | 112 Cancel(); |
111 } | 113 } |
112 | 114 |
113 bool ChromeDuplicateDownloadInfoBarDelegate::IsOffTheRecord() const { | 115 bool ChromeDuplicateDownloadInfoBarDelegate::IsOffTheRecord() const { |
114 return is_off_the_record_; | 116 return is_off_the_record_; |
115 } | 117 } |
116 | 118 |
117 } // namespace android | 119 } // namespace android |
118 } // namespace chrome | 120 } // namespace chrome |
OLD | NEW |