Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(226)

Side by Side Diff: components/offline_pages/offline_page_model_impl.cc

Issue 2342443006: [Offline pages] Use the new policy bits (Closed)
Patch Set: i think i got it! Made sure it compiles Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/offline_pages/offline_page_model_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 weak_ptr_factory_.GetWeakPtr(), predicate, callback)); 436 weak_ptr_factory_.GetWeakPtr(), predicate, callback));
437 } 437 }
438 438
439 void OfflinePageModelImpl::DoDeleteCachedPagesByURLPredicate( 439 void OfflinePageModelImpl::DoDeleteCachedPagesByURLPredicate(
440 const UrlPredicate& predicate, 440 const UrlPredicate& predicate,
441 const DeletePageCallback& callback) { 441 const DeletePageCallback& callback) {
442 DCHECK(is_loaded_); 442 DCHECK(is_loaded_);
443 443
444 std::vector<int64_t> offline_ids; 444 std::vector<int64_t> offline_ids;
445 for (const auto& id_page_pair : offline_pages_) { 445 for (const auto& id_page_pair : offline_pages_) {
446 if (!IsUserRequestedPage(id_page_pair.second) && 446 if (IsRemovedOnCacheReset(id_page_pair.second) &&
447 predicate.Run(id_page_pair.second.url)) 447 predicate.Run(id_page_pair.second.url)) {
448 offline_ids.push_back(id_page_pair.first); 448 offline_ids.push_back(id_page_pair.first);
449 }
449 } 450 }
450 DoDeletePagesByOfflineId(offline_ids, callback); 451 DoDeletePagesByOfflineId(offline_ids, callback);
451 } 452 }
452 453
453 void OfflinePageModelImpl::CheckPagesExistOffline( 454 void OfflinePageModelImpl::CheckPagesExistOffline(
454 const std::set<GURL>& urls, 455 const std::set<GURL>& urls,
455 const CheckPagesExistOfflineCallback& callback) { 456 const CheckPagesExistOfflineCallback& callback) {
456 RunWhenLoaded( 457 RunWhenLoaded(
457 base::Bind(&OfflinePageModelImpl::CheckPagesExistOfflineAfterLoadDone, 458 base::Bind(&OfflinePageModelImpl::CheckPagesExistOfflineAfterLoadDone,
458 weak_ptr_factory_.GetWeakPtr(), urls, callback)); 459 weak_ptr_factory_.GetWeakPtr(), urls, callback));
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after
1051 } 1052 }
1052 1053
1053 void OfflinePageModelImpl::PostClearStorageIfNeededTask() { 1054 void OfflinePageModelImpl::PostClearStorageIfNeededTask() {
1054 base::ThreadTaskRunnerHandle::Get()->PostTask( 1055 base::ThreadTaskRunnerHandle::Get()->PostTask(
1055 FROM_HERE, base::Bind(&OfflinePageModelImpl::ClearStorageIfNeeded, 1056 FROM_HERE, base::Bind(&OfflinePageModelImpl::ClearStorageIfNeeded,
1056 weak_ptr_factory_.GetWeakPtr(), 1057 weak_ptr_factory_.GetWeakPtr(),
1057 base::Bind(&OfflinePageModelImpl::OnStorageCleared, 1058 base::Bind(&OfflinePageModelImpl::OnStorageCleared,
1058 weak_ptr_factory_.GetWeakPtr()))); 1059 weak_ptr_factory_.GetWeakPtr())));
1059 } 1060 }
1060 1061
1061 bool OfflinePageModelImpl::IsUserRequestedPage( 1062 bool OfflinePageModelImpl::IsRemovedOnCacheReset(
1062 const OfflinePageItem& offline_page) const { 1063 const OfflinePageItem& offline_page) const {
1063 return (offline_page.client_id.name_space == kAsyncNamespace || 1064 return policy_controller_->IsRemovedOnCacheReset(
1064 offline_page.client_id.name_space == kDownloadNamespace); 1065 offline_page.client_id.name_space);
1065 } 1066 }
1066 1067
1067 void OfflinePageModelImpl::RunWhenLoaded(const base::Closure& task) { 1068 void OfflinePageModelImpl::RunWhenLoaded(const base::Closure& task) {
1068 if (!is_loaded_) { 1069 if (!is_loaded_) {
1069 delayed_tasks_.push_back(task); 1070 delayed_tasks_.push_back(task);
1070 return; 1071 return;
1071 } 1072 }
1072 1073
1073 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); 1074 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task);
1074 } 1075 }
1075 1076
1076 base::Time OfflinePageModelImpl::GetCurrentTime() const { 1077 base::Time OfflinePageModelImpl::GetCurrentTime() const {
1077 return testing_clock_ ? testing_clock_->Now() : base::Time::Now(); 1078 return testing_clock_ ? testing_clock_->Now() : base::Time::Now();
1078 } 1079 }
1079 1080
1080 } // namespace offline_pages 1081 } // namespace offline_pages
OLDNEW
« no previous file with comments | « components/offline_pages/offline_page_model_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698