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 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 InformDeletePageDone(callback, DeletePageResult::SUCCESS); | 421 InformDeletePageDone(callback, DeletePageResult::SUCCESS); |
422 return; | 422 return; |
423 } | 423 } |
424 | 424 |
425 archive_manager_->DeleteMultipleArchives( | 425 archive_manager_->DeleteMultipleArchives( |
426 paths_to_delete, | 426 paths_to_delete, |
427 base::Bind(&OfflinePageModelImpl::OnDeleteArchiveFilesDone, | 427 base::Bind(&OfflinePageModelImpl::OnDeleteArchiveFilesDone, |
428 weak_ptr_factory_.GetWeakPtr(), offline_ids, callback)); | 428 weak_ptr_factory_.GetWeakPtr(), offline_ids, callback)); |
429 } | 429 } |
430 | 430 |
| 431 void OfflinePageModelImpl::DeletePagesByClientIds( |
| 432 const std::vector<ClientId>& client_ids, |
| 433 const DeletePageCallback& callback) { |
| 434 RunWhenLoaded(base::Bind(&OfflinePageModelImpl::DoDeletePagesByClientIds, |
| 435 weak_ptr_factory_.GetWeakPtr(), client_ids, |
| 436 callback)); |
| 437 } |
| 438 |
| 439 void OfflinePageModelImpl::DoDeletePagesByClientIds( |
| 440 const std::vector<ClientId>& client_ids, |
| 441 const DeletePageCallback& callback) { |
| 442 std::set<ClientId> client_id_set(client_ids.begin(), client_ids.end()); |
| 443 |
| 444 std::vector<int64_t> offline_ids; |
| 445 for (const auto& page_pair : offline_pages_) { |
| 446 if (client_id_set.count(page_pair.second.client_id) > 0) |
| 447 offline_ids.emplace_back(page_pair.first); |
| 448 } |
| 449 |
| 450 DoDeletePagesByOfflineId(offline_ids, callback); |
| 451 } |
| 452 |
| 453 void OfflinePageModelImpl::GetPagesByClientIds( |
| 454 const std::vector<ClientId>& client_ids, |
| 455 const MultipleOfflinePageItemCallback& callback) { |
| 456 RunWhenLoaded(base::Bind(&OfflinePageModelImpl::DoGetPagesByClientIds, |
| 457 weak_ptr_factory_.GetWeakPtr(), client_ids, |
| 458 callback)); |
| 459 } |
| 460 |
| 461 void OfflinePageModelImpl::DoGetPagesByClientIds( |
| 462 const std::vector<ClientId>& client_ids, |
| 463 const MultipleOfflinePageItemCallback& callback) { |
| 464 std::set<ClientId> client_id_set(client_ids.begin(), client_ids.end()); |
| 465 |
| 466 std::vector<OfflinePageItem> result; |
| 467 for (const auto& page_pair : offline_pages_) { |
| 468 if (!page_pair.second.IsExpired() && |
| 469 client_id_set.count(page_pair.second.client_id) > 0) { |
| 470 result.emplace_back(page_pair.second); |
| 471 } |
| 472 } |
| 473 callback.Run(result); |
| 474 } |
| 475 |
431 void OfflinePageModelImpl::DeleteCachedPagesByURLPredicate( | 476 void OfflinePageModelImpl::DeleteCachedPagesByURLPredicate( |
432 const UrlPredicate& predicate, | 477 const UrlPredicate& predicate, |
433 const DeletePageCallback& callback) { | 478 const DeletePageCallback& callback) { |
434 RunWhenLoaded( | 479 RunWhenLoaded( |
435 base::Bind(&OfflinePageModelImpl::DoDeleteCachedPagesByURLPredicate, | 480 base::Bind(&OfflinePageModelImpl::DoDeleteCachedPagesByURLPredicate, |
436 weak_ptr_factory_.GetWeakPtr(), predicate, callback)); | 481 weak_ptr_factory_.GetWeakPtr(), predicate, callback)); |
437 } | 482 } |
438 | 483 |
439 void OfflinePageModelImpl::DoDeleteCachedPagesByURLPredicate( | 484 void OfflinePageModelImpl::DoDeleteCachedPagesByURLPredicate( |
440 const UrlPredicate& predicate, | 485 const UrlPredicate& predicate, |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
588 // stripped. | 633 // stripped. |
589 if (online_url_without_fragment == | 634 if (online_url_without_fragment == |
590 id_page_pair.second.url.ReplaceComponents(remove_params)) { | 635 id_page_pair.second.url.ReplaceComponents(remove_params)) { |
591 result.push_back(id_page_pair.second); | 636 result.push_back(id_page_pair.second); |
592 } | 637 } |
593 } | 638 } |
594 | 639 |
595 callback.Run(result); | 640 callback.Run(result); |
596 } | 641 } |
597 | 642 |
598 const OfflinePageItem* OfflinePageModelImpl::MaybeGetBestPageForOnlineURL( | |
599 const GURL& online_url) const { | |
600 const OfflinePageItem* result = nullptr; | |
601 for (const auto& id_page_pair : offline_pages_) { | |
602 if (id_page_pair.second.url == online_url && | |
603 !id_page_pair.second.IsExpired()) { | |
604 if (!result || id_page_pair.second.creation_time > result->creation_time) | |
605 result = &(id_page_pair.second); | |
606 } | |
607 } | |
608 return result; | |
609 } | |
610 | |
611 void OfflinePageModelImpl::CheckMetadataConsistency() { | 643 void OfflinePageModelImpl::CheckMetadataConsistency() { |
612 DCHECK(is_loaded_); | 644 DCHECK(is_loaded_); |
613 archive_manager_->GetAllArchives( | 645 archive_manager_->GetAllArchives( |
614 base::Bind(&OfflinePageModelImpl::CheckMetadataConsistencyForArchivePaths, | 646 base::Bind(&OfflinePageModelImpl::CheckMetadataConsistencyForArchivePaths, |
615 weak_ptr_factory_.GetWeakPtr())); | 647 weak_ptr_factory_.GetWeakPtr())); |
616 } | 648 } |
617 | 649 |
618 void OfflinePageModelImpl::ExpirePages( | 650 void OfflinePageModelImpl::ExpirePages( |
619 const std::vector<int64_t>& offline_ids, | 651 const std::vector<int64_t>& offline_ids, |
620 const base::Time& expiration_time, | 652 const base::Time& expiration_time, |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1048 } | 1080 } |
1049 | 1081 |
1050 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); | 1082 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); |
1051 } | 1083 } |
1052 | 1084 |
1053 base::Time OfflinePageModelImpl::GetCurrentTime() const { | 1085 base::Time OfflinePageModelImpl::GetCurrentTime() const { |
1054 return testing_clock_ ? testing_clock_->Now() : base::Time::Now(); | 1086 return testing_clock_ ? testing_clock_->Now() : base::Time::Now(); |
1055 } | 1087 } |
1056 | 1088 |
1057 } // namespace offline_pages | 1089 } // namespace offline_pages |
OLD | NEW |