Chromium Code Reviews| 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> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "components/offline_pages/offline_page_types.h" | 15 #include "components/offline_pages/offline_page_types.h" |
| 16 | 16 |
| 17 namespace base { | |
| 18 class Clock; | |
| 19 } | |
| 20 | |
| 17 namespace offline_pages { | 21 namespace offline_pages { |
| 18 | 22 |
| 19 class ClientPolicyController; | 23 class ClientPolicyController; |
| 20 | 24 |
| 21 // This class is used for storage management of offline pages. It provides | 25 // This class is used for storage management of offline pages. It provides |
| 22 // a ClearPagesIfNeeded method which is used to clear expired offline pages | 26 // a ClearPagesIfNeeded method which is used to clear expired offline pages |
| 23 // based on last_access_time and lifetime policy of its namespace. | 27 // based on last_access_time and lifetime policy of its namespace. |
| 24 // It has its own throttle mechanism so calling the method would not be | 28 // It has its own throttle mechanism so calling the method would not be |
| 25 // guaranteed to clear the pages immediately. | 29 // guaranteed to clear the pages immediately. |
| 26 // | 30 // |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 50 explicit OfflinePageStorageManager(Client* client, | 54 explicit OfflinePageStorageManager(Client* client, |
| 51 ClientPolicyController* policy_controller); | 55 ClientPolicyController* policy_controller); |
| 52 | 56 |
| 53 ~OfflinePageStorageManager(); | 57 ~OfflinePageStorageManager(); |
| 54 | 58 |
| 55 // The manager would *try* to clear pages when called. It may not delete any | 59 // The manager would *try* to clear pages when called. It may not delete any |
| 56 // pages (if clearing condition wasn't satisfied). | 60 // pages (if clearing condition wasn't satisfied). |
| 57 void ClearPagesIfNeeded(const ClearPageCallback& callback); | 61 void ClearPagesIfNeeded(const ClearPageCallback& callback); |
| 58 | 62 |
| 59 private: | 63 private: |
| 64 friend class OfflinePageStorageManagerTest; | |
| 65 | |
| 60 // Selects and removes pages that need to be expired. Triggered as a callback | 66 // Selects and removes pages that need to be expired. Triggered as a callback |
| 61 // to |GetAllPages|. | 67 // to |GetAllPages|. |
| 62 void ClearExpiredPages(const ClearPageCallback& callback, | 68 void ClearExpiredPages(const ClearPageCallback& callback, |
| 63 const MultipleOfflinePageItemResult& pages); | 69 const MultipleOfflinePageItemResult& pages); |
| 64 | 70 |
| 65 // Gets offline IDs of all expired pages and return in |offline_ids|. | 71 // Gets offline IDs of all expired pages and return in |offline_ids|. |
| 66 void GetExpiredPageIds(const MultipleOfflinePageItemResult& pages, | 72 void GetExpiredPageIds(const MultipleOfflinePageItemResult& pages, |
| 67 std::vector<int64_t>& offline_ids); | 73 std::vector<int64_t>& offline_ids); |
| 68 | 74 |
| 69 // Callback when expired pages has been deleted. | 75 // Callback when expired pages has been deleted. |
| 70 void OnExpiredPagesDeleted(const ClearPageCallback& callback, | 76 void OnExpiredPagesDeleted(const ClearPageCallback& callback, |
| 71 int pages_to_clear, | 77 int pages_to_clear, |
| 72 DeletePageResult result); | 78 DeletePageResult result); |
| 73 | 79 |
| 74 // Determine if manager should clear pages. | 80 // Determine if manager should clear pages. |
| 75 bool ShouldClearPages(); | 81 bool ShouldClearPages(); |
| 76 | 82 |
| 77 // Return true if |page| is expired. | 83 // Return true if |page| is expired comparing to |now|. |
| 78 bool IsPageExpired(const OfflinePageItem& page); | 84 bool ShouldBeExpired(const base::Time& now, const OfflinePageItem& page); |
| 85 | |
| 86 // Sets the clock for testing. | |
| 87 void SetClockForTesting(std::unique_ptr<base::Clock> clock); | |
|
fgorski
2016/05/12 22:34:25
make this public and don't friend the test class.
romax
2016/05/12 23:31:20
Done.
| |
| 79 | 88 |
| 80 // Not owned. | 89 // Not owned. |
| 81 Client* client_; | 90 Client* client_; |
| 82 | 91 |
| 83 // Not owned. | 92 // Not owned. |
| 84 ClientPolicyController* policy_controller_; | 93 ClientPolicyController* policy_controller_; |
| 85 | 94 |
| 86 bool in_progress_; | 95 bool in_progress_; |
| 87 | 96 |
| 97 // Clock for getting time. | |
| 98 std::unique_ptr<base::Clock> clock_; | |
| 99 | |
| 88 base::WeakPtrFactory<OfflinePageStorageManager> weak_ptr_factory_; | 100 base::WeakPtrFactory<OfflinePageStorageManager> weak_ptr_factory_; |
| 89 | 101 |
| 90 DISALLOW_COPY_AND_ASSIGN(OfflinePageStorageManager); | 102 DISALLOW_COPY_AND_ASSIGN(OfflinePageStorageManager); |
| 91 }; | 103 }; |
| 92 | 104 |
| 93 } // namespace offline_pages | 105 } // namespace offline_pages |
| 94 | 106 |
| 95 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_STORAGE_MANAGER_H_ | 107 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_STORAGE_MANAGER_H_ |
| OLD | NEW |