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 |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6dda5c8a418f4e480a00bee92ce2d264b3e1dc11 |
| --- /dev/null |
| +++ b/components/offline_pages/offline_page_storage_manager.h |
| @@ -0,0 +1,86 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_STORAGE_MANAGER_H_ |
| +#define COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_STORAGE_MANAGER_H_ |
| + |
| +#include <stdint.h> |
| + |
| +#include <vector> |
| + |
| +#include "base/callback.h" |
| +#include "base/macros.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "components/offline_pages/offline_page_model.h" |
| + |
| +namespace offline_pages { |
| + |
| +// TODO(romax): Keep this as a default value until I find a way to get |
| +// storage size in C++. (20MB) |
| +static const int64_t kDefaultStorageSize = 20 * (1 << 20); |
| + |
| +class ClientPolicyController; |
| +struct OfflinePageItem; |
| + |
| +// 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. |
| +// It has its own throttle mechanism so calling the method would not be |
| +// guaranteed to clear the pages immediately. |
| +// |
| +// OfflinePageModel should own and control the lifecycle of this manager. |
| +// And this manager would use OfflinePageModel to get/remove pages. |
| +class OfflinePageStorageManager { |
| + public: |
| + // Callback used when calling ClearPagesIfNeeded. |
| + // int: the number of deleted pages. |
| + // DeletePageResult: result of deleting pages. |
| + typedef base::Callback<void(int, OfflinePageModel::DeletePageResult)> |
|
fgorski
2016/05/06 05:57:24
typedef base::Callback<void(int /* number of delet
romax
2016/05/07 02:22:42
i dont see a difference other than making it inlin
|
| + ClearPageCallback; |
| + |
| + explicit OfflinePageStorageManager(OfflinePageModel* model); |
| + |
| + ~OfflinePageStorageManager(); |
| + |
| + // The manager would *try* to clear pages when called. It may not delete any |
| + // pages (if clearing condition wasn't satisfied). |
| + void ClearPagesIfNeeded(const ClearPageCallback& callback); |
| + |
| + private: |
| + // Would be used as callback of GetAllPages(). |
|
fgorski
2016/05/06 05:57:24
Selects and removes pages that need to be expired.
romax
2016/05/07 02:22:42
Done.
fgorski
2016/05/09 20:20:37
no sure you applied first part of the comment
|
| + void PurgePages(const ClearPageCallback& callback, |
| + const OfflinePageModel::MultipleOfflinePageItemResult& pages); |
| + |
| + // Get offline_ids of all expired pages and return in |offline_ids|. |
|
fgorski
2016/05/06 05:57:24
Gets offline IDs of all
romax
2016/05/07 02:22:42
Done.
fgorski
2016/05/09 20:20:37
not sure you applied the comment
|
| + void GetExpiredPageIds( |
| + const OfflinePageModel::MultipleOfflinePageItemResult& pages, |
| + std::vector<int64_t>& offline_ids); |
| + |
| + // Callback when expired pages has been deleted. |
| + void OnExpiredPagesDeleted(const ClearPageCallback& callback, |
| + int pages_to_clear, |
| + OfflinePageModel::DeletePageResult result); |
| + |
| + // Determine if manager should clear pages. |
| + bool ShouldClearPages(); |
| + |
| + // Return true if |page| is expired. |
| + bool IsPageExpired(const OfflinePageItem& page); |
| + |
| + // Not owned. |
| + OfflinePageModel* model_; |
| + |
| + // Not owned. |
| + ClientPolicyController* policy_controller_; |
| + |
| + bool in_progress_; |
| + |
| + base::WeakPtrFactory<OfflinePageStorageManager> weak_ptr_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(OfflinePageStorageManager); |
| +}; |
| + |
| +} // namespace offline_pages |
| + |
| +#endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_STORAGE_MANAGER_H_ |