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

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

Issue 1694863003: Refactor the offline page storage to include client namespace and id. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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 2015 The Chromium Authors. All rights reserved. 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 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_MODEL_H_ 5 #ifndef COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_H_
6 #define COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_H_ 6 #define COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
(...skipping 19 matching lines...) Expand all
30 class SequencedTaskRunner; 30 class SequencedTaskRunner;
31 class Time; 31 class Time;
32 class TimeDelta; 32 class TimeDelta;
33 } 33 }
34 namespace bookmarks { 34 namespace bookmarks {
35 class BookmarkModel; 35 class BookmarkModel;
36 } 36 }
37 37
38 namespace offline_pages { 38 namespace offline_pages {
39 39
40 class ClientId;
41
40 struct OfflinePageItem; 42 struct OfflinePageItem;
41 class OfflinePageMetadataStore; 43 class OfflinePageMetadataStore;
42 44
43 // Service for saving pages offline, storing the offline copy and metadata, and 45 // Service for saving pages offline, storing the offline copy and metadata, and
44 // retrieving them upon request. 46 // retrieving them upon request.
45 // 47 //
46 // Example usage: 48 // Example usage:
47 // class ArchiverImpl : public OfflinePageArchiver { 49 // class ArchiverImpl : public OfflinePageArchiver {
48 // // This is a class that knows how to create archiver 50 // // This is a class that knows how to create archiver
49 // void CreateArchiver(...) override; 51 // void CreateArchiver(...) override;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 // Observer of the OfflinePageModel. 107 // Observer of the OfflinePageModel.
106 class Observer { 108 class Observer {
107 public: 109 public:
108 // Invoked when the model has finished loading. 110 // Invoked when the model has finished loading.
109 virtual void OfflinePageModelLoaded(OfflinePageModel* model) = 0; 111 virtual void OfflinePageModelLoaded(OfflinePageModel* model) = 0;
110 112
111 // Invoked when the model is being updated, due to adding, removing or 113 // Invoked when the model is being updated, due to adding, removing or
112 // updating an offline page. 114 // updating an offline page.
113 virtual void OfflinePageModelChanged(OfflinePageModel* model) = 0; 115 virtual void OfflinePageModelChanged(OfflinePageModel* model) = 0;
114 116
115 // Invoked when an offline copy related to |bookmark_id| was deleted. 117 // Invoked when an offline copy related to |offline_id| was deleted.
116 // In can be invoked as a result of |CheckForExternalFileDeletion|, if a 118 // In can be invoked as a result of |CheckForExternalFileDeletion|, if a
117 // deleted page is detected. 119 // deleted page is detected.
118 virtual void OfflinePageDeleted(int64_t bookmark_id) = 0; 120 virtual void OfflinePageDeleted(int64_t offline_id) = 0;
119 121
120 protected: 122 protected:
121 virtual ~Observer() {} 123 virtual ~Observer() {}
122 }; 124 };
123 125
124 typedef base::Callback<void(SavePageResult)> SavePageCallback; 126 typedef base::Callback<void(SavePageResult)> SavePageCallback;
125 typedef base::Callback<void(DeletePageResult)> DeletePageCallback; 127 typedef base::Callback<void(DeletePageResult)> DeletePageCallback;
126 128
127 // Returns true if an offline copy can be saved for the given URL. 129 // Returns true if an offline copy can be saved for the given URL.
128 static bool CanSavePage(const GURL& url); 130 static bool CanSavePage(const GURL& url);
(...skipping 14 matching lines...) Expand all
143 145
144 // KeyedService implementation. 146 // KeyedService implementation.
145 void Shutdown() override; 147 void Shutdown() override;
146 148
147 void AddObserver(Observer* observer); 149 void AddObserver(Observer* observer);
148 void RemoveObserver(Observer* observer); 150 void RemoveObserver(Observer* observer);
149 151
150 // Attempts to save a page addressed by |url| offline. Requires that the model 152 // Attempts to save a page addressed by |url| offline. Requires that the model
151 // is loaded. 153 // is loaded.
152 void SavePage(const GURL& url, 154 void SavePage(const GURL& url,
153 int64_t bookmark_id, 155 int64_t offline_id,
Dmitry Titov 2016/02/12 21:46:51 I don't know if you want to remove this parameter
bburns 2016/02/20 01:14:18 yes, I will do this in the next CL.
156 const ClientId& client_id,
154 scoped_ptr<OfflinePageArchiver> archiver, 157 scoped_ptr<OfflinePageArchiver> archiver,
155 const SavePageCallback& callback); 158 const SavePageCallback& callback);
156 159
157 // Marks that the offline page related to the passed |bookmark_id| has been 160 // Marks that the offline page related to the passed |offline_id| has been
158 // accessed. Its access info, including last access time and access count, 161 // accessed. Its access info, including last access time and access count,
159 // will be updated. Requires that the model is loaded. 162 // will be updated. Requires that the model is loaded.
160 void MarkPageAccessed(int64_t bookmark_id); 163 void MarkPageAccessed(int64_t offline_id);
161 164
162 // Marks that the offline page related to the passed |bookmark_id| was going 165 // Marks that the offline page related to the passed |offline_id| was going
163 // to be deleted. The deletion will occur in a short while. The undo can be 166 // to be deleted. The deletion will occur in a short while. The undo can be
164 // done before this. Requires that the model is loaded. 167 // done before this. Requires that the model is loaded.
165 void MarkPageForDeletion(int64_t bookmark_id, 168 void MarkPageForDeletion(int64_t offline_id,
166 const DeletePageCallback& callback); 169 const DeletePageCallback& callback);
167 170
168 // Deletes an offline page related to the passed |bookmark_id|. Requires that 171 // Deletes an offline page related to the passed |offline_id|. Requires that
169 // the model is loaded. 172 // the model is loaded.
170 void DeletePageByBookmarkId(int64_t bookmark_id, 173 void DeletePageByOfflineId(int64_t offline_id,
171 const DeletePageCallback& callback); 174 const DeletePageCallback& callback);
172 175
173 // Deletes offline pages related to the passed |bookmark_ids|. Requires that 176 // Deletes offline pages related to the passed |offline_ids|. Requires that
174 // the model is loaded. 177 // the model is loaded.
175 void DeletePagesByBookmarkId(const std::vector<int64_t>& bookmark_ids, 178 void DeletePagesByOfflineId(const std::vector<int64_t>& offline_ids,
176 const DeletePageCallback& callback); 179 const DeletePageCallback& callback);
177 180
178 // Wipes out all the data by deleting all saved files and clearing the store. 181 // Wipes out all the data by deleting all saved files and clearing the store.
179 void ClearAll(const base::Closure& callback); 182 void ClearAll(const base::Closure& callback);
180 183
181 // Returns true if there're offline pages. 184 // Returns true if there're offline pages.
182 bool HasOfflinePages() const; 185 bool HasOfflinePages() const;
183 186
184 // Gets all available offline pages. Requires that the model is loaded. 187 // Gets all available offline pages. Requires that the model is loaded.
185 const std::vector<OfflinePageItem> GetAllPages() const; 188 const std::vector<OfflinePageItem> GetAllPages() const;
186 189
187 // Gets pages that should be removed to clean up storage. Requires that the 190 // Gets pages that should be removed to clean up storage. Requires that the
188 // model is loaded. 191 // model is loaded.
189 const std::vector<OfflinePageItem> GetPagesToCleanUp() const; 192 const std::vector<OfflinePageItem> GetPagesToCleanUp() const;
190 193
191 // Returns an offline page associated with a specified |bookmark_id|. nullptr 194 // Returns an offline page associated with a specified |offline_id|. nullptr
192 // is returned if not found. 195 // is returned if not found.
193 const OfflinePageItem* GetPageByBookmarkId(int64_t bookmark_id) const; 196 const OfflinePageItem* GetPageByOfflineId(int64_t offline_id) const;
194 197
195 // Returns an offline page that is stored as |offline_url|. A nullptr is 198 // Returns an offline page that is stored as |offline_url|. A nullptr is
196 // returned if not found. 199 // returned if not found.
197 const OfflinePageItem* GetPageByOfflineURL(const GURL& offline_url) const; 200 const OfflinePageItem* GetPageByOfflineURL(const GURL& offline_url) const;
198 201
199 // Returns an offline page saved for |online_url|. A nullptr is returned if 202 // Returns an offline page saved for |online_url|. A nullptr is returned if
200 // not found. 203 // not found.
201 const OfflinePageItem* GetPageByOnlineURL(const GURL& online_url) const; 204 const OfflinePageItem* GetPageByOnlineURL(const GURL& online_url) const;
202 205
203 // Checks that all of the offline pages have corresponding offline copies. 206 // Checks that all of the offline pages have corresponding offline copies.
(...skipping 28 matching lines...) Expand all
232 235
233 // Callback for ensuring archive directory is created. 236 // Callback for ensuring archive directory is created.
234 void OnEnsureArchivesDirCreatedDone(); 237 void OnEnsureArchivesDirCreatedDone();
235 238
236 // Callback for loading pages from the offline page metadata store. 239 // Callback for loading pages from the offline page metadata store.
237 void OnLoadDone(OfflinePageMetadataStore::LoadStatus load_status, 240 void OnLoadDone(OfflinePageMetadataStore::LoadStatus load_status,
238 const std::vector<OfflinePageItem>& offline_pages); 241 const std::vector<OfflinePageItem>& offline_pages);
239 242
240 // Steps for saving a page offline. 243 // Steps for saving a page offline.
241 void OnCreateArchiveDone(const GURL& requested_url, 244 void OnCreateArchiveDone(const GURL& requested_url,
242 int64_t bookmark_id, 245 int64_t offline_id,
246 const ClientId& client_id,
243 const base::Time& start_time, 247 const base::Time& start_time,
244 const SavePageCallback& callback, 248 const SavePageCallback& callback,
245 OfflinePageArchiver* archiver, 249 OfflinePageArchiver* archiver,
246 OfflinePageArchiver::ArchiverResult result, 250 OfflinePageArchiver::ArchiverResult result,
247 const GURL& url, 251 const GURL& url,
248 const base::FilePath& file_path, 252 const base::FilePath& file_path,
249 int64_t file_size); 253 int64_t file_size);
250 void OnAddOfflinePageDone(OfflinePageArchiver* archiver, 254 void OnAddOfflinePageDone(OfflinePageArchiver* archiver,
251 const SavePageCallback& callback, 255 const SavePageCallback& callback,
252 const OfflinePageItem& offline_page, 256 const OfflinePageItem& offline_page,
253 bool success); 257 bool success);
254 void InformSavePageDone(const SavePageCallback& callback, 258 void InformSavePageDone(const SavePageCallback& callback,
255 SavePageResult result); 259 SavePageResult result);
256 void DeletePendingArchiver(OfflinePageArchiver* archiver); 260 void DeletePendingArchiver(OfflinePageArchiver* archiver);
257 261
258 // Steps for deleting files and data for an offline page. 262 // Steps for deleting files and data for an offline page.
259 void OnDeleteArchiveFilesDone(const std::vector<int64_t>& bookmark_ids, 263 void OnDeleteArchiveFilesDone(const std::vector<int64_t>& offline_ids,
260 const DeletePageCallback& callback, 264 const DeletePageCallback& callback,
261 const bool* success); 265 const bool* success);
262 void OnRemoveOfflinePagesDone(const std::vector<int64_t>& bookmark_ids, 266 void OnRemoveOfflinePagesDone(const std::vector<int64_t>& offline_ids,
263 const DeletePageCallback& callback, 267 const DeletePageCallback& callback,
264 bool success); 268 bool success);
265 void InformDeletePageDone(const DeletePageCallback& callback, 269 void InformDeletePageDone(const DeletePageCallback& callback,
266 DeletePageResult result); 270 DeletePageResult result);
267 271
268 void OnMarkPageAccesseDone(const OfflinePageItem& offline_page_item, 272 void OnMarkPageAccesseDone(const OfflinePageItem& offline_page_item,
269 bool success); 273 bool success);
270 274
271 // Steps for marking an offline page for deletion that can be undone. 275 // Steps for marking an offline page for deletion that can be undone.
272 void OnMarkPageForDeletionDone(const OfflinePageItem& offline_page_item, 276 void OnMarkPageForDeletionDone(const OfflinePageItem& offline_page_item,
273 const DeletePageCallback& callback, 277 const DeletePageCallback& callback,
274 bool success); 278 bool success);
275 void FinalizePageDeletion(); 279 void FinalizePageDeletion();
276 280
277 // Steps for undoing an offline page deletion. 281 // Steps for undoing an offline page deletion.
278 void UndoPageDeletion(int64_t bookmark_id); 282 void UndoPageDeletion(int64_t offline_id);
279 void OnUndoOfflinePageDone(const OfflinePageItem& offline_page, bool success); 283 void OnUndoOfflinePageDone(const OfflinePageItem& offline_page, bool success);
280 284
281 // Callbacks for checking if offline pages are missing archive files. 285 // Callbacks for checking if offline pages are missing archive files.
282 void OnFindPagesMissingArchiveFile( 286 void OnFindPagesMissingArchiveFile(
283 const std::vector<int64_t>* pages_missing_archive_file); 287 const std::vector<int64_t>* pages_missing_archive_file);
284 void OnRemoveOfflinePagesMissingArchiveFileDone( 288 void OnRemoveOfflinePagesMissingArchiveFileDone(
285 const std::vector<int64_t>& bookmark_ids, 289 const std::vector<int64_t>& offline_ids,
286 OfflinePageModel::DeletePageResult result); 290 OfflinePageModel::DeletePageResult result);
287 291
288 // Steps for clearing all. 292 // Steps for clearing all.
289 void OnRemoveAllFilesDoneForClearAll(const base::Closure& callback, 293 void OnRemoveAllFilesDoneForClearAll(const base::Closure& callback,
290 DeletePageResult result); 294 DeletePageResult result);
291 void OnResetStoreDoneForClearAll(const base::Closure& callback, bool success); 295 void OnResetStoreDoneForClearAll(const base::Closure& callback, bool success);
292 void OnReloadStoreDoneForClearAll( 296 void OnReloadStoreDoneForClearAll(
293 const base::Closure& callback, 297 const base::Closure& callback,
294 OfflinePageMetadataStore::LoadStatus load_status, 298 OfflinePageMetadataStore::LoadStatus load_status,
295 const std::vector<OfflinePageItem>& offline_pages); 299 const std::vector<OfflinePageItem>& offline_pages);
(...skipping 26 matching lines...) Expand all
322 scoped_observer_; 326 scoped_observer_;
323 327
324 base::WeakPtrFactory<OfflinePageModel> weak_ptr_factory_; 328 base::WeakPtrFactory<OfflinePageModel> weak_ptr_factory_;
325 329
326 DISALLOW_COPY_AND_ASSIGN(OfflinePageModel); 330 DISALLOW_COPY_AND_ASSIGN(OfflinePageModel);
327 }; 331 };
328 332
329 } // namespace offline_pages 333 } // namespace offline_pages
330 334
331 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_H_ 335 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698