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

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: Simplifying interface per suggestion. 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 16
17 namespace offline_pages { 17 namespace offline_pages {
18 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; 19 class ClientPolicyController;
24 struct OfflinePageItem;
25 20
26 // This class is used for storage management of offline pages. It provides 21 // This class is used for storage management of offline pages. It provides
27 // a ClearPagesIfNeeded method which is used to clear expired offline pages 22 // a ClearPagesIfNeeded method which is used to clear expired offline pages
28 // based on last_access_time and lifetime policy of its namespace. 23 // 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 24 // It has its own throttle mechanism so calling the method would not be
30 // guaranteed to clear the pages immediately. 25 // guaranteed to clear the pages immediately.
31 // 26 //
32 // OfflinePageModel should own and control the lifecycle of this manager. 27 // OfflinePageModel should own and control the lifecycle of this manager.
33 // And this manager would use OfflinePageModel to get/remove pages. 28 // And this manager would use OfflinePageModel to get/remove pages.
34 class OfflinePageStorageManager { 29 class OfflinePageStorageManager {
35 public: 30 public:
31 // This interface should have no knowledge of offline page model.
32 // This interface should be implemented by clients managed by storage manager.
33 class Client {
34 public:
35 // Asks the client to get all offline pages and invoke |callback|.
36 virtual void GetAllPages(
37 const MultipleOfflinePageItemCallback& callback) = 0;
38
39 // Asks the client to delete pages based on |offline_ids| and invoke
40 // |callback|.
41 virtual void DeletePagesByOfflineId(const std::vector<int64_t>& offline_ids,
42 const DeletePageCallback& callback) = 0;
43 };
44
36 // Callback used when calling ClearPagesIfNeeded. 45 // Callback used when calling ClearPagesIfNeeded.
37 // int: the number of deleted pages. 46 // int: the number of deleted pages.
38 // DeletePageResult: result of deleting pages. 47 // DeletePageResult: result of deleting pages.
39 typedef base::Callback<void(int, OfflinePageModel::DeletePageResult)> 48 typedef base::Callback<void(int, DeletePageResult)> ClearPageCallback;
40 ClearPageCallback;
41 49
42 explicit OfflinePageStorageManager(OfflinePageModel* model); 50 explicit OfflinePageStorageManager(Client* client,
51 ClientPolicyController* policy_controller);
43 52
44 ~OfflinePageStorageManager(); 53 ~OfflinePageStorageManager();
45 54
46 // The manager would *try* to clear pages when called. It may not delete any 55 // The manager would *try* to clear pages when called. It may not delete any
47 // pages (if clearing condition wasn't satisfied). 56 // pages (if clearing condition wasn't satisfied).
48 void ClearPagesIfNeeded(const ClearPageCallback& callback); 57 void ClearPagesIfNeeded(const ClearPageCallback& callback);
49 58
50 private: 59 private:
51 // Selects and removes pages that need to be expired. Triggered as a callback 60 // Selects and removes pages that need to be expired. Triggered as a callback
52 // to |GetAllPages|. 61 // to |GetAllPages|.
53 void ClearExpiredPages( 62 void ClearExpiredPages(const ClearPageCallback& callback,
54 const ClearPageCallback& callback, 63 const MultipleOfflinePageItemResult& pages);
55 const OfflinePageModel::MultipleOfflinePageItemResult& pages);
56 64
57 // Gets offline IDs of all expired pages and return in |offline_ids|. 65 // Gets offline IDs of all expired pages and return in |offline_ids|.
58 void GetExpiredPageIds( 66 void GetExpiredPageIds(const MultipleOfflinePageItemResult& pages,
59 const OfflinePageModel::MultipleOfflinePageItemResult& pages, 67 std::vector<int64_t>& offline_ids);
60 std::vector<int64_t>& offline_ids);
61 68
62 // Callback when expired pages has been deleted. 69 // Callback when expired pages has been deleted.
63 void OnExpiredPagesDeleted(const ClearPageCallback& callback, 70 void OnExpiredPagesDeleted(const ClearPageCallback& callback,
64 int pages_to_clear, 71 int pages_to_clear,
65 OfflinePageModel::DeletePageResult result); 72 DeletePageResult result);
66 73
67 // Determine if manager should clear pages. 74 // Determine if manager should clear pages.
68 bool ShouldClearPages(); 75 bool ShouldClearPages();
69 76
70 // Return true if |page| is expired. 77 // Return true if |page| is expired.
71 bool IsPageExpired(const OfflinePageItem& page); 78 bool IsPageExpired(const OfflinePageItem& page);
72 79
73 // Not owned. 80 // Not owned.
74 OfflinePageModel* model_; 81 Client* client_;
75 82
76 // Not owned. 83 // Not owned.
77 ClientPolicyController* policy_controller_; 84 ClientPolicyController* policy_controller_;
78 85
79 bool in_progress_; 86 bool in_progress_;
80 87
81 base::WeakPtrFactory<OfflinePageStorageManager> weak_ptr_factory_; 88 base::WeakPtrFactory<OfflinePageStorageManager> weak_ptr_factory_;
82 89
83 DISALLOW_COPY_AND_ASSIGN(OfflinePageStorageManager); 90 DISALLOW_COPY_AND_ASSIGN(OfflinePageStorageManager);
84 }; 91 };
85 92
86 } // namespace offline_pages 93 } // namespace offline_pages
87 94
88 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_STORAGE_MANAGER_H_ 95 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_STORAGE_MANAGER_H_
OLDNEW
« no previous file with comments | « components/offline_pages/offline_page_model.cc ('k') | components/offline_pages/offline_page_storage_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698