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

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

Issue 1947323002: [Offline Pages] Implement OfflinePageStorageManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
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
OLDNEW
(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)>
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
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 // 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
52 void PurgePages(const ClearPageCallback& callback,
53 const OfflinePageModel::MultipleOfflinePageItemResult& pages);
54
55 // 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
56 void GetExpiredPageIds(
57 const OfflinePageModel::MultipleOfflinePageItemResult& pages,
58 std::vector<int64_t>& offline_ids);
59
60 // Callback when expired pages has been deleted.
61 void OnExpiredPagesDeleted(const ClearPageCallback& callback,
62 int pages_to_clear,
63 OfflinePageModel::DeletePageResult result);
64
65 // Determine if manager should clear pages.
66 bool ShouldClearPages();
67
68 // Return true if |page| is expired.
69 bool IsPageExpired(const OfflinePageItem& page);
70
71 // Not owned.
72 OfflinePageModel* model_;
73
74 // Not owned.
75 ClientPolicyController* policy_controller_;
76
77 bool in_progress_;
78
79 base::WeakPtrFactory<OfflinePageStorageManager> weak_ptr_factory_;
80
81 DISALLOW_COPY_AND_ASSIGN(OfflinePageStorageManager);
82 };
83
84 } // namespace offline_pages
85
86 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_STORAGE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698