Chromium Code Reviews| 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 778 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 789 kStorageManagerStartingDelay); | 789 kStorageManagerStartingDelay); |
| 790 } | 790 } |
| 791 | 791 |
| 792 void OfflinePageModelImpl::InformSavePageDone(const SavePageCallback& callback, | 792 void OfflinePageModelImpl::InformSavePageDone(const SavePageCallback& callback, |
| 793 SavePageResult result, | 793 SavePageResult result, |
| 794 const ClientId& client_id, | 794 const ClientId& client_id, |
| 795 int64_t offline_id) { | 795 int64_t offline_id) { |
| 796 ReportSavePageResultHistogramAfterSave(client_id, result); | 796 ReportSavePageResultHistogramAfterSave(client_id, result); |
| 797 archive_manager_->GetStorageStats( | 797 archive_manager_->GetStorageStats( |
| 798 base::Bind(&ReportStorageHistogramsAfterSave)); | 798 base::Bind(&ReportStorageHistogramsAfterSave)); |
| 799 // Remove other user initiated pages with same url if the new save request was | |
| 800 // user initiated. | |
| 801 if (result == SavePageResult::SUCCESS && | |
| 802 OfflinePageModel::IsUserInitiated(client_id)) { | |
|
Dmitry Titov
2016/06/16 04:07:15
So far, we seem to gravitate to a model where each
fgorski
2016/06/16 15:05:13
I think we already have the policy object which sh
| |
| 803 GetPagesByOnlineURL( | |
| 804 offline_pages_[offline_id].url, | |
| 805 base::Bind(&OfflinePageModelImpl::OnPagesFoundWithSameURL, | |
| 806 weak_ptr_factory_.GetWeakPtr(), client_id, offline_id)); | |
| 807 } | |
| 799 base::ThreadTaskRunnerHandle::Get()->PostTask( | 808 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 800 FROM_HERE, base::Bind(&OfflinePageModelImpl::ClearStorageIfNeeded, | 809 FROM_HERE, base::Bind(&OfflinePageModelImpl::ClearStorageIfNeeded, |
| 801 weak_ptr_factory_.GetWeakPtr(), | 810 weak_ptr_factory_.GetWeakPtr(), |
| 802 base::Bind(&OfflinePageModelImpl::OnStorageCleared, | 811 base::Bind(&OfflinePageModelImpl::OnStorageCleared, |
| 803 weak_ptr_factory_.GetWeakPtr()))); | 812 weak_ptr_factory_.GetWeakPtr()))); |
| 804 callback.Run(result, offline_id); | 813 callback.Run(result, offline_id); |
| 805 } | 814 } |
| 806 | 815 |
| 816 void OfflinePageModelImpl::OnPagesFoundWithSameURL( | |
| 817 const ClientId& client_id, | |
| 818 int64_t offline_id, | |
| 819 const MultipleOfflinePageItemResult& items) { | |
| 820 std::vector<int64_t> pages_to_delete; | |
| 821 for (const auto& item : items) { | |
| 822 if (item.offline_id != offline_id && | |
| 823 item.client_id.name_space == client_id.name_space) { | |
| 824 pages_to_delete.push_back(item.offline_id); | |
| 825 } | |
| 826 } | |
| 827 DeletePagesByOfflineId( | |
| 828 pages_to_delete, | |
| 829 base::Bind(&OfflinePageModelImpl::OnDeleteOldPagesWithSameURL, | |
| 830 weak_ptr_factory_.GetWeakPtr())); | |
| 831 } | |
| 832 | |
| 833 void OfflinePageModelImpl::OnDeleteOldPagesWithSameURL( | |
| 834 DeletePageResult result) { | |
| 835 // TODO(romax) Seems like nothing to do here. | |
|
Dmitry Titov
2016/06/16 04:07:15
UMA on failures would be interesting.
| |
| 836 } | |
| 837 | |
| 807 void OfflinePageModelImpl::DeletePendingArchiver( | 838 void OfflinePageModelImpl::DeletePendingArchiver( |
| 808 OfflinePageArchiver* archiver) { | 839 OfflinePageArchiver* archiver) { |
| 809 pending_archivers_.erase(std::find(pending_archivers_.begin(), | 840 pending_archivers_.erase(std::find(pending_archivers_.begin(), |
| 810 pending_archivers_.end(), archiver)); | 841 pending_archivers_.end(), archiver)); |
| 811 } | 842 } |
| 812 | 843 |
| 813 void OfflinePageModelImpl::OnDeleteArchiveFilesDone( | 844 void OfflinePageModelImpl::OnDeleteArchiveFilesDone( |
| 814 const std::vector<int64_t>& offline_ids, | 845 const std::vector<int64_t>& offline_ids, |
| 815 const DeletePageCallback& callback, | 846 const DeletePageCallback& callback, |
| 816 bool success) { | 847 bool success) { |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 983 void OfflinePageModelImpl::RunWhenLoaded(const base::Closure& task) { | 1014 void OfflinePageModelImpl::RunWhenLoaded(const base::Closure& task) { |
| 984 if (!is_loaded_) { | 1015 if (!is_loaded_) { |
| 985 delayed_tasks_.push_back(task); | 1016 delayed_tasks_.push_back(task); |
| 986 return; | 1017 return; |
| 987 } | 1018 } |
| 988 | 1019 |
| 989 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); | 1020 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); |
| 990 } | 1021 } |
| 991 | 1022 |
| 992 } // namespace offline_pages | 1023 } // namespace offline_pages |
| OLD | NEW |