| 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/offline_page_model_impl.h" | 5 #include "components/offline_pages/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 750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 761 weak_ptr_factory_.GetWeakPtr(), archiver, | 761 weak_ptr_factory_.GetWeakPtr(), archiver, |
| 762 callback, offline_page_item)); | 762 callback, offline_page_item)); |
| 763 } | 763 } |
| 764 | 764 |
| 765 void OfflinePageModelImpl::OnAddOfflinePageDone( | 765 void OfflinePageModelImpl::OnAddOfflinePageDone( |
| 766 OfflinePageArchiver* archiver, | 766 OfflinePageArchiver* archiver, |
| 767 const SavePageCallback& callback, | 767 const SavePageCallback& callback, |
| 768 const OfflinePageItem& offline_page, | 768 const OfflinePageItem& offline_page, |
| 769 ItemActionStatus status) { | 769 ItemActionStatus status) { |
| 770 SavePageResult result; | 770 SavePageResult result; |
| 771 |
| 771 if (status == ItemActionStatus::SUCCESS) { | 772 if (status == ItemActionStatus::SUCCESS) { |
| 772 offline_pages_[offline_page.offline_id] = offline_page; | 773 offline_pages_[offline_page.offline_id] = offline_page; |
| 773 result = SavePageResult::SUCCESS; | 774 result = SavePageResult::SUCCESS; |
| 774 ReportPageHistogramAfterSave(offline_pages_, offline_page, | 775 ReportPageHistogramAfterSave(offline_pages_, offline_page, |
| 775 GetCurrentTime()); | 776 GetCurrentTime()); |
| 776 offline_event_logger_.RecordPageSaved( | 777 offline_event_logger_.RecordPageSaved( |
| 777 offline_page.client_id.name_space, offline_page.url.spec(), | 778 offline_page.client_id.name_space, offline_page.url.spec(), |
| 778 std::to_string(offline_page.offline_id)); | 779 std::to_string(offline_page.offline_id)); |
| 779 } else if (status == ItemActionStatus::ALREADY_EXISTS) { | 780 } else if (status == ItemActionStatus::ALREADY_EXISTS) { |
| 780 result = SavePageResult::ALREADY_EXISTS; | 781 result = SavePageResult::ALREADY_EXISTS; |
| 781 } else { | 782 } else { |
| 782 result = SavePageResult::STORE_FAILURE; | 783 result = SavePageResult::STORE_FAILURE; |
| 783 } | 784 } |
| 784 InformSavePageDone(callback, result, offline_page.client_id, | 785 InformSavePageDone(callback, result, offline_page.client_id, |
| 785 offline_page.offline_id); | 786 offline_page.offline_id); |
| 786 if (result == SavePageResult::SUCCESS) { | 787 if (result == SavePageResult::SUCCESS) { |
| 787 DeleteExistingPagesWithSameURL(offline_page); | 788 DeleteExistingPagesWithSameURL(offline_page); |
| 788 } else { | 789 } else { |
| 789 PostClearStorageIfNeededTask(); | 790 PostClearStorageIfNeededTask(); |
| 790 } | 791 } |
| 791 | 792 |
| 792 DeletePendingArchiver(archiver); | 793 DeletePendingArchiver(archiver); |
| 793 for (Observer& observer : observers_) | 794 for (Observer& observer : observers_) { |
| 794 observer.OfflinePageModelChanged(this); | 795 observer.OfflinePageAdded(this, result, result == SavePageResult::SUCCESS |
| 796 ? &offline_page |
| 797 : nullptr); |
| 798 } |
| 795 } | 799 } |
| 796 | 800 |
| 797 void OfflinePageModelImpl::OnMarkPageAccesseDone( | 801 void OfflinePageModelImpl::OnMarkPageAccesseDone( |
| 798 const OfflinePageItem& offline_page_item, | 802 const OfflinePageItem& offline_page_item, |
| 799 std::unique_ptr<OfflinePagesUpdateResult> result) { | 803 std::unique_ptr<OfflinePagesUpdateResult> result) { |
| 800 // Update the item in the cache only upon success. | 804 // Update the item in the cache only upon success. |
| 801 if (result->updated_items.size() > 0) | 805 if (result->updated_items.size() > 0) |
| 802 offline_pages_[offline_page_item.offline_id] = offline_page_item; | 806 offline_pages_[offline_page_item.offline_id] = offline_page_item; |
| 803 | 807 |
| 804 // No need to fire OfflinePageModelChanged event since updating access info | 808 // No need to fire OfflinePageModelChanged event since updating access info |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1082 } | 1086 } |
| 1083 | 1087 |
| 1084 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); | 1088 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); |
| 1085 } | 1089 } |
| 1086 | 1090 |
| 1087 base::Time OfflinePageModelImpl::GetCurrentTime() const { | 1091 base::Time OfflinePageModelImpl::GetCurrentTime() const { |
| 1088 return testing_clock_ ? testing_clock_->Now() : base::Time::Now(); | 1092 return testing_clock_ ? testing_clock_->Now() : base::Time::Now(); |
| 1089 } | 1093 } |
| 1090 | 1094 |
| 1091 } // namespace offline_pages | 1095 } // namespace offline_pages |
| OLD | NEW |