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

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

Issue 2512073002: [Offline Pages] Removes two-step expiration related. (Closed)
Patch Set: Created 4 years, 1 month 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 #ifndef COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_STORAGE_MANAGER_H_ 5 #ifndef COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_STORAGE_MANAGER_H_
6 #define COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_STORAGE_MANAGER_H_ 6 #define COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_STORAGE_MANAGER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "base/time/time.h" 15 #include "base/time/time.h"
16 #include "components/offline_pages/archive_manager.h" 16 #include "components/offline_pages/archive_manager.h"
17 #include "components/offline_pages/offline_page_types.h" 17 #include "components/offline_pages/offline_page_types.h"
18 18
19 namespace base { 19 namespace base {
20 class Clock; 20 class Clock;
21 } // namespace base 21 } // namespace base
22 22
23 namespace offline_pages { 23 namespace offline_pages {
24 24
25 // Maximum % of total available storage that will be occupied by offline pages 25 // Maximum % of total available storage that will be occupied by offline pages
26 // before a storage clearup. 26 // before a storage clearup.
27 const double kOfflinePageStorageLimit = 0.3; 27 const double kOfflinePageStorageLimit = 0.3;
28 // The target % of storage usage we try to reach below when expiring pages. 28 // The target % of storage usage we try to reach below when deleting pages.
29 const double kOfflinePageStorageClearThreshold = 0.1; 29 const double kOfflinePageStorageClearThreshold = 0.1;
30 // The time that the storage cleanup will be triggered again since the last one. 30 // The time that the storage cleanup will be triggered again since the last one.
31 const base::TimeDelta kClearStorageInterval = base::TimeDelta::FromMinutes(10); 31 const base::TimeDelta kClearStorageInterval = base::TimeDelta::FromMinutes(10);
32 // The time that the page record will be removed from the store since the page
33 // has been expired.
34 const base::TimeDelta kRemovePageItemInterval = base::TimeDelta::FromDays(21);
35 32
36 class ClientPolicyController; 33 class ClientPolicyController;
37 class OfflinePageModel; 34 class OfflinePageModel;
38 35
39 // This class is used for storage management of offline pages. It provides 36 // This class is used for storage management of offline pages. It provides
40 // a ClearPagesIfNeeded method which is used to clear expired offline pages 37 // a ClearPagesIfNeeded method which is used to clear outdated offline pages
41 // based on last_access_time and lifetime policy of its namespace. 38 // based on last_access_time and lifetime policy of its namespace.
42 // It has its own throttle mechanism so calling the method would not be 39 // It has its own throttle mechanism so calling the method would not be
43 // guaranteed to clear the pages immediately. 40 // guaranteed to clear the pages immediately.
44 // 41 //
45 // OfflinePageModel should own and control the lifecycle of this manager. 42 // OfflinePageModel should own and control the lifecycle of this manager.
46 // And this manager would use OfflinePageModel to get/remove pages. 43 // And this manager would use OfflinePageModel to get/remove pages.
47 class OfflinePageStorageManager { 44 class OfflinePageStorageManager {
48 public: 45 public:
49 enum class ClearStorageResult { 46 enum class ClearStorageResult {
jianli 2016/11/18 00:15:48 Do you want to update the histogram for this?
romax 2016/11/18 20:50:49 Yes, I'm following the comment from Filip below to
50 SUCCESS, // Cleared successfully. 47 SUCCESS, // Cleared successfully.
51 UNNECESSARY, // No expired pages. 48 UNNECESSARY, // No expired pages.
52 EXPIRE_FAILURE, // Expiration failed. 49 CLEAR_FAILURE, // Deletion failed.
53 DELETE_FAILURE, // Deletion failed.
54 EXPIRE_AND_DELETE_FAILURES, // Both expiration and deletion failed.
55 // NOTE: always keep this entry at the end. Add new result types only 50 // NOTE: always keep this entry at the end. Add new result types only
fgorski 2016/11/18 00:13:04 Read this note before making changes. Mark the im
romax 2016/11/18 20:50:49 Done but not sure, can you please take a close loo
56 // immediately above this line. Make sure to update the corresponding 51 // immediately above this line. Make sure to update the corresponding
57 // histogram enum accordingly. 52 // histogram enum accordingly.
58 RESULT_COUNT, 53 RESULT_COUNT,
59 }; 54 };
60 55
61 // Callback used when calling ClearPagesIfNeeded. 56 // Callback used when calling ClearPagesIfNeeded.
62 // size_t: the number of expired pages. 57 // size_t: the number of cleared pages.
63 // ClearStorageResult: result of expiring pages in storage. 58 // ClearStorageResult: result of clearing pages in storage.
64 typedef base::Callback<void(size_t, ClearStorageResult)> ClearStorageCallback; 59 typedef base::Callback<void(size_t, ClearStorageResult)> ClearStorageCallback;
65 60
66 explicit OfflinePageStorageManager(OfflinePageModel* model, 61 explicit OfflinePageStorageManager(OfflinePageModel* model,
67 ClientPolicyController* policy_controller, 62 ClientPolicyController* policy_controller,
68 ArchiveManager* archive_manager); 63 ArchiveManager* archive_manager);
69 64
70 ~OfflinePageStorageManager(); 65 ~OfflinePageStorageManager();
71 66
72 // The manager would *try* to clear pages when called. It may not delete any 67 // The manager would *try* to clear pages when called. It may not delete any
73 // pages (if clearing condition wasn't satisfied). 68 // pages (if clearing condition wasn't satisfied).
74 // It clears the storage (expire pages) when it's using more disk space than a 69 // It clears the storage (expire pages) when it's using more disk space than a
75 // certain limit, or the time elapsed from last time clearing is longer than a 70 // certain limit, or the time elapsed from last time clearing is longer than a
76 // certain interval. Both values are defined above. 71 // certain interval. Both values are defined above.
77 void ClearPagesIfNeeded(const ClearStorageCallback& callback); 72 void ClearPagesIfNeeded(const ClearStorageCallback& callback);
78 73
79 // Sets the clock for testing. 74 // Sets the clock for testing.
80 void SetClockForTesting(std::unique_ptr<base::Clock> clock); 75 void SetClockForTesting(std::unique_ptr<base::Clock> clock);
81 76
82 private: 77 private:
83 // Enum indicating how to clear the pages. 78 // Enum indicating how to clear the pages.
84 enum class ClearMode { 79 enum class ClearMode {
85 // Using normal expiration logic to expire pages. Will reduce the storage 80 // Using normal expiration logic to clear pages. Will reduce the storage
86 // usage down below the threshold. 81 // usage down below the threshold.
87 DEFAULT, 82 DEFAULT,
88 // No need to expire any page (no pages in the model or no expired 83 // No need to clear any page (no pages in the model or no expired pages and
89 // pages and we're not exceeding the storage limit.) 84 // we're not exceeding the storage limit.)
90 NOT_NEEDED, 85 NOT_NEEDED,
91 }; 86 };
92 87
93 // Callback called after getting storage stats from archive manager. 88 // Callback called after getting storage stats from archive manager.
94 void OnGetStorageStatsDoneForClearingPages( 89 void OnGetStorageStatsDoneForClearingPages(
95 const ClearStorageCallback& callback, 90 const ClearStorageCallback& callback,
96 const ArchiveManager::StorageStats& pages); 91 const ArchiveManager::StorageStats& pages);
97 92
98 // Callback called after getting all pages from model. 93 // Callback called after getting all pages from model.
99 void OnGetAllPagesDoneForClearingPages( 94 void OnGetAllPagesDoneForClearingPages(
100 const ClearStorageCallback& callback, 95 const ClearStorageCallback& callback,
101 const ArchiveManager::StorageStats& storage_stats, 96 const ArchiveManager::StorageStats& storage_stats,
102 const MultipleOfflinePageItemResult& pages); 97 const MultipleOfflinePageItemResult& pages);
103 98
104 // Callback called after expired pages have been deleted. 99 // Callback called after clearing expired pages from model.
105 void OnPagesExpired(const ClearStorageCallback& callback, 100 void OnExpiredPagesCleared(const ClearStorageCallback& callback,
fgorski 2016/11/18 00:13:04 Expired... part should probably go.
romax 2016/11/18 20:50:49 Acknowledged.
106 size_t pages_to_clear, 101 size_t pages_cleared,
107 const std::vector<int64_t>& page_ids_to_remove, 102 DeletePageResult result);
108 bool expiration_succeeded);
109 103
110 // Callback called after clearing outdated pages from model. 104 // Gets offline IDs of pages that should be cleared based on current |stats|
111 void OnOutdatedPagesCleared(const ClearStorageCallback& callback, 105 // and return the IDs in |page_ids_to_clear|.
112 size_t pages_cleared,
113 bool expiration_succeeded,
114 DeletePageResult result);
115
116 // Gets offline IDs of both pages that should be expired and the ones that
117 // need to be removed from metadata store. |page_ids_to_expire| will have
118 // the pages to be expired, |page_ids_to_remove| will have the pages to be
119 // removed.
120 void GetPageIdsToClear(const MultipleOfflinePageItemResult& pages, 106 void GetPageIdsToClear(const MultipleOfflinePageItemResult& pages,
121 const ArchiveManager::StorageStats& stats, 107 const ArchiveManager::StorageStats& stats,
122 std::vector<int64_t>* page_ids_to_expire, 108 std::vector<int64_t>* page_ids_to_clear);
123 std::vector<int64_t>* page_ids_to_remove);
124 109
125 // Determines if manager should clear pages. 110 // Determines if manager should clear pages.
126 ClearMode ShouldClearPages(const ArchiveManager::StorageStats& storage_stats); 111 ClearMode ShouldClearPages(const ArchiveManager::StorageStats& storage_stats);
127 112
128 // Returns true if |page| is expired comparing to |clear_time_|. 113 // Returns true if |page| is should be cleared based on |clear_time_|.
129 bool ShouldBeExpired(const OfflinePageItem& page) const; 114 bool IsExpired(const OfflinePageItem& page) const;
fgorski 2016/11/18 00:13:04 Explain why we are still using the concept of expi
romax 2016/11/18 20:50:49 Yes expiration should still be a valid term for th
130 115
131 // Returns true if we're currently doing a cleanup. 116 // Returns true if we're currently doing a cleanup.
132 bool IsInProgress() const; 117 bool IsInProgress() const;
133 118
134 // Not owned. 119 // Not owned.
135 OfflinePageModel* model_; 120 OfflinePageModel* model_;
136 121
137 // Not owned. 122 // Not owned.
138 ClientPolicyController* policy_controller_; 123 ClientPolicyController* policy_controller_;
139 124
(...skipping 11 matching lines...) Expand all
151 std::unique_ptr<base::Clock> clock_; 136 std::unique_ptr<base::Clock> clock_;
152 137
153 base::WeakPtrFactory<OfflinePageStorageManager> weak_ptr_factory_; 138 base::WeakPtrFactory<OfflinePageStorageManager> weak_ptr_factory_;
154 139
155 DISALLOW_COPY_AND_ASSIGN(OfflinePageStorageManager); 140 DISALLOW_COPY_AND_ASSIGN(OfflinePageStorageManager);
156 }; 141 };
157 142
158 } // namespace offline_pages 143 } // namespace offline_pages
159 144
160 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_STORAGE_MANAGER_H_ 145 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_STORAGE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698