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

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: move id generation to C++, add DB migration Created 4 years, 9 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 static const char* BOOKMARK_NAMESPACE = "bookmark";
41 static const int64_t INVALID_OFFLINE_ID = 0;
42
43 struct ClientId;
44
40 struct OfflinePageItem; 45 struct OfflinePageItem;
41 class OfflinePageMetadataStore; 46 class OfflinePageMetadataStore;
42 47
43 // Service for saving pages offline, storing the offline copy and metadata, and 48 // Service for saving pages offline, storing the offline copy and metadata, and
44 // retrieving them upon request. 49 // retrieving them upon request.
45 // 50 //
46 // Example usage: 51 // Example usage:
47 // class ArchiverImpl : public OfflinePageArchiver { 52 // class ArchiverImpl : public OfflinePageArchiver {
48 // // This is a class that knows how to create archiver 53 // // This is a class that knows how to create archiver
49 // void CreateArchiver(...) override; 54 // void CreateArchiver(...) override;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 // Observer of the OfflinePageModel. 110 // Observer of the OfflinePageModel.
106 class Observer { 111 class Observer {
107 public: 112 public:
108 // Invoked when the model has finished loading. 113 // Invoked when the model has finished loading.
109 virtual void OfflinePageModelLoaded(OfflinePageModel* model) = 0; 114 virtual void OfflinePageModelLoaded(OfflinePageModel* model) = 0;
110 115
111 // Invoked when the model is being updated, due to adding, removing or 116 // Invoked when the model is being updated, due to adding, removing or
112 // updating an offline page. 117 // updating an offline page.
113 virtual void OfflinePageModelChanged(OfflinePageModel* model) = 0; 118 virtual void OfflinePageModelChanged(OfflinePageModel* model) = 0;
114 119
115 // Invoked when an offline copy related to |bookmark_id| was deleted. 120 // Invoked when an offline copy related to |offline_id| was deleted.
116 // In can be invoked as a result of |CheckForExternalFileDeletion|, if a 121 // In can be invoked as a result of |CheckForExternalFileDeletion|, if a
117 // deleted page is detected. 122 // deleted page is detected.
118 virtual void OfflinePageDeleted(int64_t bookmark_id) = 0; 123 virtual void OfflinePageDeleted(int64_t offline_id) = 0;
119 124
120 protected: 125 protected:
121 virtual ~Observer() {} 126 virtual ~Observer() {}
122 }; 127 };
123 128
124 typedef base::Callback<void(SavePageResult)> SavePageCallback; 129 typedef base::Callback<void(SavePageResult, int64_t)> SavePageCallback;
125 typedef base::Callback<void(DeletePageResult)> DeletePageCallback; 130 typedef base::Callback<void(DeletePageResult)> DeletePageCallback;
126 131
132 // Generates a new offline id
133 static int64_t GenerateOfflineId();
134
127 // Returns true if an offline copy can be saved for the given URL. 135 // Returns true if an offline copy can be saved for the given URL.
128 static bool CanSavePage(const GURL& url); 136 static bool CanSavePage(const GURL& url);
129 137
130 static base::TimeDelta GetFinalDeletionDelayForTesting(); 138 static base::TimeDelta GetFinalDeletionDelayForTesting();
131 139
132 // All blocking calls/disk access will happen on the provided |task_runner|. 140 // All blocking calls/disk access will happen on the provided |task_runner|.
133 OfflinePageModel(scoped_ptr<OfflinePageMetadataStore> store, 141 OfflinePageModel(scoped_ptr<OfflinePageMetadataStore> store,
134 const base::FilePath& archives_dir, 142 const base::FilePath& archives_dir,
135 const scoped_refptr<base::SequencedTaskRunner>& task_runner); 143 const scoped_refptr<base::SequencedTaskRunner>& task_runner);
136 ~OfflinePageModel() override; 144 ~OfflinePageModel() override;
137 145
138 // Starts the OfflinePageModel and registers it as a BookmarkModelObserver. 146 // Starts the OfflinePageModel and registers it as a BookmarkModelObserver.
139 // Calling this method is optional, but offline pages will not be deleted 147 // Calling this method is optional, but offline pages will not be deleted
140 // when the bookmark is deleted, i.e. due to sync, until this method is 148 // when the bookmark is deleted, i.e. due to sync, until this method is
141 // called. 149 // called.
142 void Start(bookmarks::BookmarkModel* model); 150 void Start(bookmarks::BookmarkModel* model);
143 151
144 // KeyedService implementation. 152 // KeyedService implementation.
145 void Shutdown() override; 153 void Shutdown() override;
146 154
147 void AddObserver(Observer* observer); 155 void AddObserver(Observer* observer);
148 void RemoveObserver(Observer* observer); 156 void RemoveObserver(Observer* observer);
149 157
150 // Attempts to save a page addressed by |url| offline. Requires that the model 158 // Attempts to save a page addressed by |url| offline. Requires that the model
151 // is loaded. 159 // is loaded. If offline_id is zero a new offline id is generated and
160 // returned.
152 void SavePage(const GURL& url, 161 void SavePage(const GURL& url,
153 int64_t bookmark_id, 162 int64_t offline_id,
163 const ClientId& client_id,
154 scoped_ptr<OfflinePageArchiver> archiver, 164 scoped_ptr<OfflinePageArchiver> archiver,
155 const SavePageCallback& callback); 165 const SavePageCallback& callback);
156 166
157 // Marks that the offline page related to the passed |bookmark_id| has been 167 // 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, 168 // accessed. Its access info, including last access time and access count,
159 // will be updated. Requires that the model is loaded. 169 // will be updated. Requires that the model is loaded.
160 void MarkPageAccessed(int64_t bookmark_id); 170 void MarkPageAccessed(int64_t offline_id);
161 171
162 // Marks that the offline page related to the passed |bookmark_id| was going 172 // 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 173 // 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. 174 // done before this. Requires that the model is loaded.
165 void MarkPageForDeletion(int64_t bookmark_id, 175 void MarkPageForDeletion(int64_t offline_id,
166 const DeletePageCallback& callback); 176 const DeletePageCallback& callback);
167 177
168 // Deletes an offline page related to the passed |bookmark_id|. Requires that 178 // Deletes an offline page related to the passed |offline_id|. Requires that
169 // the model is loaded. 179 // the model is loaded.
170 void DeletePageByBookmarkId(int64_t bookmark_id, 180 void DeletePageByOfflineId(int64_t offline_id,
181 const DeletePageCallback& callback);
182
183 // Deletes offline pages related to the passed |offline_ids|. Requires that
184 // the model is loaded.
185 void DeletePagesByOfflineId(const std::vector<int64_t>& offline_ids,
171 const DeletePageCallback& callback); 186 const DeletePageCallback& callback);
172 187
173 // Deletes offline pages related to the passed |bookmark_ids|. Requires that
174 // the model is loaded.
175 void DeletePagesByBookmarkId(const std::vector<int64_t>& bookmark_ids,
176 const DeletePageCallback& callback);
177
178 // Wipes out all the data by deleting all saved files and clearing the store. 188 // Wipes out all the data by deleting all saved files and clearing the store.
179 void ClearAll(const base::Closure& callback); 189 void ClearAll(const base::Closure& callback);
180 190
181 // Returns true if there're offline pages. 191 // Returns true if there're offline pages.
182 bool HasOfflinePages() const; 192 bool HasOfflinePages() const;
183 193
184 // Gets all available offline pages. Requires that the model is loaded. 194 // Gets all available offline pages. Requires that the model is loaded.
185 const std::vector<OfflinePageItem> GetAllPages() const; 195 const std::vector<OfflinePageItem> GetAllPages() const;
186 196
187 // Gets pages that should be removed to clean up storage. Requires that the 197 // Gets pages that should be removed to clean up storage. Requires that the
188 // model is loaded. 198 // model is loaded.
189 const std::vector<OfflinePageItem> GetPagesToCleanUp() const; 199 const std::vector<OfflinePageItem> GetPagesToCleanUp() const;
190 200
191 // Returns an offline page associated with a specified |bookmark_id|. nullptr 201 // Gets all offline ids where the offline page has the matching client id
202 const std::vector<int64_t> GetOfflineIdsForClientId(
203 const ClientId& cid) const;
204
205 // Returns an offline page associated with a specified |offline_id|. nullptr
192 // is returned if not found. 206 // is returned if not found.
193 const OfflinePageItem* GetPageByBookmarkId(int64_t bookmark_id) const; 207 const OfflinePageItem* GetPageByOfflineId(int64_t offline_id) const;
194 208
195 // Returns an offline page that is stored as |offline_url|. A nullptr is 209 // Returns an offline page that is stored as |offline_url|. A nullptr is
196 // returned if not found. 210 // returned if not found.
197 const OfflinePageItem* GetPageByOfflineURL(const GURL& offline_url) const; 211 const OfflinePageItem* GetPageByOfflineURL(const GURL& offline_url) const;
198 212
199 // Returns an offline page saved for |online_url|. A nullptr is returned if 213 // Returns an offline page saved for |online_url|. A nullptr is returned if
200 // not found. 214 // not found.
201 const OfflinePageItem* GetPageByOnlineURL(const GURL& online_url) const; 215 const OfflinePageItem* GetPageByOnlineURL(const GURL& online_url) const;
202 216
203 // Checks that all of the offline pages have corresponding offline copies. 217 // Checks that all of the offline pages have corresponding offline copies.
(...skipping 28 matching lines...) Expand all
232 246
233 // Callback for ensuring archive directory is created. 247 // Callback for ensuring archive directory is created.
234 void OnEnsureArchivesDirCreatedDone(); 248 void OnEnsureArchivesDirCreatedDone();
235 249
236 // Callback for loading pages from the offline page metadata store. 250 // Callback for loading pages from the offline page metadata store.
237 void OnLoadDone(OfflinePageMetadataStore::LoadStatus load_status, 251 void OnLoadDone(OfflinePageMetadataStore::LoadStatus load_status,
238 const std::vector<OfflinePageItem>& offline_pages); 252 const std::vector<OfflinePageItem>& offline_pages);
239 253
240 // Steps for saving a page offline. 254 // Steps for saving a page offline.
241 void OnCreateArchiveDone(const GURL& requested_url, 255 void OnCreateArchiveDone(const GURL& requested_url,
242 int64_t bookmark_id, 256 int64_t offline_id,
257 const ClientId& client_id,
243 const base::Time& start_time, 258 const base::Time& start_time,
244 const SavePageCallback& callback, 259 const SavePageCallback& callback,
245 OfflinePageArchiver* archiver, 260 OfflinePageArchiver* archiver,
246 OfflinePageArchiver::ArchiverResult result, 261 OfflinePageArchiver::ArchiverResult result,
247 const GURL& url, 262 const GURL& url,
248 const base::FilePath& file_path, 263 const base::FilePath& file_path,
249 int64_t file_size); 264 int64_t file_size);
250 void OnAddOfflinePageDone(OfflinePageArchiver* archiver, 265 void OnAddOfflinePageDone(OfflinePageArchiver* archiver,
251 const SavePageCallback& callback, 266 const SavePageCallback& callback,
252 const OfflinePageItem& offline_page, 267 const OfflinePageItem& offline_page,
253 bool success); 268 bool success);
254 void InformSavePageDone(const SavePageCallback& callback, 269 void InformSavePageDone(const SavePageCallback& callback,
255 SavePageResult result); 270 SavePageResult result,
271 int64_t offline_id);
256 void DeletePendingArchiver(OfflinePageArchiver* archiver); 272 void DeletePendingArchiver(OfflinePageArchiver* archiver);
257 273
258 // Steps for deleting files and data for an offline page. 274 // Steps for deleting files and data for an offline page.
259 void OnDeleteArchiveFilesDone(const std::vector<int64_t>& bookmark_ids, 275 void OnDeleteArchiveFilesDone(const std::vector<int64_t>& offline_ids,
260 const DeletePageCallback& callback, 276 const DeletePageCallback& callback,
261 const bool* success); 277 const bool* success);
262 void OnRemoveOfflinePagesDone(const std::vector<int64_t>& bookmark_ids, 278 void OnRemoveOfflinePagesDone(const std::vector<int64_t>& offline_ids,
263 const DeletePageCallback& callback, 279 const DeletePageCallback& callback,
264 bool success); 280 bool success);
265 void InformDeletePageDone(const DeletePageCallback& callback, 281 void InformDeletePageDone(const DeletePageCallback& callback,
266 DeletePageResult result); 282 DeletePageResult result);
267 283
268 void OnMarkPageAccesseDone(const OfflinePageItem& offline_page_item, 284 void OnMarkPageAccesseDone(const OfflinePageItem& offline_page_item,
269 bool success); 285 bool success);
270 286
271 // Steps for marking an offline page for deletion that can be undone. 287 // Steps for marking an offline page for deletion that can be undone.
272 void OnMarkPageForDeletionDone(const OfflinePageItem& offline_page_item, 288 void OnMarkPageForDeletionDone(const OfflinePageItem& offline_page_item,
273 const DeletePageCallback& callback, 289 const DeletePageCallback& callback,
274 bool success); 290 bool success);
275 void FinalizePageDeletion(); 291 void FinalizePageDeletion();
276 292
277 // Steps for undoing an offline page deletion. 293 // Steps for undoing an offline page deletion.
278 void UndoPageDeletion(int64_t bookmark_id); 294 void UndoPageDeletion(int64_t offline_id);
279 void OnUndoOfflinePageDone(const OfflinePageItem& offline_page, bool success); 295 void OnUndoOfflinePageDone(const OfflinePageItem& offline_page, bool success);
280 296
281 // Callbacks for checking if offline pages are missing archive files. 297 // Callbacks for checking if offline pages are missing archive files.
282 void OnFindPagesMissingArchiveFile( 298 void OnFindPagesMissingArchiveFile(
283 const std::vector<int64_t>* pages_missing_archive_file); 299 const std::vector<int64_t>* pages_missing_archive_file);
284 void OnRemoveOfflinePagesMissingArchiveFileDone( 300 void OnRemoveOfflinePagesMissingArchiveFileDone(
285 const std::vector<int64_t>& bookmark_ids, 301 const std::vector<int64_t>& offline_ids,
286 OfflinePageModel::DeletePageResult result); 302 OfflinePageModel::DeletePageResult result);
287 303
288 // Steps for clearing all. 304 // Steps for clearing all.
289 void OnRemoveAllFilesDoneForClearAll(const base::Closure& callback, 305 void OnRemoveAllFilesDoneForClearAll(const base::Closure& callback,
290 DeletePageResult result); 306 DeletePageResult result);
291 void OnResetStoreDoneForClearAll(const base::Closure& callback, bool success); 307 void OnResetStoreDoneForClearAll(const base::Closure& callback, bool success);
292 void OnReloadStoreDoneForClearAll( 308 void OnReloadStoreDoneForClearAll(
293 const base::Closure& callback, 309 const base::Closure& callback,
294 OfflinePageMetadataStore::LoadStatus load_status, 310 OfflinePageMetadataStore::LoadStatus load_status,
295 const std::vector<OfflinePageItem>& offline_pages); 311 const std::vector<OfflinePageItem>& offline_pages);
(...skipping 26 matching lines...) Expand all
322 scoped_observer_; 338 scoped_observer_;
323 339
324 base::WeakPtrFactory<OfflinePageModel> weak_ptr_factory_; 340 base::WeakPtrFactory<OfflinePageModel> weak_ptr_factory_;
325 341
326 DISALLOW_COPY_AND_ASSIGN(OfflinePageModel); 342 DISALLOW_COPY_AND_ASSIGN(OfflinePageModel);
327 }; 343 };
328 344
329 } // namespace offline_pages 345 } // namespace offline_pages
330 346
331 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_H_ 347 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698