| 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 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 weak_ptr_factory_.GetWeakPtr(), predicate, callback)); | 464 weak_ptr_factory_.GetWeakPtr(), predicate, callback)); |
| 465 } | 465 } |
| 466 | 466 |
| 467 void OfflinePageModelImpl::DoDeleteCachedPagesByURLPredicate( | 467 void OfflinePageModelImpl::DoDeleteCachedPagesByURLPredicate( |
| 468 const UrlPredicate& predicate, | 468 const UrlPredicate& predicate, |
| 469 const DeletePageCallback& callback) { | 469 const DeletePageCallback& callback) { |
| 470 DCHECK(is_loaded_); | 470 DCHECK(is_loaded_); |
| 471 | 471 |
| 472 std::vector<int64_t> offline_ids; | 472 std::vector<int64_t> offline_ids; |
| 473 for (const auto& id_page_pair : offline_pages_) { | 473 for (const auto& id_page_pair : offline_pages_) { |
| 474 if (!IsUserRequestedPage(id_page_pair.second) && | 474 if (IsRemovedOnCacheReset(id_page_pair.second) && |
| 475 predicate.Run(id_page_pair.second.url)) | 475 predicate.Run(id_page_pair.second.url)) |
| 476 offline_ids.push_back(id_page_pair.first); | 476 offline_ids.push_back(id_page_pair.first); |
| 477 } | 477 } |
| 478 DoDeletePagesByOfflineId(offline_ids, callback); | 478 DoDeletePagesByOfflineId(offline_ids, callback); |
| 479 } | 479 } |
| 480 | 480 |
| 481 void OfflinePageModelImpl::CheckPagesExistOffline( | 481 void OfflinePageModelImpl::CheckPagesExistOffline( |
| 482 const std::set<GURL>& urls, | 482 const std::set<GURL>& urls, |
| 483 const CheckPagesExistOfflineCallback& callback) { | 483 const CheckPagesExistOfflineCallback& callback) { |
| 484 RunWhenLoaded( | 484 RunWhenLoaded( |
| (...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1121 } | 1121 } |
| 1122 | 1122 |
| 1123 void OfflinePageModelImpl::PostClearStorageIfNeededTask() { | 1123 void OfflinePageModelImpl::PostClearStorageIfNeededTask() { |
| 1124 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1124 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1125 FROM_HERE, base::Bind(&OfflinePageModelImpl::ClearStorageIfNeeded, | 1125 FROM_HERE, base::Bind(&OfflinePageModelImpl::ClearStorageIfNeeded, |
| 1126 weak_ptr_factory_.GetWeakPtr(), | 1126 weak_ptr_factory_.GetWeakPtr(), |
| 1127 base::Bind(&OfflinePageModelImpl::OnStorageCleared, | 1127 base::Bind(&OfflinePageModelImpl::OnStorageCleared, |
| 1128 weak_ptr_factory_.GetWeakPtr()))); | 1128 weak_ptr_factory_.GetWeakPtr()))); |
| 1129 } | 1129 } |
| 1130 | 1130 |
| 1131 bool OfflinePageModelImpl::IsUserRequestedPage( | 1131 bool OfflinePageModelImpl::IsRemovedOnCacheReset( |
| 1132 const OfflinePageItem& offline_page) const { | 1132 const OfflinePageItem& offline_page) const { |
| 1133 return (offline_page.client_id.name_space == kAsyncNamespace || | 1133 return policy_controller_->IsRemovedOnCacheReset( |
| 1134 offline_page.client_id.name_space == kDownloadNamespace); | 1134 offline_page.client_id.name_space); |
| 1135 } | 1135 } |
| 1136 | 1136 |
| 1137 void OfflinePageModelImpl::RunWhenLoaded(const base::Closure& task) { | 1137 void OfflinePageModelImpl::RunWhenLoaded(const base::Closure& task) { |
| 1138 if (!is_loaded_) { | 1138 if (!is_loaded_) { |
| 1139 delayed_tasks_.push_back(task); | 1139 delayed_tasks_.push_back(task); |
| 1140 return; | 1140 return; |
| 1141 } | 1141 } |
| 1142 | 1142 |
| 1143 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); | 1143 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); |
| 1144 } | 1144 } |
| 1145 | 1145 |
| 1146 base::Time OfflinePageModelImpl::GetCurrentTime() const { | 1146 base::Time OfflinePageModelImpl::GetCurrentTime() const { |
| 1147 return testing_clock_ ? testing_clock_->Now() : base::Time::Now(); | 1147 return testing_clock_ ? testing_clock_->Now() : base::Time::Now(); |
| 1148 } | 1148 } |
| 1149 | 1149 |
| 1150 } // namespace offline_pages | 1150 } // namespace offline_pages |
| OLD | NEW |