Chromium Code Reviews| Index: components/offline_pages/offline_page_storage_manager.h |
| diff --git a/components/offline_pages/offline_page_storage_manager.h b/components/offline_pages/offline_page_storage_manager.h |
| index 47f560120d929cfe10b80358f35b631c65796aae..254cc25bbbbf633cc7836375263fe8f20eda3f54 100644 |
| --- a/components/offline_pages/offline_page_storage_manager.h |
| +++ b/components/offline_pages/offline_page_storage_manager.h |
| @@ -22,12 +22,17 @@ class Clock; |
| namespace offline_pages { |
| -// Limit of the total storage space occupied by offline pages should be 30% of |
| -// available storage. And we clear storage when it is over the threshold, |
| -// reducing the usage below threshold. |
| +// Maximum % of total available storage that will be occupied by offline pages |
| +// before a storage clearing. |
|
jianli
2016/05/26 21:59:31
nit: storage clearing => storage cleanup
romax
2016/05/27 00:41:38
Done.
|
| const double kOfflinePageStorageLimit = 0.3; |
|
jianli
2016/05/26 21:59:32
If these constants are only needed in .cc file, pl
romax
2016/05/27 00:41:38
per discussion I'm leaving them here.
|
| +// The target % of storage usage we try to reach below when expiring pages. |
| const double kOfflinePageStorageClearThreshold = 0.1; |
| +// Storage manager will clear storage if it has been longer than this interval |
|
jianli
2016/05/26 21:59:31
nit: The time that the storage cleanup will be tri
romax
2016/05/27 00:41:38
Done.
|
| +// since last clearing. |
| const base::TimeDelta kClearStorageInterval = base::TimeDelta::FromMinutes(10); |
| +// Storage manager will remove a page from metadata store once the page has been |
|
jianli
2016/05/26 21:59:32
nit: The time that the page record will be removed
romax
2016/05/27 00:41:38
Done.
|
| +// expired longer than this interval. |
| +const base::TimeDelta kRemovePageItemInterval = base::TimeDelta::FromDays(21); |
| class ArchiveManager; |
| class ClientPolicyController; |
| @@ -48,26 +53,33 @@ class OfflinePageStorageManager { |
| public: |
| virtual ~Client() {} |
| + // Asks the client to delete pages based on |ofline_ids| and invoke |
|
jianli
2016/05/26 21:59:32
nit: invoke => invokes
also consider adding "upon
romax
2016/05/27 00:41:38
Done.
|
| + // |callback|. |
| + virtual void DeletePagesByOfflineId(const std::vector<int64_t>& offline_ids, |
| + const DeletePageCallback& callback) = 0; |
| + |
| // Asks the client to get all offline pages and invoke |callback|. |
| virtual void GetAllPages( |
| const MultipleOfflinePageItemCallback& callback) = 0; |
| - // Asks the client to delete pages based on |offline_ids| and invoke |
| - // |callback|. |
| - virtual void DeletePagesByOfflineId(const std::vector<int64_t>& offline_ids, |
| - const DeletePageCallback& callback) = 0; |
| + // Asks the client to mark pages with |offline_ids| as expired and the |
|
jianli
2016/05/26 21:59:32
nit: add "deletes" after "and".
romax
2016/05/27 00:41:38
Done.
|
| + // associated archive files. |
| + virtual void ExpirePages(const std::vector<int64_t>& offline_ids, |
| + const base::Time& expiration_time, |
| + const base::Callback<void(bool)>& callback) = 0; |
| }; |
| enum class ClearStorageResult { |
| SUCCESS, // Cleared successfully. |
| UNNECESSARY, // No expired pages. |
| + EXPIRE_FAILURE, // Expiration failed. |
| DELETE_FAILURE, // Deletion failed. |
| }; |
| // Callback used when calling ClearPagesIfNeeded. |
| - // int: the number of expired pages. |
| + // size_t: the number of expired pages. |
| // ClearStorageResult: result of expiring pages in storage. |
| - typedef base::Callback<void(int, ClearStorageResult)> ClearPagesCallback; |
| + typedef base::Callback<void(size_t, ClearStorageResult)> ClearPagesCallback; |
| explicit OfflinePageStorageManager(Client* client, |
| ClientPolicyController* policy_controller, |
| @@ -103,20 +115,34 @@ class OfflinePageStorageManager { |
| // Callback called after getting all pages from client done. |
| void OnGetAllPagesDone(const ClearPagesCallback& callback, |
| const ArchiveManager::StorageStats& storage_stats, |
| + const base::Time& now, |
| const MultipleOfflinePageItemResult& pages); |
| // Callback called after expired pages have been deleted. |
| - void OnExpiredPagesDeleted(const ClearPagesCallback& callback, |
| - int pages_to_clear, |
| - DeletePageResult result); |
| - |
| - // Gets offline IDs of all expired pages and return in |offline_ids|. |
| - void GetExpiredPageIds(const MultipleOfflinePageItemResult& pages, |
| + void OnPagesExpired(const ClearPagesCallback& callback, |
| + size_t pages_to_clear, |
| + std::vector<int64_t>* page_ids_to_remove, |
| + bool success); |
| + |
| + // Callback called after clearing outdated pages from client. |
| + void OnDeadPagesCleared(const ClearPagesCallback& callback, |
|
jianli
2016/05/26 21:59:32
replace Dead with Outdated
romax
2016/05/27 00:41:38
Done.
|
| + size_t pages_cleared, |
| + bool success, |
| + DeletePageResult result); |
| + |
| + // Gets offline IDs of both pages that should be expired and the ones that |
| + // need to be removed from metadata store. |page_ids_to_expire| will have |
| + // the pages to be expired, |page_ids_to_remove| will have the pages to be |
| + // removed. |now| is used to keep the time consistecy with other operations. |
| + void GetPageIdsToClear(const MultipleOfflinePageItemResult& pages, |
| const ArchiveManager::StorageStats& stats, |
| - std::vector<int64_t>& offline_ids); |
| + const base::Time& now, |
| + std::vector<int64_t>* page_ids_to_expire, |
| + std::vector<int64_t>* page_ids_to_remove); |
| // Determine if manager should clear pages. |
| - ClearMode ShouldClearPages(const ArchiveManager::StorageStats& storage_stats); |
| + ClearMode ShouldClearPages(const ArchiveManager::StorageStats& storage_stats, |
| + const base::Time& now); |
| // Return true if |page| is expired comparing to |now|. |
| bool ShouldBeExpired(const base::Time& now, const OfflinePageItem& page); |