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

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

Issue 2026843003: [Offline Pages] Removing client in storage manager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Styles. 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 #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>
(...skipping 15 matching lines...) Expand all
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 expiring 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 32 // The time that the page record will be removed from the store since the page
33 // has been expired. 33 // has been expired.
34 const base::TimeDelta kRemovePageItemInterval = base::TimeDelta::FromDays(21); 34 const base::TimeDelta kRemovePageItemInterval = base::TimeDelta::FromDays(21);
35 35
36 class ArchiveManager;
37 class ClientPolicyController; 36 class ClientPolicyController;
37 class OfflinePageModel;
38 38
39 // This class is used for storage management of offline pages. It provides 39 // This class is used for storage management of offline pages. It provides
40 // a ClearPagesIfNeeded method which is used to clear expired offline pages 40 // a ClearPagesIfNeeded method which is used to clear expired offline pages
41 // based on last_access_time and lifetime policy of its namespace. 41 // 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 42 // It has its own throttle mechanism so calling the method would not be
43 // guaranteed to clear the pages immediately. 43 // guaranteed to clear the pages immediately.
44 // 44 //
45 // OfflinePageModel should own and control the lifecycle of this manager. 45 // OfflinePageModel should own and control the lifecycle of this manager.
46 // And this manager would use OfflinePageModel to get/remove pages. 46 // And this manager would use OfflinePageModel to get/remove pages.
47 class OfflinePageStorageManager { 47 class OfflinePageStorageManager {
48 public: 48 public:
49 // This interface should have no knowledge of offline page model.
50 // This interface should be implemented by clients managed by storage manager.
51 class Client {
52 public:
53 virtual ~Client() {}
54
55 // Asks the client to delete pages based on |ofline_ids| and invokes
56 // |callback| upon completion.
57 virtual void DeletePagesByOfflineId(const std::vector<int64_t>& offline_ids,
58 const DeletePageCallback& callback) = 0;
59
60 // Asks the client to get all offline pages and invokes |callback| upon
61 // completion.
62 virtual void GetAllPages(
63 const MultipleOfflinePageItemCallback& callback) = 0;
64
65 // Asks the client to mark pages with |offline_ids| as expired and delete
66 // the associated archive files.
67 virtual void ExpirePages(const std::vector<int64_t>& offline_ids,
68 const base::Time& expiration_time,
69 const base::Callback<void(bool)>& callback) = 0;
70 };
71
72 enum class ClearStorageResult { 49 enum class ClearStorageResult {
73 SUCCESS, // Cleared successfully. 50 SUCCESS, // Cleared successfully.
74 UNNECESSARY, // No expired pages. 51 UNNECESSARY, // No expired pages.
75 EXPIRE_FAILURE, // Expiration failed. 52 EXPIRE_FAILURE, // Expiration failed.
76 DELETE_FAILURE, // Deletion failed. 53 DELETE_FAILURE, // Deletion failed.
77 EXPIRE_AND_DELETE_FAILURES, // Both expiration and deletion failed. 54 EXPIRE_AND_DELETE_FAILURES, // Both expiration and deletion failed.
78 // NOTE: always keep this entry at the end. Add new result types only 55 // NOTE: always keep this entry at the end. Add new result types only
79 // immediately above this line. Make sure to update the corresponding 56 // immediately above this line. Make sure to update the corresponding
80 // histogram enum accordingly. 57 // histogram enum accordingly.
81 RESULT_COUNT, 58 RESULT_COUNT,
82 }; 59 };
83 60
84 // Callback used when calling ClearPagesIfNeeded. 61 // Callback used when calling ClearPagesIfNeeded.
85 // size_t: the number of expired pages. 62 // size_t: the number of expired pages.
86 // ClearStorageResult: result of expiring pages in storage. 63 // ClearStorageResult: result of expiring pages in storage.
87 typedef base::Callback<void(size_t, ClearStorageResult)> ClearStorageCallback; 64 typedef base::Callback<void(size_t, ClearStorageResult)> ClearStorageCallback;
88 65
89 explicit OfflinePageStorageManager(Client* client, 66 explicit OfflinePageStorageManager(OfflinePageModel* model,
90 ClientPolicyController* policy_controller, 67 ClientPolicyController* policy_controller,
91 ArchiveManager* archive_manager); 68 ArchiveManager* archive_manager);
92 69
93 ~OfflinePageStorageManager(); 70 ~OfflinePageStorageManager();
94 71
95 // The manager would *try* to clear pages when called. It may not delete any 72 // The manager would *try* to clear pages when called. It may not delete any
96 // pages (if clearing condition wasn't satisfied). 73 // pages (if clearing condition wasn't satisfied).
97 // It clears the storage (expire pages) when it's using more disk space than a 74 // It clears the storage (expire pages) when it's using more disk space than a
98 // certain limit, or the time elapsed from last time clearing is longer than a 75 // certain limit, or the time elapsed from last time clearing is longer than a
99 // certain interval. Both values are defined above. 76 // certain interval. Both values are defined above.
(...skipping 11 matching lines...) Expand all
111 // No need to expire any page (no pages in the model or no expired 88 // No need to expire any page (no pages in the model or no expired
112 // pages and we're not exceeding the storage limit.) 89 // pages and we're not exceeding the storage limit.)
113 NOT_NEEDED, 90 NOT_NEEDED,
114 }; 91 };
115 92
116 // Callback called after getting storage stats from archive manager. 93 // Callback called after getting storage stats from archive manager.
117 void OnGetStorageStatsDoneForClearingPages( 94 void OnGetStorageStatsDoneForClearingPages(
118 const ClearStorageCallback& callback, 95 const ClearStorageCallback& callback,
119 const ArchiveManager::StorageStats& pages); 96 const ArchiveManager::StorageStats& pages);
120 97
121 // Callback called after getting all pages from client. 98 // Callback called after getting all pages from model.
122 void OnGetAllPagesDoneForClearingPages( 99 void OnGetAllPagesDoneForClearingPages(
123 const ClearStorageCallback& callback, 100 const ClearStorageCallback& callback,
124 const ArchiveManager::StorageStats& storage_stats, 101 const ArchiveManager::StorageStats& storage_stats,
125 const MultipleOfflinePageItemResult& pages); 102 const MultipleOfflinePageItemResult& pages);
126 103
127 // Callback called after expired pages have been deleted. 104 // Callback called after expired pages have been deleted.
128 void OnPagesExpired(const ClearStorageCallback& callback, 105 void OnPagesExpired(const ClearStorageCallback& callback,
129 size_t pages_to_clear, 106 size_t pages_to_clear,
130 const std::vector<int64_t>& page_ids_to_remove, 107 const std::vector<int64_t>& page_ids_to_remove,
131 bool expiration_succeeded); 108 bool expiration_succeeded);
132 109
133 // Callback called after clearing outdated pages from client. 110 // Callback called after clearing outdated pages from model.
134 void OnOutdatedPagesCleared(const ClearStorageCallback& callback, 111 void OnOutdatedPagesCleared(const ClearStorageCallback& callback,
135 size_t pages_cleared, 112 size_t pages_cleared,
136 bool expiration_succeeded, 113 bool expiration_succeeded,
137 DeletePageResult result); 114 DeletePageResult result);
138 115
139 // Gets offline IDs of both pages that should be expired and the ones that 116 // Gets offline IDs of both pages that should be expired and the ones that
140 // need to be removed from metadata store. |page_ids_to_expire| will have 117 // need to be removed from metadata store. |page_ids_to_expire| will have
141 // the pages to be expired, |page_ids_to_remove| will have the pages to be 118 // the pages to be expired, |page_ids_to_remove| will have the pages to be
142 // removed. 119 // removed.
143 void GetPageIdsToClear(const MultipleOfflinePageItemResult& pages, 120 void GetPageIdsToClear(const MultipleOfflinePageItemResult& pages,
144 const ArchiveManager::StorageStats& stats, 121 const ArchiveManager::StorageStats& stats,
145 std::vector<int64_t>* page_ids_to_expire, 122 std::vector<int64_t>* page_ids_to_expire,
146 std::vector<int64_t>* page_ids_to_remove); 123 std::vector<int64_t>* page_ids_to_remove);
147 124
148 // Determines if manager should clear pages. 125 // Determines if manager should clear pages.
149 ClearMode ShouldClearPages(const ArchiveManager::StorageStats& storage_stats); 126 ClearMode ShouldClearPages(const ArchiveManager::StorageStats& storage_stats);
150 127
151 // Returns true if |page| is expired comparing to |clear_time_|. 128 // Returns true if |page| is expired comparing to |clear_time_|.
152 bool ShouldBeExpired(const OfflinePageItem& page) const; 129 bool ShouldBeExpired(const OfflinePageItem& page) const;
153 130
154 // Returns true if we're currently doing a cleanup. 131 // Returns true if we're currently doing a cleanup.
155 bool IsInProgress() const; 132 bool IsInProgress() const;
156 133
157 // Not owned. 134 // Not owned.
158 Client* client_; 135 OfflinePageModel* model_;
159 136
160 // Not owned. 137 // Not owned.
161 ClientPolicyController* policy_controller_; 138 ClientPolicyController* policy_controller_;
162 139
163 // Not owned. 140 // Not owned.
164 ArchiveManager* archive_manager_; 141 ArchiveManager* archive_manager_;
165 142
166 // Starting time of the current storage cleanup. If this time is later than 143 // Starting time of the current storage cleanup. If this time is later than
167 // |last_clear_time_| it means we're doing a cleanup. 144 // |last_clear_time_| it means we're doing a cleanup.
168 base::Time clear_time_; 145 base::Time clear_time_;
169 146
170 // Timestamp of last storage cleanup. 147 // Timestamp of last storage cleanup.
171 base::Time last_clear_time_; 148 base::Time last_clear_time_;
172 149
173 // Clock for getting time. 150 // Clock for getting time.
174 std::unique_ptr<base::Clock> clock_; 151 std::unique_ptr<base::Clock> clock_;
175 152
176 base::WeakPtrFactory<OfflinePageStorageManager> weak_ptr_factory_; 153 base::WeakPtrFactory<OfflinePageStorageManager> weak_ptr_factory_;
177 154
178 DISALLOW_COPY_AND_ASSIGN(OfflinePageStorageManager); 155 DISALLOW_COPY_AND_ASSIGN(OfflinePageStorageManager);
179 }; 156 };
180 157
181 } // namespace offline_pages 158 } // namespace offline_pages
182 159
183 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_STORAGE_MANAGER_H_ 160 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_STORAGE_MANAGER_H_
OLDNEW
« no previous file with comments | « components/offline_pages/offline_page_model_impl.cc ('k') | components/offline_pages/offline_page_storage_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698