Chromium Code Reviews| Index: components/offline_pages/offline_page_model_impl.cc |
| diff --git a/components/offline_pages/offline_page_model_impl.cc b/components/offline_pages/offline_page_model_impl.cc |
| index 4d6f1d7af3939455a3ab139c1001cfda815afc1a..813e72035d39466d414db8be941f2ac6280ae08e 100644 |
| --- a/components/offline_pages/offline_page_model_impl.cc |
| +++ b/components/offline_pages/offline_page_model_impl.cc |
| @@ -796,6 +796,17 @@ void OfflinePageModelImpl::InformSavePageDone(const SavePageCallback& callback, |
| ReportSavePageResultHistogramAfterSave(client_id, result); |
| archive_manager_->GetStorageStats( |
| base::Bind(&ReportStorageHistogramsAfterSave)); |
| + // Remove other user initiated pages with same url if the new save request was |
| + // user initiated. |
| + size_t pages_allowed = |
| + policy_controller_->GetPolicy(client_id.name_space).pages_allowed_per_url; |
| + if (result == SavePageResult::SUCCESS && pages_allowed > 0) { |
| + GetPagesByOnlineURL( |
| + offline_pages_[offline_id].url, |
| + base::Bind(&OfflinePageModelImpl::OnPagesFoundWithSameURL, |
| + weak_ptr_factory_.GetWeakPtr(), client_id, offline_id, |
| + pages_allowed)); |
| + } |
| base::ThreadTaskRunnerHandle::Get()->PostTask( |
|
fgorski
2016/06/17 22:51:06
It would probably make sense to run this code afte
romax
2016/06/20 20:04:41
Done.
|
| FROM_HERE, base::Bind(&OfflinePageModelImpl::ClearStorageIfNeeded, |
| weak_ptr_factory_.GetWeakPtr(), |
| @@ -804,6 +815,39 @@ void OfflinePageModelImpl::InformSavePageDone(const SavePageCallback& callback, |
| callback.Run(result, offline_id); |
| } |
| +void OfflinePageModelImpl::OnPagesFoundWithSameURL( |
| + const ClientId& client_id, |
| + int64_t offline_id, |
| + size_t pages_allowed, |
| + const MultipleOfflinePageItemResult& items) { |
| + std::vector<int64_t> pages_to_delete; |
| + for (const auto& item : items) { |
| + if (item.offline_id != offline_id && |
| + item.client_id.name_space == client_id.name_space) { |
| + pages_to_delete.push_back(item.offline_id); |
| + } |
| + } |
| + // Only keep |pages_allowed|-1 of most fresh pages, and delete others, by |
| + // sorting pages with fresh ones first and resize the vector. |
| + if (pages_to_delete.size() >= pages_allowed) { |
| + sort(pages_to_delete.begin(), pages_to_delete.end(), |
| + [this](int64_t a, int64_t b) -> bool { |
| + return this->offline_pages_[a].last_access_time > |
|
fgorski
2016/06/17 22:51:06
rewrite this to not use offline_pages_ so that it
romax
2016/06/20 20:04:41
Done.
|
| + this->offline_pages_[b].last_access_time; |
| + }); |
| + pages_to_delete.resize(pages_to_delete.size() - pages_allowed + 1); |
| + } |
| + DeletePagesByOfflineId( |
| + pages_to_delete, |
| + base::Bind(&OfflinePageModelImpl::OnDeleteOldPagesWithSameURL, |
| + weak_ptr_factory_.GetWeakPtr())); |
| +} |
| + |
| +void OfflinePageModelImpl::OnDeleteOldPagesWithSameURL( |
| + DeletePageResult result) { |
| + // TODO(romax) Seems like nothing to do here. |
| +} |
| + |
| void OfflinePageModelImpl::DeletePendingArchiver( |
| OfflinePageArchiver* archiver) { |
| pending_archivers_.erase(std::find(pending_archivers_.begin(), |