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

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

Issue 2004993002: add a couple of casts. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments. 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.cc ('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 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 stats)); 59 stats));
60 } 60 }
61 61
62 void OfflinePageStorageManager::OnGetAllPagesDone( 62 void OfflinePageStorageManager::OnGetAllPagesDone(
63 const ClearPagesCallback& callback, 63 const ClearPagesCallback& callback,
64 const ArchiveManager::StorageStats& stats, 64 const ArchiveManager::StorageStats& stats,
65 const MultipleOfflinePageItemResult& pages) { 65 const MultipleOfflinePageItemResult& pages) {
66 std::vector<int64_t> offline_ids; 66 std::vector<int64_t> offline_ids;
67 GetExpiredPageIds(pages, stats, offline_ids); 67 GetExpiredPageIds(pages, stats, offline_ids);
68 client_->DeletePagesByOfflineId( 68 client_->DeletePagesByOfflineId(
69 offline_ids, 69 offline_ids, base::Bind(&OfflinePageStorageManager::OnExpiredPagesDeleted,
70 base::Bind(&OfflinePageStorageManager::OnExpiredPagesDeleted, 70 weak_ptr_factory_.GetWeakPtr(), callback,
71 weak_ptr_factory_.GetWeakPtr(), callback, offline_ids.size())); 71 static_cast<int>(offline_ids.size())));
72 } 72 }
73 73
74 void OfflinePageStorageManager::OnExpiredPagesDeleted( 74 void OfflinePageStorageManager::OnExpiredPagesDeleted(
75 const ClearPagesCallback& callback, 75 const ClearPagesCallback& callback,
76 int pages_cleared, 76 int pages_cleared,
77 DeletePageResult result) { 77 DeletePageResult result) {
78 last_clear_time_ = clock_->Now(); 78 last_clear_time_ = clock_->Now();
79 ClearStorageResult clear_result = result == DeletePageResult::SUCCESS 79 ClearStorageResult clear_result = result == DeletePageResult::SUCCESS
80 ? ClearStorageResult::SUCCESS 80 ? ClearStorageResult::SUCCESS
81 : ClearStorageResult::DELETE_FAILURE; 81 : ClearStorageResult::DELETE_FAILURE;
(...skipping 23 matching lines...) Expand all
105 std::vector<OfflinePageItem>& page_list = iter.second; 105 std::vector<OfflinePageItem>& page_list = iter.second;
106 106
107 LifetimePolicy policy = 107 LifetimePolicy policy =
108 policy_controller_->GetPolicy(name_space).lifetime_policy; 108 policy_controller_->GetPolicy(name_space).lifetime_policy;
109 109
110 std::sort(page_list.begin(), page_list.end(), 110 std::sort(page_list.begin(), page_list.end(),
111 [](const OfflinePageItem& a, const OfflinePageItem& b) -> bool { 111 [](const OfflinePageItem& a, const OfflinePageItem& b) -> bool {
112 return a.last_access_time > b.last_access_time; 112 return a.last_access_time > b.last_access_time;
113 }); 113 });
114 114
115 int page_list_size = page_list.size(); 115 int page_list_size = static_cast<int>(page_list.size());
116 int pos = 0; 116 int pos = 0;
117 while (pos < page_list_size && 117 while (pos < page_list_size &&
118 (policy.page_limit == kUnlimitedPages || pos < policy.page_limit) && 118 (policy.page_limit == kUnlimitedPages || pos < policy.page_limit) &&
119 !ShouldBeExpired(now, page_list.at(pos))) { 119 !ShouldBeExpired(now, page_list.at(pos))) {
120 kept_pages_size += page_list.at(pos).file_size; 120 kept_pages_size += page_list.at(pos).file_size;
121 kept_pages.push_back(page_list.at(pos)); 121 kept_pages.push_back(page_list.at(pos));
122 pos++; 122 pos++;
123 } 123 }
124 124
125 for (; pos < page_list_size; pos++) 125 for (; pos < page_list_size; pos++)
126 offline_ids.push_back(page_list.at(pos).offline_id); 126 offline_ids.push_back(page_list.at(pos).offline_id);
127 } 127 }
128 128
129 // If we're still over the clear threshold, we're going to clear remaining 129 // If we're still over the clear threshold, we're going to clear remaining
130 // pages from oldest last access time. 130 // pages from oldest last access time.
131 int64_t free_space = stats.free_disk_space; 131 int64_t free_space = stats.free_disk_space;
132 int64_t total_size = stats.total_archives_size; 132 int64_t total_size = stats.total_archives_size;
133 int64_t space_to_release = 133 int64_t space_to_release =
134 kept_pages_size - 134 kept_pages_size -
135 (total_size + free_space) * kOfflinePageStorageClearThreshold; 135 (total_size + free_space) * kOfflinePageStorageClearThreshold;
136 if (space_to_release > 0) { 136 if (space_to_release > 0) {
137 // Here we're sorting the |kept_pages| with oldest first. 137 // Here we're sorting the |kept_pages| with oldest first.
138 std::sort(kept_pages.begin(), kept_pages.end(), 138 std::sort(kept_pages.begin(), kept_pages.end(),
139 [](const OfflinePageItem& a, const OfflinePageItem& b) -> bool { 139 [](const OfflinePageItem& a, const OfflinePageItem& b) -> bool {
140 return a.last_access_time < b.last_access_time; 140 return a.last_access_time < b.last_access_time;
141 }); 141 });
142 int kept_pages_size = kept_pages.size(); 142 int kept_pages_size = static_cast<int>(kept_pages.size());
143 int pos = 0; 143 int pos = 0;
144 while (pos < kept_pages_size && space_to_release > 0) { 144 while (pos < kept_pages_size && space_to_release > 0) {
145 space_to_release -= kept_pages.at(pos).file_size; 145 space_to_release -= kept_pages.at(pos).file_size;
146 offline_ids.push_back(kept_pages.at(pos).offline_id); 146 offline_ids.push_back(kept_pages.at(pos).offline_id);
147 pos++; 147 pos++;
148 } 148 }
149 } 149 }
150 } 150 }
151 151
152 OfflinePageStorageManager::ClearMode 152 OfflinePageStorageManager::ClearMode
(...skipping 21 matching lines...) Expand all
174 } 174 }
175 175
176 bool OfflinePageStorageManager::ShouldBeExpired(const base::Time& now, 176 bool OfflinePageStorageManager::ShouldBeExpired(const base::Time& now,
177 const OfflinePageItem& page) { 177 const OfflinePageItem& page) {
178 const LifetimePolicy& policy = 178 const LifetimePolicy& policy =
179 policy_controller_->GetPolicy(page.client_id.name_space).lifetime_policy; 179 policy_controller_->GetPolicy(page.client_id.name_space).lifetime_policy;
180 return now - page.last_access_time >= policy.expiration_period; 180 return now - page.last_access_time >= policy.expiration_period;
181 } 181 }
182 182
183 } // namespace offline_pages 183 } // namespace offline_pages
OLDNEW
« no previous file with comments | « components/offline_pages/offline_page_model.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698