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 eebcff6c4538c66f0200b30d4008f80df6eceeb5..288873431ebba42fc4625c4a8883eba085842f68 100644 |
| --- a/components/offline_pages/offline_page_storage_manager.h |
| +++ b/components/offline_pages/offline_page_storage_manager.h |
| @@ -12,8 +12,10 @@ |
| #include "base/callback.h" |
| #include "base/macros.h" |
| #include "base/memory/weak_ptr.h" |
| +#include "base/time/time.h" |
| #include "components/offline_pages/offline_page_types.h" |
| +class PrefService; |
| namespace base { |
| class Clock; |
| } |
| @@ -22,6 +24,15 @@ namespace offline_pages { |
| class ClientPolicyController; |
| +// Limit of the total storage space occupied by offline pages should be minimal |
| +// of (50 MB, 10% of available storage space). |
|
fgorski
2016/05/17 05:33:29
where did the second number come from?
romax
2016/05/18 02:36:19
it's from the Offline Page Cache prd. second point
|
| +static const int64_t kOfflinePageStorageLimit = 50 * (1 << 20); |
| +static const double kOfflinePageStorageLimitPercentage = 0.1; |
| +static const base::TimeDelta kClearStorageTimeGap = |
|
fgorski
2016/05/17 05:33:29
kClearStorageInterval
romax
2016/05/18 02:36:19
Done.
|
| + base::TimeDelta::FromHours(6); |
| +static const char kOfflinePageStorageLastClearedTime[] = |
|
fgorski
2016/05/17 05:33:29
isn't this defined already?
If unaccessible, this
romax
2016/05/18 02:36:20
yes it was unaccessible. removing since we no long
|
| + "offline_page.storage.last_cleared_time"; |
| + |
| // This class is used for storage management of offline pages. It provides |
| // a ClearPagesIfNeeded method which is used to clear expired offline pages |
| // based on last_access_time and lifetime policy of its namespace. |
| @@ -46,13 +57,20 @@ class OfflinePageStorageManager { |
| const DeletePageCallback& callback) = 0; |
| }; |
| + enum class StorageClearResult { |
| + SUCCESS, // Cleared successfully. |
| + UNNECESSARY, // No expired pages. |
| + DELETE_FAIL, // Deletion failed. |
|
fgorski
2016/05/17 05:33:29
FAILURE?
romax
2016/05/18 02:36:20
Done.
|
| + }; |
| + |
| // Callback used when calling ClearPagesIfNeeded. |
| // int: the number of deleted pages. |
| // DeletePageResult: result of deleting pages. |
| - typedef base::Callback<void(int, DeletePageResult)> ClearPageCallback; |
| + typedef base::Callback<void(int, StorageClearResult)> ClearPageCallback; |
| explicit OfflinePageStorageManager(Client* client, |
| - ClientPolicyController* policy_controller); |
| + ClientPolicyController* policy_controller, |
| + PrefService* prefs); |
| ~OfflinePageStorageManager(); |
| @@ -64,6 +82,13 @@ class OfflinePageStorageManager { |
| void SetClockForTesting(std::unique_ptr<base::Clock> clock); |
| private: |
| + // Enum indicating how to clear the pages. |
| + enum class ClearMode { |
| + DEFAULT, // Using normal expiration logic. |
| + CLEAR_ALL, // Remove all offline pages. |
| + NO_NEED, // No need to remove any page. |
|
fgorski
2016/05/17 05:33:29
Please explain that a bit better.
romax
2016/05/18 02:36:20
Done.
|
| + }; |
| + |
| // Selects and removes pages that need to be expired. Triggered as a callback |
| // to |GetAllPages|. |
| void ClearExpiredPages(const ClearPageCallback& callback, |
| @@ -79,7 +104,7 @@ class OfflinePageStorageManager { |
| DeletePageResult result); |
| // Determine if manager should clear pages. |
| - bool ShouldClearPages(); |
| + ClearMode ShouldClearPages(const MultipleOfflinePageItemResult& pages); |
| // Return true if |page| is expired comparing to |now|. |
| bool ShouldBeExpired(const base::Time& now, const OfflinePageItem& page); |
| @@ -90,6 +115,9 @@ class OfflinePageStorageManager { |
| // Not owned. |
| ClientPolicyController* policy_controller_; |
| + // Not owned, PrefService which is used to store last clear time. |
| + PrefService* prefs_; |
| + |
| bool in_progress_; |
| // Clock for getting time. |