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 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 459 weak_ptr_factory_.GetWeakPtr(), predicate, callback)); | 459 weak_ptr_factory_.GetWeakPtr(), predicate, callback)); |
| 460 } | 460 } |
| 461 | 461 |
| 462 void OfflinePageModelImpl::DoDeleteCachedPagesByURLPredicate( | 462 void OfflinePageModelImpl::DoDeleteCachedPagesByURLPredicate( |
| 463 const UrlPredicate& predicate, | 463 const UrlPredicate& predicate, |
| 464 const DeletePageCallback& callback) { | 464 const DeletePageCallback& callback) { |
| 465 DCHECK(is_loaded_); | 465 DCHECK(is_loaded_); |
| 466 | 466 |
| 467 std::vector<int64_t> offline_ids; | 467 std::vector<int64_t> offline_ids; |
| 468 for (const auto& id_page_pair : offline_pages_) { | 468 for (const auto& id_page_pair : offline_pages_) { |
| 469 if (!IsUserRequestedPage(id_page_pair.second) && | 469 if (IsRemovedOnCacheReset(id_page_pair.second) && |
| 470 predicate.Run(id_page_pair.second.url)) | 470 predicate.Run(id_page_pair.second.url)) |
|
fgorski
2016/10/04 18:28:50
please add {}, because the condition of if spans m
chili
2016/10/04 20:20:25
Done.
| |
| 471 offline_ids.push_back(id_page_pair.first); | 471 offline_ids.push_back(id_page_pair.first); |
| 472 } | 472 } |
| 473 DoDeletePagesByOfflineId(offline_ids, callback); | 473 DoDeletePagesByOfflineId(offline_ids, callback); |
| 474 } | 474 } |
| 475 | 475 |
| 476 void OfflinePageModelImpl::CheckPagesExistOffline( | 476 void OfflinePageModelImpl::CheckPagesExistOffline( |
| 477 const std::set<GURL>& urls, | 477 const std::set<GURL>& urls, |
| 478 const CheckPagesExistOfflineCallback& callback) { | 478 const CheckPagesExistOfflineCallback& callback) { |
| 479 RunWhenLoaded( | 479 RunWhenLoaded( |
| 480 base::Bind(&OfflinePageModelImpl::CheckPagesExistOfflineAfterLoadDone, | 480 base::Bind(&OfflinePageModelImpl::CheckPagesExistOfflineAfterLoadDone, |
| (...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1119 } | 1119 } |
| 1120 | 1120 |
| 1121 void OfflinePageModelImpl::PostClearStorageIfNeededTask() { | 1121 void OfflinePageModelImpl::PostClearStorageIfNeededTask() { |
| 1122 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1122 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1123 FROM_HERE, base::Bind(&OfflinePageModelImpl::ClearStorageIfNeeded, | 1123 FROM_HERE, base::Bind(&OfflinePageModelImpl::ClearStorageIfNeeded, |
| 1124 weak_ptr_factory_.GetWeakPtr(), | 1124 weak_ptr_factory_.GetWeakPtr(), |
| 1125 base::Bind(&OfflinePageModelImpl::OnStorageCleared, | 1125 base::Bind(&OfflinePageModelImpl::OnStorageCleared, |
| 1126 weak_ptr_factory_.GetWeakPtr()))); | 1126 weak_ptr_factory_.GetWeakPtr()))); |
| 1127 } | 1127 } |
| 1128 | 1128 |
| 1129 bool OfflinePageModelImpl::IsUserRequestedPage( | 1129 bool OfflinePageModelImpl::IsRemovedOnCacheReset( |
| 1130 const OfflinePageItem& offline_page) const { | 1130 const OfflinePageItem& offline_page) const { |
| 1131 return (offline_page.client_id.name_space == kAsyncNamespace || | 1131 return policy_controller_->IsRemovedOnCacheReset( |
| 1132 offline_page.client_id.name_space == kDownloadNamespace); | 1132 offline_page.client_id.name_space); |
| 1133 } | 1133 } |
| 1134 | 1134 |
| 1135 void OfflinePageModelImpl::RunWhenLoaded(const base::Closure& task) { | 1135 void OfflinePageModelImpl::RunWhenLoaded(const base::Closure& task) { |
| 1136 if (!is_loaded_) { | 1136 if (!is_loaded_) { |
| 1137 delayed_tasks_.push_back(task); | 1137 delayed_tasks_.push_back(task); |
| 1138 return; | 1138 return; |
| 1139 } | 1139 } |
| 1140 | 1140 |
| 1141 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); | 1141 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); |
| 1142 } | 1142 } |
| 1143 | 1143 |
| 1144 base::Time OfflinePageModelImpl::GetCurrentTime() const { | 1144 base::Time OfflinePageModelImpl::GetCurrentTime() const { |
| 1145 return testing_clock_ ? testing_clock_->Now() : base::Time::Now(); | 1145 return testing_clock_ ? testing_clock_->Now() : base::Time::Now(); |
| 1146 } | 1146 } |
| 1147 | 1147 |
| 1148 } // namespace offline_pages | 1148 } // namespace offline_pages |
| OLD | NEW |