Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Side by Side Diff: components/offline_pages/offline_page_storage_manager.h

Issue 1970953002: [Offline Pages] Adding more expiration logic. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@interface
Patch Set: More comments. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | components/offline_pages/offline_page_storage_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 22 matching lines...) Expand all
49 53
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
63 // Sets the clock for testing.
64 void SetClockForTesting(std::unique_ptr<base::Clock> clock);
65
59 private: 66 private:
60 // Selects and removes pages that need to be expired. Triggered as a callback 67 // Selects and removes pages that need to be expired. Triggered as a callback
61 // to |GetAllPages|. 68 // to |GetAllPages|.
62 void ClearExpiredPages(const ClearPageCallback& callback, 69 void ClearExpiredPages(const ClearPageCallback& callback,
63 const MultipleOfflinePageItemResult& pages); 70 const MultipleOfflinePageItemResult& pages);
64 71
65 // Gets offline IDs of all expired pages and return in |offline_ids|. 72 // Gets offline IDs of all expired pages and return in |offline_ids|.
66 void GetExpiredPageIds(const MultipleOfflinePageItemResult& pages, 73 void GetExpiredPageIds(const MultipleOfflinePageItemResult& pages,
67 std::vector<int64_t>& offline_ids); 74 std::vector<int64_t>& offline_ids);
68 75
69 // Callback when expired pages has been deleted. 76 // Callback when expired pages has been deleted.
70 void OnExpiredPagesDeleted(const ClearPageCallback& callback, 77 void OnExpiredPagesDeleted(const ClearPageCallback& callback,
71 int pages_to_clear, 78 int pages_to_clear,
72 DeletePageResult result); 79 DeletePageResult result);
73 80
74 // Determine if manager should clear pages. 81 // Determine if manager should clear pages.
75 bool ShouldClearPages(); 82 bool ShouldClearPages();
76 83
77 // Return true if |page| is expired. 84 // Return true if |page| is expired comparing to |now|.
78 bool IsPageExpired(const OfflinePageItem& page); 85 bool ShouldBeExpired(const base::Time& now, const OfflinePageItem& page);
79 86
80 // Not owned. 87 // Not owned.
81 Client* client_; 88 Client* client_;
82 89
83 // Not owned. 90 // Not owned.
84 ClientPolicyController* policy_controller_; 91 ClientPolicyController* policy_controller_;
85 92
86 bool in_progress_; 93 bool in_progress_;
87 94
95 // Clock for getting time.
96 std::unique_ptr<base::Clock> clock_;
97
88 base::WeakPtrFactory<OfflinePageStorageManager> weak_ptr_factory_; 98 base::WeakPtrFactory<OfflinePageStorageManager> weak_ptr_factory_;
89 99
90 DISALLOW_COPY_AND_ASSIGN(OfflinePageStorageManager); 100 DISALLOW_COPY_AND_ASSIGN(OfflinePageStorageManager);
91 }; 101 };
92 102
93 } // namespace offline_pages 103 } // namespace offline_pages
94 104
95 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_STORAGE_MANAGER_H_ 105 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_STORAGE_MANAGER_H_
OLDNEW
« no previous file with comments | « no previous file | components/offline_pages/offline_page_storage_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698