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

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

Issue 2015793002: [Offline Pages] Linking storage manager and model with UMAs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@wisp
Patch Set: fixing typo in histograms.xml 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 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_storage_manager.h" 5 #include "components/offline_pages/offline_page_storage_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/time/clock.h" 10 #include "base/time/clock.h"
(...skipping 10 matching lines...) Expand all
21 ArchiveManager* archive_manager) 21 ArchiveManager* archive_manager)
22 : client_(client), 22 : client_(client),
23 policy_controller_(policy_controller), 23 policy_controller_(policy_controller),
24 archive_manager_(archive_manager), 24 archive_manager_(archive_manager),
25 clock_(new base::DefaultClock()), 25 clock_(new base::DefaultClock()),
26 weak_ptr_factory_(this) {} 26 weak_ptr_factory_(this) {}
27 27
28 OfflinePageStorageManager::~OfflinePageStorageManager() {} 28 OfflinePageStorageManager::~OfflinePageStorageManager() {}
29 29
30 void OfflinePageStorageManager::ClearPagesIfNeeded( 30 void OfflinePageStorageManager::ClearPagesIfNeeded(
31 const ClearPagesCallback& callback) { 31 const ClearStorageCallback& callback) {
32 if (IsInProgress()) 32 if (IsInProgress())
33 return; 33 return;
34 clear_time_ = clock_->Now(); 34 clear_time_ = clock_->Now();
35 archive_manager_->GetStorageStats(base::Bind( 35 archive_manager_->GetStorageStats(base::Bind(
36 &OfflinePageStorageManager::OnGetStorageStatsDoneForClearingPages, 36 &OfflinePageStorageManager::OnGetStorageStatsDoneForClearingPages,
37 weak_ptr_factory_.GetWeakPtr(), callback)); 37 weak_ptr_factory_.GetWeakPtr(), callback));
38 } 38 }
39 39
40 void OfflinePageStorageManager::SetClockForTesting( 40 void OfflinePageStorageManager::SetClockForTesting(
41 std::unique_ptr<base::Clock> clock) { 41 std::unique_ptr<base::Clock> clock) {
42 clock_ = std::move(clock); 42 clock_ = std::move(clock);
43 } 43 }
44 44
45 void OfflinePageStorageManager::OnGetStorageStatsDoneForClearingPages( 45 void OfflinePageStorageManager::OnGetStorageStatsDoneForClearingPages(
46 const ClearPagesCallback& callback, 46 const ClearStorageCallback& callback,
47 const ArchiveManager::StorageStats& stats) { 47 const ArchiveManager::StorageStats& stats) {
48 DCHECK(IsInProgress()); 48 DCHECK(IsInProgress());
49 ClearMode mode = ShouldClearPages(stats); 49 ClearMode mode = ShouldClearPages(stats);
50 if (mode == ClearMode::NOT_NEEDED) { 50 if (mode == ClearMode::NOT_NEEDED) {
51 last_clear_time_ = clear_time_; 51 last_clear_time_ = clear_time_;
52 callback.Run(0, ClearStorageResult::UNNECESSARY); 52 callback.Run(0, ClearStorageResult::UNNECESSARY);
53 return; 53 return;
54 } 54 }
55 client_->GetAllPages( 55 client_->GetAllPages(
56 base::Bind(&OfflinePageStorageManager::OnGetAllPagesDoneForClearingPages, 56 base::Bind(&OfflinePageStorageManager::OnGetAllPagesDoneForClearingPages,
57 weak_ptr_factory_.GetWeakPtr(), callback, stats)); 57 weak_ptr_factory_.GetWeakPtr(), callback, stats));
58 } 58 }
59 59
60 void OfflinePageStorageManager::OnGetAllPagesDoneForClearingPages( 60 void OfflinePageStorageManager::OnGetAllPagesDoneForClearingPages(
61 const ClearPagesCallback& callback, 61 const ClearStorageCallback& callback,
62 const ArchiveManager::StorageStats& stats, 62 const ArchiveManager::StorageStats& stats,
63 const MultipleOfflinePageItemResult& pages) { 63 const MultipleOfflinePageItemResult& pages) {
64 std::vector<int64_t> page_ids_to_expire; 64 std::vector<int64_t> page_ids_to_expire;
65 std::vector<int64_t> page_ids_to_remove; 65 std::vector<int64_t> page_ids_to_remove;
66 GetPageIdsToClear(pages, stats, &page_ids_to_expire, &page_ids_to_remove); 66 GetPageIdsToClear(pages, stats, &page_ids_to_expire, &page_ids_to_remove);
67 client_->ExpirePages( 67 client_->ExpirePages(
68 page_ids_to_expire, clear_time_, 68 page_ids_to_expire, clear_time_,
69 base::Bind(&OfflinePageStorageManager::OnPagesExpired, 69 base::Bind(&OfflinePageStorageManager::OnPagesExpired,
70 weak_ptr_factory_.GetWeakPtr(), callback, 70 weak_ptr_factory_.GetWeakPtr(), callback,
71 page_ids_to_expire.size(), page_ids_to_remove)); 71 page_ids_to_expire.size(), page_ids_to_remove));
72 } 72 }
73 73
74 void OfflinePageStorageManager::OnPagesExpired( 74 void OfflinePageStorageManager::OnPagesExpired(
75 const ClearPagesCallback& callback, 75 const ClearStorageCallback& callback,
76 size_t pages_expired, 76 size_t pages_expired,
77 const std::vector<int64_t>& page_ids_to_remove, 77 const std::vector<int64_t>& page_ids_to_remove,
78 bool expiration_succeeded) { 78 bool expiration_succeeded) {
79 // We want to delete the outdated page records regardless the expiration 79 // We want to delete the outdated page records regardless the expiration
80 // succeeded or not. 80 // succeeded or not.
81 client_->DeletePagesByOfflineId( 81 client_->DeletePagesByOfflineId(
82 page_ids_to_remove, 82 page_ids_to_remove,
83 base::Bind(&OfflinePageStorageManager::OnOutdatedPagesCleared, 83 base::Bind(&OfflinePageStorageManager::OnOutdatedPagesCleared,
84 weak_ptr_factory_.GetWeakPtr(), callback, pages_expired, 84 weak_ptr_factory_.GetWeakPtr(), callback, pages_expired,
85 expiration_succeeded)); 85 expiration_succeeded));
86 } 86 }
87 87
88 void OfflinePageStorageManager::OnOutdatedPagesCleared( 88 void OfflinePageStorageManager::OnOutdatedPagesCleared(
89 const ClearPagesCallback& callback, 89 const ClearStorageCallback& callback,
90 size_t pages_cleared, 90 size_t pages_cleared,
91 bool expiration_succeeded, 91 bool expiration_succeeded,
92 DeletePageResult result) { 92 DeletePageResult result) {
93 ClearStorageResult clear_result = ClearStorageResult::SUCCESS; 93 ClearStorageResult clear_result = ClearStorageResult::SUCCESS;
94 if (!expiration_succeeded) { 94 if (!expiration_succeeded) {
95 clear_result = ClearStorageResult::EXPIRE_FAILURE; 95 clear_result = ClearStorageResult::EXPIRE_FAILURE;
96 if (result != DeletePageResult::SUCCESS) 96 if (result != DeletePageResult::SUCCESS)
97 clear_result = ClearStorageResult::EXPIRE_AND_DELETE_FAILURES; 97 clear_result = ClearStorageResult::EXPIRE_AND_DELETE_FAILURES;
98 } else if (result != DeletePageResult::SUCCESS) { 98 } else if (result != DeletePageResult::SUCCESS) {
99 clear_result = ClearStorageResult::DELETE_FAILURE; 99 clear_result = ClearStorageResult::DELETE_FAILURE;
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 const LifetimePolicy& policy = 200 const LifetimePolicy& policy =
201 policy_controller_->GetPolicy(page.client_id.name_space).lifetime_policy; 201 policy_controller_->GetPolicy(page.client_id.name_space).lifetime_policy;
202 return clear_time_ - page.last_access_time >= policy.expiration_period; 202 return clear_time_ - page.last_access_time >= policy.expiration_period;
203 } 203 }
204 204
205 bool OfflinePageStorageManager::IsInProgress() const { 205 bool OfflinePageStorageManager::IsInProgress() const {
206 return clear_time_ > last_clear_time_; 206 return clear_time_ > last_clear_time_;
207 } 207 }
208 208
209 } // namespace offline_pages 209 } // namespace offline_pages
OLDNEW
« no previous file with comments | « components/offline_pages/offline_page_storage_manager.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698