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

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: fixing unittest on win. Created 4 years, 6 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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 } 239 }
240 240
241 void OfflinePageModel::DoDeletePagesByOfflineId( 241 void OfflinePageModel::DoDeletePagesByOfflineId(
242 const std::vector<int64_t>& offline_ids, 242 const std::vector<int64_t>& offline_ids,
243 const DeletePageCallback& callback) { 243 const DeletePageCallback& callback) {
244 DCHECK(is_loaded_); 244 DCHECK(is_loaded_);
245 245
246 std::vector<base::FilePath> paths_to_delete; 246 std::vector<base::FilePath> paths_to_delete;
247 for (const auto& offline_id : offline_ids) { 247 for (const auto& offline_id : offline_ids) {
248 auto iter = offline_pages_.find(offline_id); 248 auto iter = offline_pages_.find(offline_id);
249 if (iter != offline_pages_.end()) { 249 if (iter != offline_pages_.end() && !iter->second.IsExpired()) {
250 paths_to_delete.push_back(iter->second.file_path); 250 paths_to_delete.push_back(iter->second.file_path);
251 } 251 }
252 } 252 }
253 253
254 if (paths_to_delete.empty()) { 254 if (paths_to_delete.empty()) {
255 InformDeletePageDone(callback, DeletePageResult::NOT_FOUND); 255 InformDeletePageDone(callback, DeletePageResult::NOT_FOUND);
256 return; 256 return;
257 } 257 }
258 258
259 archive_manager_->DeleteMultipleArchives( 259 archive_manager_->DeleteMultipleArchives(
(...skipping 241 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 base::Callback<void(bool)>& callback) {
513 std::vector<base::FilePath> paths_to_delete;
512 for (int64_t offline_id : offline_ids) { 514 for (int64_t offline_id : offline_ids) {
513 auto iter = offline_pages_.find(offline_id); 515 auto iter = offline_pages_.find(offline_id);
514 if (iter == offline_pages_.end()) 516 if (iter == offline_pages_.end())
515 continue; 517 continue;
516 518
517 OfflinePageItem offline_page = iter->second; 519 OfflinePageItem offline_page = iter->second;
520 paths_to_delete.push_back(offline_page.file_path);
518 offline_page.expiration_time = expiration_time; 521 offline_page.expiration_time = expiration_time;
519 522
520 store_->AddOrUpdateOfflinePage( 523 store_->AddOrUpdateOfflinePage(
521 offline_page, base::Bind(&OfflinePageModel::OnExpirePageDone, 524 offline_page, base::Bind(&OfflinePageModel::OnExpirePageDone,
522 weak_ptr_factory_.GetWeakPtr(), offline_id, 525 weak_ptr_factory_.GetWeakPtr(), offline_id,
523 expiration_time)); 526 expiration_time));
524 } 527 }
528 archive_manager_->DeleteMultipleArchives(paths_to_delete, callback);
jianli 2016/05/26 21:59:31 You can just check if paths_to_delete is empty and
romax 2016/05/27 00:41:37 Done.
525 } 529 }
526 530
527 void OfflinePageModel::OnExpirePageDone(int64_t offline_id, 531 void OfflinePageModel::OnExpirePageDone(int64_t offline_id,
528 const base::Time& expiration_time, 532 const base::Time& expiration_time,
529 bool success) { 533 bool success) {
530 // TODO(romax): Report UMA about successful expiration. 534 // TODO(romax): Report UMA about successful expiration.
531 if (success) { 535 if (success) {
532 auto iter = offline_pages_.find(offline_id); 536 auto iter = offline_pages_.find(offline_id);
533 if (iter != offline_pages_.end()) 537 if (iter != offline_pages_.end())
534 iter->second.expiration_time = expiration_time; 538 iter->second.expiration_time = expiration_time;
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 void OfflinePageModel::RunWhenLoaded(const base::Closure& task) { 858 void OfflinePageModel::RunWhenLoaded(const base::Closure& task) {
855 if (!is_loaded_) { 859 if (!is_loaded_) {
856 delayed_tasks_.push_back(task); 860 delayed_tasks_.push_back(task);
857 return; 861 return;
858 } 862 }
859 863
860 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); 864 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task);
861 } 865 }
862 866
863 } // namespace offline_pages 867 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698