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

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

Issue 2489443002: Move all components/offline_pages/ files into component/offline_pages/core (Closed)
Patch Set: rebase Created 4 years 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 2015 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_MODEL_H_
6 #define COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_H_
7
8 #include <stdint.h>
9
10 #include <memory>
11 #include <set>
12 #include <string>
13 #include <vector>
14
15 #include "base/supports_user_data.h"
16 #include "components/offline_pages/offline_event_logger.h"
17 #include "components/offline_pages/offline_page_archiver.h"
18 #include "components/offline_pages/offline_page_model_query.h"
19 #include "components/offline_pages/offline_page_storage_manager.h"
20 #include "components/offline_pages/offline_page_types.h"
21
22 class GURL;
23
24 namespace offline_pages {
25
26 struct ClientId;
27
28 // Service for saving pages offline, storing the offline copy and metadata, and
29 // retrieving them upon request.
30 //
31 // Example usage:
32 // class ArchiverImpl : public OfflinePageArchiver {
33 // // This is a class that knows how to create archiver
34 // void CreateArchiver(...) override;
35 // ...
36 // }
37 //
38 // // In code using the OfflinePagesModel to save a page:
39 // std::unique_ptr<ArchiverImpl> archiver(new ArchiverImpl());
40 // // Callback is of type SavePageCallback.
41 // model->SavePage(url, std::move(archiver), callback);
42 //
43 // TODO(fgorski): Things to describe:
44 // * how to cancel requests and what to expect
45 class OfflinePageModel : public base::SupportsUserData {
46 public:
47 // Controls how to search on differnt URLs for pages.
48 enum class URLSearchMode {
49 // Match against the last committed URL only.
50 SEARCH_BY_FINAL_URL_ONLY,
51 // Match against all stored URLs, including the last committed URL and
52 // the original request URL.
53 SEARCH_BY_ALL_URLS
54 };
55
56 // Describes the parameters to control how to save a page.
57 struct SavePageParams {
58 SavePageParams();
59 SavePageParams(const SavePageParams& other);
60
61 // The last committed URL of the page to save.
62 GURL url;
63
64 // The identification used by the client.
65 ClientId client_id;
66
67 // Used for the offline_id for the saved file if non-zero. If it is
68 // kInvalidOfflineId, a new, random ID will be generated.
69 int64_t proposed_offline_id;
70
71 // The original URL of the page to save. Empty if no redirect occurs.
72 GURL original_url;
73 };
74
75 // Observer of the OfflinePageModel.
76 class Observer {
77 public:
78 // Invoked when the model has finished loading.
79 virtual void OfflinePageModelLoaded(OfflinePageModel* model) = 0;
80
81 // Invoked when the model is being updated, due to adding, removing or
82 // updating an offline page.
83 virtual void OfflinePageModelChanged(OfflinePageModel* model) = 0;
84
85 // Invoked when an offline copy related to |offline_id| was deleted.
86 virtual void OfflinePageDeleted(int64_t offline_id,
87 const ClientId& client_id) = 0;
88
89 protected:
90 virtual ~Observer() = default;
91 };
92
93 using CheckPagesExistOfflineResult =
94 offline_pages::CheckPagesExistOfflineResult;
95 using MultipleOfflinePageItemResult =
96 offline_pages::MultipleOfflinePageItemResult;
97 using DeletePageResult = offline_pages::DeletePageResult;
98 using SavePageResult = offline_pages::SavePageResult;
99
100 // Returns true if saving an offline page may be attempted for |url|.
101 static bool CanSaveURL(const GURL& url);
102
103 OfflinePageModel();
104 ~OfflinePageModel() override;
105
106 virtual void AddObserver(Observer* observer) = 0;
107 virtual void RemoveObserver(Observer* observer) = 0;
108
109 static const int64_t kInvalidOfflineId = 0;
110
111 // Attempts to save a page offline per |save_page_params|. Requires that the
112 // model is loaded. Generates a new offline id or uses the proposed offline
113 // id in |save_page_params| and returns it.
114 virtual void SavePage(const SavePageParams& save_page_params,
115 std::unique_ptr<OfflinePageArchiver> archiver,
116 const SavePageCallback& callback) = 0;
117
118 // Marks that the offline page related to the passed |offline_id| has been
119 // accessed. Its access info, including last access time and access count,
120 // will be updated. Requires that the model is loaded.
121 virtual void MarkPageAccessed(int64_t offline_id) = 0;
122
123 // Deletes pages based on |offline_ids|.
124 virtual void DeletePagesByOfflineId(const std::vector<int64_t>& offline_ids,
125 const DeletePageCallback& callback) = 0;
126
127 // Deletes all pages associated with any of |client_ids|.
128 virtual void DeletePagesByClientIds(const std::vector<ClientId>& client_ids,
129 const DeletePageCallback& callback) = 0;
130
131 virtual void GetPagesMatchingQuery(
132 std::unique_ptr<OfflinePageModelQuery> query,
133 const MultipleOfflinePageItemCallback& callback) = 0;
134
135 // Retrieves all pages associated with any of |client_ids|.
136 virtual void GetPagesByClientIds(
137 const std::vector<ClientId>& client_ids,
138 const MultipleOfflinePageItemCallback& callback) = 0;
139
140 // Deletes cached offline pages matching the URL predicate.
141 virtual void DeleteCachedPagesByURLPredicate(
142 const UrlPredicate& predicate,
143 const DeletePageCallback& callback) = 0;
144
145 // Returns via callback all GURLs in |urls| that are equal to the online URL
146 // of any offline page.
147 virtual void CheckPagesExistOffline(
148 const std::set<GURL>& urls,
149 const CheckPagesExistOfflineCallback& callback) = 0;
150
151 // Gets all offline pages.
152 virtual void GetAllPages(const MultipleOfflinePageItemCallback& callback) = 0;
153
154 // Gets all offline ids where the offline page has the matching client id.
155 virtual void GetOfflineIdsForClientId(
156 const ClientId& client_id,
157 const MultipleOfflineIdCallback& callback) = 0;
158
159 // Returns zero or one offline pages associated with a specified |offline_id|.
160 virtual void GetPageByOfflineId(
161 int64_t offline_id,
162 const SingleOfflinePageItemCallback& callback) = 0;
163
164 // Returns the offline pages that are related to |url|. |url_search_mode|
165 // controls how the url match is done. See URLSearchMode for more details.
166 virtual void GetPagesByURL(
167 const GURL& url,
168 URLSearchMode url_search_mode,
169 const MultipleOfflinePageItemCallback& callback) = 0;
170
171 // Returns the policy controller.
172 virtual ClientPolicyController* GetPolicyController() = 0;
173
174 // TODO(dougarnett): Remove this and its uses.
175 virtual bool is_loaded() const = 0;
176
177 // Returns the logger. Ownership is retained by the model.
178 virtual OfflineEventLogger* GetLogger() = 0;
179 };
180
181 } // namespace offline_pages
182
183 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_H_
OLDNEW
« no previous file with comments | « components/offline_pages/offline_page_metadata_store_sql.cc ('k') | components/offline_pages/offline_page_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698