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

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

Issue 2111653002: [Offline Pages] Adding metadatas for namespace async_loading. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing tests. Created 4 years, 5 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"
11 #include "base/time/default_clock.h" 11 #include "base/time/default_clock.h"
12 #include "components/offline_pages/client_policy_controller.h" 12 #include "components/offline_pages/client_policy_controller.h"
13 #include "components/offline_pages/offline_page_client_policy.h" 13 #include "components/offline_pages/offline_page_client_policy.h"
14 #include "components/offline_pages/offline_page_item.h" 14 #include "components/offline_pages/offline_page_item.h"
15 #include "components/offline_pages/offline_page_model.h" 15 #include "components/offline_pages/offline_page_model.h"
16 16
17 using LifetimeType = offline_pages::LifetimePolicy::LifetimeType;
18
17 namespace offline_pages { 19 namespace offline_pages {
18 20
19 OfflinePageStorageManager::OfflinePageStorageManager( 21 OfflinePageStorageManager::OfflinePageStorageManager(
20 OfflinePageModel* model, 22 OfflinePageModel* model,
21 ClientPolicyController* policy_controller, 23 ClientPolicyController* policy_controller,
22 ArchiveManager* archive_manager) 24 ArchiveManager* archive_manager)
23 : model_(model), 25 : model_(model),
24 policy_controller_(policy_controller), 26 policy_controller_(policy_controller),
25 archive_manager_(archive_manager), 27 archive_manager_(archive_manager),
26 clock_(new base::DefaultClock()), 28 clock_(new base::DefaultClock()),
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 } 103 }
102 last_clear_time_ = clear_time_; 104 last_clear_time_ = clear_time_;
103 callback.Run(pages_cleared, clear_result); 105 callback.Run(pages_cleared, clear_result);
104 } 106 }
105 107
106 void OfflinePageStorageManager::GetPageIdsToClear( 108 void OfflinePageStorageManager::GetPageIdsToClear(
107 const MultipleOfflinePageItemResult& pages, 109 const MultipleOfflinePageItemResult& pages,
108 const ArchiveManager::StorageStats& stats, 110 const ArchiveManager::StorageStats& stats,
109 std::vector<int64_t>* page_ids_to_expire, 111 std::vector<int64_t>* page_ids_to_expire,
110 std::vector<int64_t>* page_ids_to_remove) { 112 std::vector<int64_t>* page_ids_to_remove) {
113 // TODO(romax): See how persistent should be considered here.
111 // Creating a map from namespace to a vector of page items. 114 // Creating a map from namespace to a vector of page items.
112 // Sort each vector based on last accessed time and all pages after index 115 // Sort each vector based on last accessed time and all pages after index
113 // min{size(), page_limit} should be expired. And then start iterating 116 // min{size(), page_limit} should be expired. And then start iterating
114 // backwards to expire pages. 117 // backwards to expire pages.
115 std::map<std::string, std::vector<OfflinePageItem>> pages_map; 118 std::map<std::string, std::vector<OfflinePageItem>> pages_map;
116 std::vector<OfflinePageItem> kept_pages; 119 std::vector<OfflinePageItem> kept_pages;
117 int64_t kept_pages_size = 0; 120 int64_t kept_pages_size = 0;
118 121
119 for (const auto& page : pages) { 122 for (const auto& page : pages) {
120 if (!page.IsExpired()) { 123 if (!page.IsExpired()) {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 return ClearMode::DEFAULT; 196 return ClearMode::DEFAULT;
194 } 197 }
195 // Otherwise there's no need to clear storage right now. 198 // Otherwise there's no need to clear storage right now.
196 return ClearMode::NOT_NEEDED; 199 return ClearMode::NOT_NEEDED;
197 } 200 }
198 201
199 bool OfflinePageStorageManager::ShouldBeExpired( 202 bool OfflinePageStorageManager::ShouldBeExpired(
200 const OfflinePageItem& page) const { 203 const OfflinePageItem& page) const {
201 const LifetimePolicy& policy = 204 const LifetimePolicy& policy =
202 policy_controller_->GetPolicy(page.client_id.name_space).lifetime_policy; 205 policy_controller_->GetPolicy(page.client_id.name_space).lifetime_policy;
203 return clear_time_ - page.last_access_time >= policy.expiration_period; 206 return policy.lifetime_type == LifetimeType::TEMPORARY &&
207 clear_time_ - page.last_access_time >= policy.expiration_period;
204 } 208 }
205 209
206 bool OfflinePageStorageManager::IsInProgress() const { 210 bool OfflinePageStorageManager::IsInProgress() const {
207 return clear_time_ > last_clear_time_; 211 return clear_time_ > last_clear_time_;
208 } 212 }
209 213
210 } // namespace offline_pages 214 } // namespace offline_pages
OLDNEW
« no previous file with comments | « components/offline_pages/offline_page_model_impl.cc ('k') | components/offline_pages/offline_page_storage_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698