| 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/offline_pages/downloads/offline_page_infobar_de
legate.h" | 5 #include "chrome/browser/android/offline_pages/downloads/offline_page_infobar_de
legate.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "chrome/browser/infobars/infobar_service.h" | 8 #include "chrome/browser/infobars/infobar_service.h" |
| 9 #include "chrome/browser/ui/android/infobars/download_overwrite_infobar.h" | 9 #include "chrome/browser/ui/android/infobars/download_overwrite_infobar.h" |
| 10 | 10 |
| 11 namespace offline_pages { | 11 namespace offline_pages { |
| 12 | 12 |
| 13 // static | 13 // static |
| 14 void OfflinePageInfoBarDelegate::Create( | 14 void OfflinePageInfoBarDelegate::Create( |
| 15 const base::Closure& confirm_continuation, | 15 const base::Callback<void(Action)>& confirm_continuation, |
| 16 const std::string& downloads_label, |
| 16 const std::string& page_name, | 17 const std::string& page_name, |
| 17 content::WebContents* web_contents) { | 18 content::WebContents* web_contents) { |
| 18 InfoBarService::FromWebContents(web_contents) | 19 InfoBarService::FromWebContents(web_contents) |
| 19 ->AddInfoBar(DownloadOverwriteInfoBar::CreateInfoBar(base::WrapUnique( | 20 ->AddInfoBar(DownloadOverwriteInfoBar::CreateInfoBar( |
| 20 new OfflinePageInfoBarDelegate(confirm_continuation, page_name)))); | 21 base::WrapUnique(new OfflinePageInfoBarDelegate( |
| 22 confirm_continuation, downloads_label, page_name)))); |
| 21 } | 23 } |
| 22 | 24 |
| 23 OfflinePageInfoBarDelegate::~OfflinePageInfoBarDelegate() {} | 25 OfflinePageInfoBarDelegate::~OfflinePageInfoBarDelegate() {} |
| 24 | 26 |
| 25 OfflinePageInfoBarDelegate::OfflinePageInfoBarDelegate( | 27 OfflinePageInfoBarDelegate::OfflinePageInfoBarDelegate( |
| 26 const base::Closure& confirm_continuation, | 28 const base::Callback<void(Action)>& confirm_continuation, |
| 29 const std::string& downloads_label, |
| 27 const std::string& page_name) | 30 const std::string& page_name) |
| 28 : confirm_continuation_(confirm_continuation), page_name_(page_name) {} | 31 : confirm_continuation_(confirm_continuation), |
| 32 downloads_label_(downloads_label), |
| 33 page_name_(page_name) {} |
| 29 | 34 |
| 30 infobars::InfoBarDelegate::InfoBarIdentifier | 35 infobars::InfoBarDelegate::InfoBarIdentifier |
| 31 OfflinePageInfoBarDelegate::GetIdentifier() const { | 36 OfflinePageInfoBarDelegate::GetIdentifier() const { |
| 32 return OFFLINE_PAGE_INFOBAR_DELEGATE; | 37 return OFFLINE_PAGE_INFOBAR_DELEGATE; |
| 33 } | 38 } |
| 34 | 39 |
| 35 bool OfflinePageInfoBarDelegate::EqualsDelegate( | 40 bool OfflinePageInfoBarDelegate::EqualsDelegate( |
| 36 InfoBarDelegate* delegate) const { | 41 InfoBarDelegate* delegate) const { |
| 37 OfflinePageInfoBarDelegate* confirm_delegate = | 42 OfflinePageInfoBarDelegate* confirm_delegate = |
| 38 delegate->AsOfflinePageInfoBarDelegate(); | 43 delegate->AsOfflinePageInfoBarDelegate(); |
| 39 return confirm_delegate && GetFileName() == confirm_delegate->GetFileName(); | 44 return confirm_delegate && GetFileName() == confirm_delegate->GetFileName(); |
| 40 } | 45 } |
| 41 | 46 |
| 42 bool OfflinePageInfoBarDelegate::OverwriteExistingFile() { | 47 bool OfflinePageInfoBarDelegate::OverwriteExistingFile() { |
| 43 // TODO(dewittj): Downloads UI intends to remove this functionality. | 48 // TODO(dewittj): Downloads UI intends to remove this functionality. |
| 44 confirm_continuation_.Run(); | 49 confirm_continuation_.Run(Action::OVERWRITE); |
| 45 return true; | 50 return true; |
| 46 } | 51 } |
| 47 | 52 |
| 48 bool OfflinePageInfoBarDelegate::CreateNewFile() { | 53 bool OfflinePageInfoBarDelegate::CreateNewFile() { |
| 49 confirm_continuation_.Run(); | 54 confirm_continuation_.Run(Action::CREATE_NEW); |
| 50 return true; | 55 return true; |
| 51 } | 56 } |
| 52 | 57 |
| 53 std::string OfflinePageInfoBarDelegate::GetFileName() const { | 58 std::string OfflinePageInfoBarDelegate::GetFileName() const { |
| 54 return page_name_; | 59 return page_name_; |
| 55 } | 60 } |
| 56 | 61 |
| 57 std::string OfflinePageInfoBarDelegate::GetDirName() const { | 62 std::string OfflinePageInfoBarDelegate::GetDirName() const { |
| 58 // TODO(dewittj): When the downloads infobar can link to download home, use | 63 return downloads_label_; |
| 59 // that link. | |
| 60 return std::string(); | |
| 61 } | 64 } |
| 62 | 65 |
| 63 std::string OfflinePageInfoBarDelegate::GetDirFullPath() const { | 66 std::string OfflinePageInfoBarDelegate::GetDirFullPath() const { |
| 64 return std::string(); | 67 return std::string(); |
| 65 } | 68 } |
| 66 | 69 |
| 67 bool OfflinePageInfoBarDelegate::ShouldExpire( | 70 bool OfflinePageInfoBarDelegate::ShouldExpire( |
| 68 const NavigationDetails& details) const { | 71 const NavigationDetails& details) const { |
| 69 return InfoBarDelegate::ShouldExpire(details); | 72 return InfoBarDelegate::ShouldExpire(details); |
| 70 } | 73 } |
| 71 | 74 |
| 72 OfflinePageInfoBarDelegate* | 75 OfflinePageInfoBarDelegate* |
| 73 OfflinePageInfoBarDelegate::AsOfflinePageInfoBarDelegate() { | 76 OfflinePageInfoBarDelegate::AsOfflinePageInfoBarDelegate() { |
| 74 return this; | 77 return this; |
| 75 } | 78 } |
| 76 | 79 |
| 77 } // namespace offline_pages | 80 } // namespace offline_pages |
| OLD | NEW |