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 "components/offline_pages/core/offline_page_model_impl.h" | 5 #include "components/offline_pages/core/offline_page_model_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
701 DeletePendingArchiver(archiver); | 701 DeletePendingArchiver(archiver); |
702 return; | 702 return; |
703 } | 703 } |
704 OfflinePageItem offline_page_item(url, offline_id, save_page_params.client_id, | 704 OfflinePageItem offline_page_item(url, offline_id, save_page_params.client_id, |
705 file_path, file_size, start_time); | 705 file_path, file_size, start_time); |
706 offline_page_item.title = title; | 706 offline_page_item.title = title; |
707 offline_page_item.original_url = save_page_params.original_url; | 707 offline_page_item.original_url = save_page_params.original_url; |
708 store_->AddOfflinePage(offline_page_item, | 708 store_->AddOfflinePage(offline_page_item, |
709 base::Bind(&OfflinePageModelImpl::OnAddOfflinePageDone, | 709 base::Bind(&OfflinePageModelImpl::OnAddOfflinePageDone, |
710 weak_ptr_factory_.GetWeakPtr(), archiver, | 710 weak_ptr_factory_.GetWeakPtr(), archiver, |
711 callback, offline_page_item)); | 711 file_path, callback, offline_page_item)); |
712 } | 712 } |
713 | 713 |
714 void OfflinePageModelImpl::OnAddOfflinePageDone( | 714 void OfflinePageModelImpl::OnAddOfflinePageDone( |
715 OfflinePageArchiver* archiver, | 715 OfflinePageArchiver* archiver, |
| 716 const base::FilePath& file_path, |
716 const SavePageCallback& callback, | 717 const SavePageCallback& callback, |
717 const OfflinePageItem& offline_page, | 718 const OfflinePageItem& offline_page, |
718 ItemActionStatus status) { | 719 ItemActionStatus status) { |
719 SavePageResult result; | 720 SavePageResult result; |
720 | 721 |
721 if (status == ItemActionStatus::SUCCESS) { | 722 if (status == ItemActionStatus::SUCCESS) { |
722 offline_pages_[offline_page.offline_id] = offline_page; | 723 offline_pages_[offline_page.offline_id] = offline_page; |
723 result = SavePageResult::SUCCESS; | 724 result = SavePageResult::SUCCESS; |
724 ReportPageHistogramAfterSave(policy_controller_.get(), offline_pages_, | 725 ReportPageHistogramAfterSave(policy_controller_.get(), offline_pages_, |
725 offline_page, GetCurrentTime()); | 726 offline_page, GetCurrentTime()); |
726 offline_event_logger_.RecordPageSaved( | 727 offline_event_logger_.RecordPageSaved( |
727 offline_page.client_id.name_space, offline_page.url.spec(), | 728 offline_page.client_id.name_space, offline_page.url.spec(), |
728 std::to_string(offline_page.offline_id)); | 729 std::to_string(offline_page.offline_id)); |
729 } else if (status == ItemActionStatus::ALREADY_EXISTS) { | 730 } else if (status == ItemActionStatus::ALREADY_EXISTS) { |
| 731 // Remove the orphaned archive. No callback necessary. |
| 732 archive_manager_->DeleteArchive(file_path, base::Bind([](bool) {})); |
730 result = SavePageResult::ALREADY_EXISTS; | 733 result = SavePageResult::ALREADY_EXISTS; |
731 } else { | 734 } else { |
732 result = SavePageResult::STORE_FAILURE; | 735 result = SavePageResult::STORE_FAILURE; |
733 } | 736 } |
734 InformSavePageDone(callback, result, offline_page.client_id, | 737 InformSavePageDone(callback, result, offline_page.client_id, |
735 offline_page.offline_id); | 738 offline_page.offline_id); |
736 if (result == SavePageResult::SUCCESS) { | 739 if (result == SavePageResult::SUCCESS) { |
737 DeleteExistingPagesWithSameURL(offline_page); | 740 DeleteExistingPagesWithSameURL(offline_page); |
738 } else { | 741 } else { |
739 PostClearStorageIfNeededTask(false /* delayed */); | 742 PostClearStorageIfNeededTask(false /* delayed */); |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1085 } | 1088 } |
1086 | 1089 |
1087 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); | 1090 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); |
1088 } | 1091 } |
1089 | 1092 |
1090 base::Time OfflinePageModelImpl::GetCurrentTime() const { | 1093 base::Time OfflinePageModelImpl::GetCurrentTime() const { |
1091 return testing_clock_ ? testing_clock_->Now() : base::Time::Now(); | 1094 return testing_clock_ ? testing_clock_->Now() : base::Time::Now(); |
1092 } | 1095 } |
1093 | 1096 |
1094 } // namespace offline_pages | 1097 } // namespace offline_pages |
OLD | NEW |