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 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 | 691 |
692 if (paths_to_delete.empty()) { | 692 if (paths_to_delete.empty()) { |
693 callback.Run(true); | 693 callback.Run(true); |
694 return; | 694 return; |
695 } | 695 } |
696 archive_manager_->DeleteMultipleArchives(paths_to_delete, callback); | 696 archive_manager_->DeleteMultipleArchives(paths_to_delete, callback); |
697 } | 697 } |
698 | 698 |
699 void OfflinePageModelImpl::OnExpirePageDone( | 699 void OfflinePageModelImpl::OnExpirePageDone( |
700 const base::Time& expiration_time, | 700 const base::Time& expiration_time, |
701 std::unique_ptr<StoreUpdateResult> result) { | 701 std::unique_ptr<OfflinePagesUpdateResult> result) { |
702 UMA_HISTOGRAM_BOOLEAN("OfflinePages.ExpirePage.StoreUpdateResult", | 702 UMA_HISTOGRAM_BOOLEAN("OfflinePages.ExpirePage.StoreUpdateResult", |
703 result->updated_items.size() > 0); | 703 result->updated_items.size() > 0); |
704 for (const auto& expired_page : result->updated_items) { | 704 for (const auto& expired_page : result->updated_items) { |
705 const auto& iter = offline_pages_.find(expired_page.offline_id); | 705 const auto& iter = offline_pages_.find(expired_page.offline_id); |
706 if (iter == offline_pages_.end()) | 706 if (iter == offline_pages_.end()) |
707 continue; | 707 continue; |
708 | 708 |
709 iter->second.expiration_time = expiration_time; | 709 iter->second.expiration_time = expiration_time; |
710 ClientId client_id = iter->second.client_id; | 710 ClientId client_id = iter->second.client_id; |
711 offline_event_logger_.RecordPageExpired( | 711 offline_event_logger_.RecordPageExpired( |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
807 } else { | 807 } else { |
808 PostClearStorageIfNeededTask(); | 808 PostClearStorageIfNeededTask(); |
809 } | 809 } |
810 | 810 |
811 DeletePendingArchiver(archiver); | 811 DeletePendingArchiver(archiver); |
812 FOR_EACH_OBSERVER(Observer, observers_, OfflinePageModelChanged(this)); | 812 FOR_EACH_OBSERVER(Observer, observers_, OfflinePageModelChanged(this)); |
813 } | 813 } |
814 | 814 |
815 void OfflinePageModelImpl::OnMarkPageAccesseDone( | 815 void OfflinePageModelImpl::OnMarkPageAccesseDone( |
816 const OfflinePageItem& offline_page_item, | 816 const OfflinePageItem& offline_page_item, |
817 std::unique_ptr<StoreUpdateResult> result) { | 817 std::unique_ptr<OfflinePagesUpdateResult> result) { |
818 // Update the item in the cache only upon success. | 818 // Update the item in the cache only upon success. |
819 if (result->updated_items.size() > 0) | 819 if (result->updated_items.size() > 0) |
820 offline_pages_[offline_page_item.offline_id] = offline_page_item; | 820 offline_pages_[offline_page_item.offline_id] = offline_page_item; |
821 | 821 |
822 // No need to fire OfflinePageModelChanged event since updating access info | 822 // No need to fire OfflinePageModelChanged event since updating access info |
823 // should not have any impact to the UI. | 823 // should not have any impact to the UI. |
824 } | 824 } |
825 | 825 |
826 void OfflinePageModelImpl::OnEnsureArchivesDirCreatedDone( | 826 void OfflinePageModelImpl::OnEnsureArchivesDirCreatedDone( |
827 const base::TimeTicks& start_time) { | 827 const base::TimeTicks& start_time) { |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
943 return; | 943 return; |
944 } | 944 } |
945 | 945 |
946 store_->RemoveOfflinePages( | 946 store_->RemoveOfflinePages( |
947 offline_ids, base::Bind(&OfflinePageModelImpl::OnRemoveOfflinePagesDone, | 947 offline_ids, base::Bind(&OfflinePageModelImpl::OnRemoveOfflinePagesDone, |
948 weak_ptr_factory_.GetWeakPtr(), callback)); | 948 weak_ptr_factory_.GetWeakPtr(), callback)); |
949 } | 949 } |
950 | 950 |
951 void OfflinePageModelImpl::OnRemoveOfflinePagesDone( | 951 void OfflinePageModelImpl::OnRemoveOfflinePagesDone( |
952 const DeletePageCallback& callback, | 952 const DeletePageCallback& callback, |
953 std::unique_ptr<StoreUpdateResult> result) { | 953 std::unique_ptr<OfflinePagesUpdateResult> result) { |
954 ReportPageHistogramsAfterDelete(offline_pages_, result->updated_items, | 954 ReportPageHistogramsAfterDelete(offline_pages_, result->updated_items, |
955 GetCurrentTime()); | 955 GetCurrentTime()); |
956 | 956 |
957 // This part of the loop is explicitly broken out, as it should be gone in | 957 // This part of the loop is explicitly broken out, as it should be gone in |
958 // fully asynchronous code. | 958 // fully asynchronous code. |
959 for (const auto& page : result->updated_items) { | 959 for (const auto& page : result->updated_items) { |
960 int64_t offline_id = page.offline_id; | 960 int64_t offline_id = page.offline_id; |
961 offline_event_logger_.RecordPageDeleted(std::to_string(offline_id)); | 961 offline_event_logger_.RecordPageDeleted(std::to_string(offline_id)); |
962 auto iter = offline_pages_.find(offline_id); | 962 auto iter = offline_pages_.find(offline_id); |
963 if (iter == offline_pages_.end()) | 963 if (iter == offline_pages_.end()) |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1144 } | 1144 } |
1145 | 1145 |
1146 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); | 1146 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); |
1147 } | 1147 } |
1148 | 1148 |
1149 base::Time OfflinePageModelImpl::GetCurrentTime() const { | 1149 base::Time OfflinePageModelImpl::GetCurrentTime() const { |
1150 return testing_clock_ ? testing_clock_->Now() : base::Time::Now(); | 1150 return testing_clock_ ? testing_clock_->Now() : base::Time::Now(); |
1151 } | 1151 } |
1152 | 1152 |
1153 } // namespace offline_pages | 1153 } // namespace offline_pages |
OLD | NEW |