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

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

Issue 1997543002: [Useless] Hooking up storage manager in page model. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@shouldClean
Patch Set: changes related to another patch 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
« no previous file with comments | « components/offline_pages/offline_page_model.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 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"
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/metrics/histogram_macros.h" 14 #include "base/metrics/histogram_macros.h"
15 #include "base/optional.h" 15 #include "base/optional.h"
16 #include "base/rand_util.h" 16 #include "base/rand_util.h"
17 #include "base/sequenced_task_runner.h" 17 #include "base/sequenced_task_runner.h"
18 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
19 #include "base/threading/thread_task_runner_handle.h" 19 #include "base/threading/thread_task_runner_handle.h"
20 #include "base/time/time.h" 20 #include "base/time/time.h"
21 #include "components/offline_pages/archive_manager.h" 21 #include "components/offline_pages/archive_manager.h"
22 #include "components/offline_pages/client_policy_controller.h" 22 #include "components/offline_pages/client_policy_controller.h"
23 #include "components/offline_pages/offline_page_item.h" 23 #include "components/offline_pages/offline_page_item.h"
24 #include "components/offline_pages/offline_page_storage_manager.h" 24 #include "components/offline_pages/offline_page_storage_manager.h"
25 #include "components/offline_pages/proto/offline_pages.pb.h" 25 #include "components/offline_pages/proto/offline_pages.pb.h"
26 #include "url/gurl.h" 26 #include "url/gurl.h"
27 27
28 using ArchiverResult = offline_pages::OfflinePageArchiver::ArchiverResult; 28 using ArchiverResult = offline_pages::OfflinePageArchiver::ArchiverResult;
29 using ClearPagesCallback =
30 offline_pages::OfflinePageStorageManager::ClearPagesCallback;
29 31
30 namespace offline_pages { 32 namespace offline_pages {
31 33
32 namespace { 34 namespace {
33 35
34 // This enum is used in an UMA histogram. Hence the entries here shouldn't 36 // This enum is used in an UMA histogram. Hence the entries here shouldn't
35 // be deleted or re-ordered and new ones should be added to the end. 37 // be deleted or re-ordered and new ones should be added to the end.
36 enum ClearAllStatus { 38 enum ClearAllStatus {
37 CLEAR_ALL_SUCCEEDED, 39 CLEAR_ALL_SUCCEEDED,
38 STORE_RESET_FAILED, 40 STORE_RESET_FAILED,
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 } 503 }
502 504
503 void OfflinePageModel::CheckForExternalFileDeletion() { 505 void OfflinePageModel::CheckForExternalFileDeletion() {
504 DCHECK(is_loaded_); 506 DCHECK(is_loaded_);
505 507
506 archive_manager_->GetAllArchives( 508 archive_manager_->GetAllArchives(
507 base::Bind(&OfflinePageModel::ScanForMissingArchiveFiles, 509 base::Bind(&OfflinePageModel::ScanForMissingArchiveFiles,
508 weak_ptr_factory_.GetWeakPtr())); 510 weak_ptr_factory_.GetWeakPtr()));
509 } 511 }
510 512
513 void OfflinePageModel::ExpirePages(const ClearPagesCallback& callback) {
514 storage_manager_->ClearPagesIfNeeded(callback);
515 }
516
511 ClientPolicyController* OfflinePageModel::GetPolicyController() { 517 ClientPolicyController* OfflinePageModel::GetPolicyController() {
512 return policy_controller_.get(); 518 return policy_controller_.get();
513 } 519 }
514 520
515 OfflinePageMetadataStore* OfflinePageModel::GetStoreForTesting() { 521 OfflinePageMetadataStore* OfflinePageModel::GetStoreForTesting() {
516 return store_.get(); 522 return store_.get();
517 } 523 }
518 524
519 OfflinePageStorageManager* OfflinePageModel::GetStorageManager() { 525 OfflinePageStorageManager* OfflinePageModel::GetStorageManager() {
520 return storage_manager_.get(); 526 return storage_manager_.get();
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 627
622 // Create Storage Manager. 628 // Create Storage Manager.
623 storage_manager_.reset(new OfflinePageStorageManager( 629 storage_manager_.reset(new OfflinePageStorageManager(
624 this, GetPolicyController(), archive_manager_.get())); 630 this, GetPolicyController(), archive_manager_.get()));
625 631
626 // Run all the delayed tasks. 632 // Run all the delayed tasks.
627 for (const auto& delayed_task : delayed_tasks_) 633 for (const auto& delayed_task : delayed_tasks_)
628 delayed_task.Run(); 634 delayed_task.Run();
629 delayed_tasks_.clear(); 635 delayed_tasks_.clear();
630 636
637 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
638 FROM_HERE,
639 base::Bind(&OfflinePageModel::ExpirePages, weak_ptr_factory_.GetWeakPtr(),
640 base::Bind(&OfflinePageModel::OnExpiredPagesCleared,
641 weak_ptr_factory_.GetWeakPtr())),
642 base::TimeDelta::FromSeconds(20));
643
631 FOR_EACH_OBSERVER(Observer, observers_, OfflinePageModelLoaded(this)); 644 FOR_EACH_OBSERVER(Observer, observers_, OfflinePageModelLoaded(this));
632 645
633 CheckForExternalFileDeletion(); 646 CheckForExternalFileDeletion();
634 } 647 }
635 648
636 void OfflinePageModel::InformSavePageDone(const SavePageCallback& callback, 649 void OfflinePageModel::InformSavePageDone(const SavePageCallback& callback,
637 SavePageResult result, 650 SavePageResult result,
638 const ClientId& client_id, 651 const ClientId& client_id,
639 int64_t offline_id) { 652 int64_t offline_id) {
640 UMA_HISTOGRAM_ENUMERATION( 653 UMA_HISTOGRAM_ENUMERATION(
641 AddHistogramSuffix(client_id, "OfflinePages.SavePageResult").c_str(), 654 AddHistogramSuffix(client_id, "OfflinePages.SavePageResult").c_str(),
642 static_cast<int>(result), 655 static_cast<int>(result),
643 static_cast<int>(SavePageResult::RESULT_COUNT)); 656 static_cast<int>(SavePageResult::RESULT_COUNT));
644 archive_manager_->GetStorageStats( 657 archive_manager_->GetStorageStats(
645 base::Bind(&ReportStorageHistogramsAfterSave)); 658 base::Bind(&ReportStorageHistogramsAfterSave));
659 base::ThreadTaskRunnerHandle::Get()->PostTask(
660 FROM_HERE,
661 base::Bind(&OfflinePageModel::ExpirePages, weak_ptr_factory_.GetWeakPtr(),
662 base::Bind(&OfflinePageModel::OnExpiredPagesCleared,
663 weak_ptr_factory_.GetWeakPtr())));
646 callback.Run(result, offline_id); 664 callback.Run(result, offline_id);
647 } 665 }
648 666
649 void OfflinePageModel::DeletePendingArchiver(OfflinePageArchiver* archiver) { 667 void OfflinePageModel::DeletePendingArchiver(OfflinePageArchiver* archiver) {
650 pending_archivers_.erase(std::find( 668 pending_archivers_.erase(std::find(
651 pending_archivers_.begin(), pending_archivers_.end(), archiver)); 669 pending_archivers_.begin(), pending_archivers_.end(), archiver));
652 } 670 }
653 671
654 void OfflinePageModel::OnDeleteArchiveFilesDone( 672 void OfflinePageModel::OnDeleteArchiveFilesDone(
655 const std::vector<int64_t>& offline_ids, 673 const std::vector<int64_t>& offline_ids,
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 callback.Run(); 830 callback.Run();
813 } 831 }
814 832
815 void OfflinePageModel::CacheLoadedData( 833 void OfflinePageModel::CacheLoadedData(
816 const std::vector<OfflinePageItem>& offline_pages) { 834 const std::vector<OfflinePageItem>& offline_pages) {
817 offline_pages_.clear(); 835 offline_pages_.clear();
818 for (const auto& offline_page : offline_pages) 836 for (const auto& offline_page : offline_pages)
819 offline_pages_[offline_page.offline_id] = offline_page; 837 offline_pages_[offline_page.offline_id] = offline_page;
820 } 838 }
821 839
840 void OfflinePageModel::OnExpiredPagesCleared(
841 const int expired_page_count,
842 OfflinePageStorageManager::ClearStorageResult result) {
843 // TODO(romax) Add something here.
844 }
845
846 // static
822 int64_t OfflinePageModel::GenerateOfflineId() { 847 int64_t OfflinePageModel::GenerateOfflineId() {
823 return base::RandGenerator(std::numeric_limits<int64_t>::max()) + 1; 848 return base::RandGenerator(std::numeric_limits<int64_t>::max()) + 1;
824 } 849 }
825 850
826 void OfflinePageModel::RunWhenLoaded(const base::Closure& task) { 851 void OfflinePageModel::RunWhenLoaded(const base::Closure& task) {
827 if (!is_loaded_) { 852 if (!is_loaded_) {
828 delayed_tasks_.push_back(task); 853 delayed_tasks_.push_back(task);
829 return; 854 return;
830 } 855 }
831 856
832 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task); 857 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task);
833 } 858 }
834 859
835 } // namespace offline_pages 860 } // namespace offline_pages
OLDNEW
« no previous file with comments | « components/offline_pages/offline_page_model.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698