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

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

Issue 2015793002: [Offline Pages] Linking storage manager and model with UMAs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@wisp
Patch Set: Adding more UMAs and hooking up model and storage manager. 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
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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 const base::Time& expiration_time, 67 const base::Time& expiration_time,
68 const base::Callback<void(bool)>& callback) = 0; 68 const base::Callback<void(bool)>& callback) = 0;
69 }; 69 };
70 70
71 enum class ClearStorageResult { 71 enum class ClearStorageResult {
72 SUCCESS, // Cleared successfully. 72 SUCCESS, // Cleared successfully.
73 UNNECESSARY, // No expired pages. 73 UNNECESSARY, // No expired pages.
74 EXPIRE_FAILURE, // Expiration failed. 74 EXPIRE_FAILURE, // Expiration failed.
75 DELETE_FAILURE, // Deletion failed. 75 DELETE_FAILURE, // Deletion failed.
76 BOTH_FAILURE, // Both expiration and deletion failed. 76 BOTH_FAILURE, // Both expiration and deletion failed.
77 // NOTE: always keep this entry at the end. Add new result types only
78 // immediately above this line. Make sure to update the corresponding
79 // histogram enum accordingly.
80 RESULT_COUNT,
77 }; 81 };
78 82
79 // Callback used when calling ClearPagesIfNeeded. 83 // Callback used when calling ClearPagesIfNeeded.
80 // size_t: the number of expired pages. 84 // size_t: the number of expired pages.
81 // ClearStorageResult: result of expiring pages in storage. 85 // ClearStorageResult: result of expiring pages in storage.
82 typedef base::Callback<void(size_t, ClearStorageResult)> ClearPagesCallback; 86 typedef base::Callback<void(size_t, ClearStorageResult)> ClearStorageCallback;
83 87
84 explicit OfflinePageStorageManager(Client* client, 88 explicit OfflinePageStorageManager(Client* client,
85 ClientPolicyController* policy_controller, 89 ClientPolicyController* policy_controller,
86 ArchiveManager* archive_manager); 90 ArchiveManager* archive_manager);
87 91
88 ~OfflinePageStorageManager(); 92 ~OfflinePageStorageManager();
89 93
90 // The manager would *try* to clear pages when called. It may not delete any 94 // The manager would *try* to clear pages when called. It may not delete any
91 // pages (if clearing condition wasn't satisfied). 95 // pages (if clearing condition wasn't satisfied).
92 // It clears the storage (expire pages) when it's using more disk space than a 96 // It clears the storage (expire pages) when it's using more disk space than a
93 // certain limit, or the time elapsed from last time clearing is longer than a 97 // certain limit, or the time elapsed from last time clearing is longer than a
94 // certain interval. Both values are defined above. 98 // certain interval. Both values are defined above.
95 void ClearPagesIfNeeded(const ClearPagesCallback& callback); 99 void ClearPagesIfNeeded(const ClearStorageCallback& callback);
96 100
97 // Sets the clock for testing. 101 // Sets the clock for testing.
98 void SetClockForTesting(std::unique_ptr<base::Clock> clock); 102 void SetClockForTesting(std::unique_ptr<base::Clock> clock);
99 103
100 private: 104 private:
101 // Enum indicating how to clear the pages. 105 // Enum indicating how to clear the pages.
102 enum class ClearMode { 106 enum class ClearMode {
103 // Using normal expiration logic to expire pages. Will reduce the storage 107 // Using normal expiration logic to expire pages. Will reduce the storage
104 // usage down below the threshold. 108 // usage down below the threshold.
105 DEFAULT, 109 DEFAULT,
106 // No need to expire any page (no pages in the model or no expired 110 // No need to expire any page (no pages in the model or no expired
107 // pages and we're not exceeding the storage limit.) 111 // pages and we're not exceeding the storage limit.)
108 NOT_NEEDED, 112 NOT_NEEDED,
109 }; 113 };
110 114
111 // Callback called after getting storage stats from archive manager. 115 // Callback called after getting storage stats from archive manager.
112 void OnGetStorageStatsDoneForClearingPages( 116 void OnGetStorageStatsDoneForClearingPages(
113 const ClearPagesCallback& callback, 117 const ClearStorageCallback& callback,
114 const ArchiveManager::StorageStats& pages); 118 const ArchiveManager::StorageStats& pages);
115 119
116 // Callback called after getting all pages from client done. 120 // Callback called after getting all pages from client done.
117 void OnGetAllPagesDoneForClearingPages( 121 void OnGetAllPagesDoneForClearingPages(
118 const ClearPagesCallback& callback, 122 const ClearStorageCallback& callback,
119 const ArchiveManager::StorageStats& storage_stats, 123 const ArchiveManager::StorageStats& storage_stats,
120 const MultipleOfflinePageItemResult& pages); 124 const MultipleOfflinePageItemResult& pages);
121 125
122 // Callback called after expired pages have been deleted. 126 // Callback called after expired pages have been deleted.
123 void OnPagesExpired(const ClearPagesCallback& callback, 127 void OnPagesExpired(const ClearStorageCallback& callback,
124 size_t pages_to_clear, 128 size_t pages_to_clear,
125 const std::vector<int64_t>& page_ids_to_remove, 129 const std::vector<int64_t>& page_ids_to_remove,
126 bool expiration_succeeded); 130 bool expiration_succeeded);
127 131
128 // Callback called after clearing outdated pages from client. 132 // Callback called after clearing outdated pages from client.
129 void OnOutdatedPagesCleared(const ClearPagesCallback& callback, 133 void OnOutdatedPagesCleared(const ClearStorageCallback& callback,
130 size_t pages_cleared, 134 size_t pages_cleared,
131 bool expiration_succeeded, 135 bool expiration_succeeded,
132 DeletePageResult result); 136 DeletePageResult result);
133 137
134 // Gets offline IDs of both pages that should be expired and the ones that 138 // Gets offline IDs of both pages that should be expired and the ones that
135 // need to be removed from metadata store. |page_ids_to_expire| will have 139 // need to be removed from metadata store. |page_ids_to_expire| will have
136 // the pages to be expired, |page_ids_to_remove| will have the pages to be 140 // the pages to be expired, |page_ids_to_remove| will have the pages to be
137 // removed. 141 // removed.
138 void GetPageIdsToClear(const MultipleOfflinePageItemResult& pages, 142 void GetPageIdsToClear(const MultipleOfflinePageItemResult& pages,
139 const ArchiveManager::StorageStats& stats, 143 const ArchiveManager::StorageStats& stats,
(...skipping 29 matching lines...) Expand all
169 std::unique_ptr<base::Clock> clock_; 173 std::unique_ptr<base::Clock> clock_;
170 174
171 base::WeakPtrFactory<OfflinePageStorageManager> weak_ptr_factory_; 175 base::WeakPtrFactory<OfflinePageStorageManager> weak_ptr_factory_;
172 176
173 DISALLOW_COPY_AND_ASSIGN(OfflinePageStorageManager); 177 DISALLOW_COPY_AND_ASSIGN(OfflinePageStorageManager);
174 }; 178 };
175 179
176 } // namespace offline_pages 180 } // namespace offline_pages
177 181
178 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_STORAGE_MANAGER_H_ 182 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_STORAGE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698