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