Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 = page_list.size(); |
|
fgorski
2016/05/23 20:45:42
this is the place the compiler complained about. B
| |
| 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++) |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 |
| OLD | NEW |