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

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

Issue 1965633002: [Offline Pages] Introducing StorageManagerClient interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebasing after extracting callbacks. 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
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_model.h" 15 #include "components/offline_pages/offline_page_types.h"
16 #include "components/offline_pages/storage_manager_client.h"
16 17
17 namespace offline_pages { 18 namespace offline_pages {
18 19
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 20 // This class is used for storage management of offline pages. It provides
27 // a ClearPagesIfNeeded method which is used to clear expired offline pages 21 // a ClearPagesIfNeeded method which is used to clear expired offline pages
28 // based on last_access_time and lifetime policy of its namespace. 22 // 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 23 // It has its own throttle mechanism so calling the method would not be
30 // guaranteed to clear the pages immediately. 24 // guaranteed to clear the pages immediately.
31 // 25 //
32 // OfflinePageModel should own and control the lifecycle of this manager. 26 // OfflinePageModel should own and control the lifecycle of this manager.
33 // And this manager would use OfflinePageModel to get/remove pages. 27 // And this manager would use OfflinePageModel to get/remove pages.
34 class OfflinePageStorageManager { 28 class OfflinePageStorageManager {
35 public: 29 public:
36 // Callback used when calling ClearPagesIfNeeded. 30 // Callback used when calling ClearPagesIfNeeded.
37 // int: the number of deleted pages. 31 // int: the number of deleted pages.
38 // DeletePageResult: result of deleting pages. 32 // DeletePageResult: result of deleting pages.
39 typedef base::Callback<void(int, OfflinePageModel::DeletePageResult)> 33 typedef base::Callback<void(int, DeletePageResult)> ClearPageCallback;
40 ClearPageCallback;
41 34
42 explicit OfflinePageStorageManager(OfflinePageModel* model); 35 explicit OfflinePageStorageManager(StorageManagerClient* client);
43 36
44 ~OfflinePageStorageManager(); 37 ~OfflinePageStorageManager();
45 38
46 // The manager would *try* to clear pages when called. It may not delete any 39 // The manager would *try* to clear pages when called. It may not delete any
47 // pages (if clearing condition wasn't satisfied). 40 // pages (if clearing condition wasn't satisfied).
48 void ClearPagesIfNeeded(const ClearPageCallback& callback); 41 void ClearPagesIfNeeded(const ClearPageCallback& callback);
49 42
50 private: 43 private:
51 // Selects and removes pages that need to be expired. Triggered as a callback 44 // Selects and removed pages that need to be expired. Triggered as a callback
fgorski 2016/05/11 22:39:00 why this change?
romax 2016/05/11 23:54:58 might be random edits. I think i should prevent th
52 // to |GetAllPages|. 45 // to |GetAllPages|.
53 void ClearExpiredPages( 46 void ClearExpiredPages(const ClearPageCallback& callback,
54 const ClearPageCallback& callback, 47 const MultipleOfflinePageItemResult& pages);
55 const OfflinePageModel::MultipleOfflinePageItemResult& pages);
56 48
57 // Gets offline IDs of all expired pages and return in |offline_ids|. 49 // Get offline IDs of all expired pages and return in |offline_ids|.
fgorski 2016/05/11 22:39:00 why this change? the full sentence would be: this
romax 2016/05/11 23:54:58 same as above..
58 void GetExpiredPageIds( 50 void GetExpiredPageIds(const MultipleOfflinePageItemResult& pages,
59 const OfflinePageModel::MultipleOfflinePageItemResult& pages, 51 std::vector<int64_t>& offline_ids);
60 std::vector<int64_t>& offline_ids);
61 52
62 // Callback when expired pages has been deleted. 53 // Callback when expired pages has been deleted.
63 void OnExpiredPagesDeleted(const ClearPageCallback& callback, 54 void OnExpiredPagesDeleted(const ClearPageCallback& callback,
64 int pages_to_clear, 55 int pages_to_clear,
65 OfflinePageModel::DeletePageResult result); 56 DeletePageResult result);
66 57
67 // Determine if manager should clear pages. 58 // Determine if manager should clear pages.
68 bool ShouldClearPages(); 59 bool ShouldClearPages();
69 60
70 // Return true if |page| is expired. 61 // Return true if |page| is expired.
71 bool IsPageExpired(const OfflinePageItem& page); 62 bool IsPageExpired(const OfflinePageItem& page);
72 63
73 // Not owned. 64 // Not owned.
74 OfflinePageModel* model_; 65 StorageManagerClient* client_;
75 66
76 // Not owned. 67 // Not owned.
77 ClientPolicyController* policy_controller_; 68 ClientPolicyController* policy_controller_;
78 69
79 bool in_progress_; 70 bool in_progress_;
80 71
81 base::WeakPtrFactory<OfflinePageStorageManager> weak_ptr_factory_; 72 base::WeakPtrFactory<OfflinePageStorageManager> weak_ptr_factory_;
82 73
83 DISALLOW_COPY_AND_ASSIGN(OfflinePageStorageManager); 74 DISALLOW_COPY_AND_ASSIGN(OfflinePageStorageManager);
84 }; 75 };
85 76
86 } // namespace offline_pages 77 } // namespace offline_pages
87 78
88 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_STORAGE_MANAGER_H_ 79 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_STORAGE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698