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

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

Issue 2006923005: [Offline Pages] Two-step expiration in storage manager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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.h" 5 #include "components/offline_pages/offline_page_model.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 501
502 void OfflinePageModel::CheckForExternalFileDeletion() { 502 void OfflinePageModel::CheckForExternalFileDeletion() {
503 DCHECK(is_loaded_); 503 DCHECK(is_loaded_);
504 504
505 archive_manager_->GetAllArchives( 505 archive_manager_->GetAllArchives(
506 base::Bind(&OfflinePageModel::ScanForMissingArchiveFiles, 506 base::Bind(&OfflinePageModel::ScanForMissingArchiveFiles,
507 weak_ptr_factory_.GetWeakPtr())); 507 weak_ptr_factory_.GetWeakPtr()));
508 } 508 }
509 509
510 void OfflinePageModel::ExpirePages(const std::vector<int64_t>& offline_ids, 510 void OfflinePageModel::ExpirePages(const std::vector<int64_t>& offline_ids,
511 const base::Time& expiration_time) { 511 const base::Time& expiration_time,
512 const DeletePageCallback& callback) {
512 for (int64_t offline_id : offline_ids) { 513 for (int64_t offline_id : offline_ids) {
513 auto iter = offline_pages_.find(offline_id); 514 auto iter = offline_pages_.find(offline_id);
514 if (iter == offline_pages_.end()) 515 if (iter == offline_pages_.end())
515 continue; 516 continue;
516 517
517 OfflinePageItem offline_page = iter->second; 518 OfflinePageItem offline_page = iter->second;
518 offline_page.expiration_time = expiration_time; 519 offline_page.expiration_time = expiration_time;
519 520
520 store_->AddOrUpdateOfflinePage( 521 store_->AddOrUpdateOfflinePage(
521 offline_page, base::Bind(&OfflinePageModel::OnExpirePageDone, 522 offline_page, base::Bind(&OfflinePageModel::OnExpirePageDone,
522 weak_ptr_factory_.GetWeakPtr(), offline_id, 523 weak_ptr_factory_.GetWeakPtr(), offline_id,
523 expiration_time)); 524 expiration_time));
524 } 525 }
526 DeletePagesByOfflineId(offline_ids, callback);
jianli 2016/05/24 23:43:32 I don't think we want to delete offline page metad
romax 2016/05/25 20:05:23 Done.
527 }
528
529 void OfflinePageModel::RemovePageItems(
530 const std::vector<int64_t>& offline_ids,
531 const base::Callback<void(bool)>& callback) {
532 store_->RemoveOfflinePages(offline_ids, callback);
525 } 533 }
526 534
527 void OfflinePageModel::OnExpirePageDone(int64_t offline_id, 535 void OfflinePageModel::OnExpirePageDone(int64_t offline_id,
528 const base::Time& expiration_time, 536 const base::Time& expiration_time,
529 bool success) { 537 bool success) {
530 // TODO(romax): Report UMA about successful expiration. 538 // TODO(romax): Report UMA about successful expiration.
531 if (success) { 539 if (success) {
532 auto iter = offline_pages_.find(offline_id); 540 auto iter = offline_pages_.find(offline_id);
533 if (iter != offline_pages_.end()) 541 if (iter != offline_pages_.end())
534 iter->second.expiration_time = expiration_time; 542 iter->second.expiration_time = expiration_time;
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 688
681 void OfflinePageModel::OnDeleteArchiveFilesDone( 689 void OfflinePageModel::OnDeleteArchiveFilesDone(
682 const std::vector<int64_t>& offline_ids, 690 const std::vector<int64_t>& offline_ids,
683 const DeletePageCallback& callback, 691 const DeletePageCallback& callback,
684 bool success) { 692 bool success) {
685 if (!success) { 693 if (!success) {
686 InformDeletePageDone(callback, DeletePageResult::DEVICE_FAILURE); 694 InformDeletePageDone(callback, DeletePageResult::DEVICE_FAILURE);
687 return; 695 return;
688 } 696 }
689 697
690 store_->RemoveOfflinePages( 698 RemovePageItems(
691 offline_ids, 699 offline_ids,
692 base::Bind(&OfflinePageModel::OnRemoveOfflinePagesDone, 700 base::Bind(&OfflinePageModel::OnRemoveOfflinePagesDone,
693 weak_ptr_factory_.GetWeakPtr(), offline_ids, callback)); 701 weak_ptr_factory_.GetWeakPtr(), offline_ids, callback));
694 } 702 }
695 703
696 void OfflinePageModel::OnRemoveOfflinePagesDone( 704 void OfflinePageModel::OnRemoveOfflinePagesDone(
697 const std::vector<int64_t>& offline_ids, 705 const std::vector<int64_t>& offline_ids,
698 const DeletePageCallback& callback, 706 const DeletePageCallback& callback,
699 bool success) { 707 bool success) {
700 // Delete the offline page from the in memory cache regardless of success in 708 // Delete the offline page from the in memory cache regardless of success in
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
778 } 786 }
779 787
780 // No offline pages missing archive files, we can bail out. 788 // No offline pages missing archive files, we can bail out.
781 if (ids_of_pages_missing_archive_file.empty()) 789 if (ids_of_pages_missing_archive_file.empty())
782 return; 790 return;
783 791
784 DeletePageCallback remove_pages_done_callback( 792 DeletePageCallback remove_pages_done_callback(
785 base::Bind(&OfflinePageModel::OnRemoveOfflinePagesMissingArchiveFileDone, 793 base::Bind(&OfflinePageModel::OnRemoveOfflinePagesMissingArchiveFileDone,
786 weak_ptr_factory_.GetWeakPtr(), offline_client_id_pairs)); 794 weak_ptr_factory_.GetWeakPtr(), offline_client_id_pairs));
787 795
788 store_->RemoveOfflinePages( 796 RemovePageItems(ids_of_pages_missing_archive_file,
789 ids_of_pages_missing_archive_file, 797 base::Bind(&OfflinePageModel::OnRemoveOfflinePagesDone,
790 base::Bind(&OfflinePageModel::OnRemoveOfflinePagesDone, 798 weak_ptr_factory_.GetWeakPtr(),
791 weak_ptr_factory_.GetWeakPtr(), 799 ids_of_pages_missing_archive_file,
792 ids_of_pages_missing_archive_file, 800 remove_pages_done_callback));
793 remove_pages_done_callback));
794 } 801 }
795 802
796 void OfflinePageModel::OnRemoveOfflinePagesMissingArchiveFileDone( 803 void OfflinePageModel::OnRemoveOfflinePagesMissingArchiveFileDone(
797 const std::vector<std::pair<int64_t, ClientId>>& offline_client_id_pairs, 804 const std::vector<std::pair<int64_t, ClientId>>& offline_client_id_pairs,
798 DeletePageResult /* result */) { 805 DeletePageResult /* result */) {
799 for (const auto& id_pair : offline_client_id_pairs) { 806 for (const auto& id_pair : offline_client_id_pairs) {
800 FOR_EACH_OBSERVER(Observer, observers_, 807 FOR_EACH_OBSERVER(Observer, observers_,
801 OfflinePageDeleted(id_pair.first, id_pair.second)); 808 OfflinePageDeleted(id_pair.first, id_pair.second));
802 } 809 }
803 } 810 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 void OfflinePageModel::RunWhenLoaded(const base::Closure& task) { 861 void OfflinePageModel::RunWhenLoaded(const base::Closure& task) {
855 if (!is_loaded_) { 862 if (!is_loaded_) {
856 delayed_tasks_.push_back(task); 863 delayed_tasks_.push_back(task);
857 return; 864 return;
858 } 865 }
859 866
860 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); 867 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task);
861 } 868 }
862 869
863 } // namespace offline_pages 870 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698