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

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

Issue 1993953002: [Offline pages] Adding expiration capability to OfflinePageModel (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebasing 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 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 } 500 }
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,
511 const base::Time& expiration_time) {
512 for (int64_t offline_id : offline_ids) {
513 auto iter = offline_pages_.find(offline_id);
514 if (iter == offline_pages_.end())
515 continue;
516
517 OfflinePageItem offline_page = iter->second;
518 offline_page.expiration_time = expiration_time;
519
520 store_->AddOrUpdateOfflinePage(
521 offline_page, base::Bind(&OfflinePageModel::OnExpirePageDone,
522 weak_ptr_factory_.GetWeakPtr(), offline_id,
523 expiration_time));
524 }
525 }
526
527 void OfflinePageModel::OnExpirePageDone(int64_t offline_id,
528 const base::Time& expiration_time,
529 bool success) {
530 // TODO(romax): Report UMA about successful expiration.
531 if (success) {
532 auto iter = offline_pages_.find(offline_id);
533 if (iter != offline_pages_.end())
534 iter->second.expiration_time = expiration_time;
535 }
536 }
537
510 ClientPolicyController* OfflinePageModel::GetPolicyController() { 538 ClientPolicyController* OfflinePageModel::GetPolicyController() {
511 return policy_controller_.get(); 539 return policy_controller_.get();
512 } 540 }
513 541
514 OfflinePageMetadataStore* OfflinePageModel::GetStoreForTesting() { 542 OfflinePageMetadataStore* OfflinePageModel::GetStoreForTesting() {
515 return store_.get(); 543 return store_.get();
516 } 544 }
517 545
518 OfflinePageStorageManager* OfflinePageModel::GetStorageManager() { 546 OfflinePageStorageManager* OfflinePageModel::GetStorageManager() {
519 return storage_manager_.get(); 547 return storage_manager_.get();
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 void OfflinePageModel::RunWhenLoaded(const base::Closure& task) { 854 void OfflinePageModel::RunWhenLoaded(const base::Closure& task) {
827 if (!is_loaded_) { 855 if (!is_loaded_) {
828 delayed_tasks_.push_back(task); 856 delayed_tasks_.push_back(task);
829 return; 857 return;
830 } 858 }
831 859
832 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); 860 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task);
833 } 861 }
834 862
835 } // namespace offline_pages 863 } // namespace offline_pages
OLDNEW
« no previous file with comments | « components/offline_pages/offline_page_model.h ('k') | components/offline_pages/offline_page_model_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698