| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_STORAGE_MANAGER_H_ |
| 6 #define COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_STORAGE_MANAGER_H_ |
| 7 |
| 8 #include <stdint.h> |
| 9 |
| 10 #include <vector> |
| 11 |
| 12 #include "base/callback.h" |
| 13 #include "base/macros.h" |
| 14 #include "base/memory/weak_ptr.h" |
| 15 #include "components/offline_pages/offline_page_model.h" |
| 16 |
| 17 namespace offline_pages { |
| 18 |
| 19 // TODO(romax): Keep this as a default value until I find a way to get |
| 20 // storage size in C++. (20MB) |
| 21 static const int64_t kDefaultStorageSize = 20 * (1 << 20); |
| 22 |
| 23 class ClientPolicyController; |
| 24 struct OfflinePageItem; |
| 25 |
| 26 // This class is used for storage management of offline pages. It provides |
| 27 // a ClearPagesIfNeeded method which is used to clear expired offline pages |
| 28 // based on last_access_time and lifetime policy of its namespace. |
| 29 // It has its own throttle mechanism so calling the method would not be |
| 30 // guaranteed to clear the pages immediately. |
| 31 // |
| 32 // OfflinePageModel should own and control the lifecycle of this manager. |
| 33 // And this manager would use OfflinePageModel to get/remove pages. |
| 34 class OfflinePageStorageManager { |
| 35 public: |
| 36 // Callback used when calling ClearPagesIfNeeded. |
| 37 // int: the number of deleted pages. |
| 38 // DeletePageResult: result of deleting pages. |
| 39 typedef base::Callback<void(int, OfflinePageModel::DeletePageResult)> |
| 40 ClearPageCallback; |
| 41 |
| 42 explicit OfflinePageStorageManager(OfflinePageModel* model); |
| 43 |
| 44 ~OfflinePageStorageManager(); |
| 45 |
| 46 // The manager would *try* to clear pages when called. It may not delete any |
| 47 // pages (if clearing condition wasn't satisfied). |
| 48 void ClearPagesIfNeeded(const ClearPageCallback& callback); |
| 49 |
| 50 private: |
| 51 // Selects and removes pages that need to be expired. Triggered as a callback |
| 52 // to |GetAllPages|. |
| 53 void ClearExpiredPages( |
| 54 const ClearPageCallback& callback, |
| 55 const OfflinePageModel::MultipleOfflinePageItemResult& pages); |
| 56 |
| 57 // Gets offline IDs of all expired pages and return in |offline_ids|. |
| 58 void GetExpiredPageIds( |
| 59 const OfflinePageModel::MultipleOfflinePageItemResult& pages, |
| 60 std::vector<int64_t>& offline_ids); |
| 61 |
| 62 // Callback when expired pages has been deleted. |
| 63 void OnExpiredPagesDeleted(const ClearPageCallback& callback, |
| 64 int pages_to_clear, |
| 65 OfflinePageModel::DeletePageResult result); |
| 66 |
| 67 // Determine if manager should clear pages. |
| 68 bool ShouldClearPages(); |
| 69 |
| 70 // Return true if |page| is expired. |
| 71 bool IsPageExpired(const OfflinePageItem& page); |
| 72 |
| 73 // Not owned. |
| 74 OfflinePageModel* model_; |
| 75 |
| 76 // Not owned. |
| 77 ClientPolicyController* policy_controller_; |
| 78 |
| 79 bool in_progress_; |
| 80 |
| 81 base::WeakPtrFactory<OfflinePageStorageManager> weak_ptr_factory_; |
| 82 |
| 83 DISALLOW_COPY_AND_ASSIGN(OfflinePageStorageManager); |
| 84 }; |
| 85 |
| 86 } // namespace offline_pages |
| 87 |
| 88 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_STORAGE_MANAGER_H_ |
| OLD | NEW |