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

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: address changes 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* const 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. Generates a new offline id and returns it.
152 void SavePage(const GURL& url, 160 void SavePage(const GURL& url,
153 int64_t bookmark_id, 161 const ClientId& client_id,
154 scoped_ptr<OfflinePageArchiver> archiver, 162 scoped_ptr<OfflinePageArchiver> archiver,
155 const SavePageCallback& callback); 163 const SavePageCallback& callback);
156 164
157 // Marks that the offline page related to the passed |bookmark_id| has been 165 // 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, 166 // accessed. Its access info, including last access time and access count,
159 // will be updated. Requires that the model is loaded. 167 // will be updated. Requires that the model is loaded.
160 void MarkPageAccessed(int64_t bookmark_id); 168 void MarkPageAccessed(int64_t offline_id);
161 169
162 // Marks that the offline page related to the passed |bookmark_id| was going 170 // 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 171 // 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. 172 // done before this. Requires that the model is loaded.
165 void MarkPageForDeletion(int64_t bookmark_id, 173 void MarkPageForDeletion(int64_t offline_id,
166 const DeletePageCallback& callback); 174 const DeletePageCallback& callback);
167 175
168 // Deletes an offline page related to the passed |bookmark_id|. Requires that 176 // Deletes an offline page related to the passed |offline_id|. Requires that
169 // the model is loaded. 177 // the model is loaded.
170 void DeletePageByBookmarkId(int64_t bookmark_id, 178 void DeletePageByOfflineId(int64_t offline_id,
179 const DeletePageCallback& callback);
180
181 // Deletes offline pages related to the passed |offline_ids|. Requires that
182 // the model is loaded.
183 void DeletePagesByOfflineId(const std::vector<int64_t>& offline_ids,
171 const DeletePageCallback& callback); 184 const DeletePageCallback& callback);
172 185
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. 186 // Wipes out all the data by deleting all saved files and clearing the store.
179 void ClearAll(const base::Closure& callback); 187 void ClearAll(const base::Closure& callback);
180 188
181 // Returns true if there're offline pages. 189 // Returns true if there're offline pages.
182 bool HasOfflinePages() const; 190 bool HasOfflinePages() const;
183 191
184 // Gets all available offline pages. Requires that the model is loaded. 192 // Gets all available offline pages. Requires that the model is loaded.
185 const std::vector<OfflinePageItem> GetAllPages() const; 193 const std::vector<OfflinePageItem> GetAllPages() const;
186 194
187 // Gets pages that should be removed to clean up storage. Requires that the 195 // Gets pages that should be removed to clean up storage. Requires that the
188 // model is loaded. 196 // model is loaded.
189 const std::vector<OfflinePageItem> GetPagesToCleanUp() const; 197 const std::vector<OfflinePageItem> GetPagesToCleanUp() const;
190 198
191 // Returns an offline page associated with a specified |bookmark_id|. nullptr 199 // Gets all offline ids where the offline page has the matching client id
200 const std::vector<int64_t> GetOfflineIdsForClientId(
201 const ClientId& cid) const;
202
203 // Returns an offline page associated with a specified |offline_id|. nullptr
192 // is returned if not found. 204 // is returned if not found.
193 const OfflinePageItem* GetPageByBookmarkId(int64_t bookmark_id) const; 205 const OfflinePageItem* GetPageByOfflineId(int64_t offline_id) const;
194 206
195 // Returns an offline page that is stored as |offline_url|. A nullptr is 207 // Returns an offline page that is stored as |offline_url|. A nullptr is
196 // returned if not found. 208 // returned if not found.
197 const OfflinePageItem* GetPageByOfflineURL(const GURL& offline_url) const; 209 const OfflinePageItem* GetPageByOfflineURL(const GURL& offline_url) const;
198 210
199 // Returns an offline page saved for |online_url|. A nullptr is returned if 211 // Returns an offline page saved for |online_url|. A nullptr is returned if
200 // not found. 212 // not found.
201 const OfflinePageItem* GetPageByOnlineURL(const GURL& online_url) const; 213 const OfflinePageItem* GetPageByOnlineURL(const GURL& online_url) const;
202 214
203 // Checks that all of the offline pages have corresponding offline copies. 215 // Checks that all of the offline pages have corresponding offline copies.
(...skipping 28 matching lines...) Expand all
232 244
233 // Callback for ensuring archive directory is created. 245 // Callback for ensuring archive directory is created.
234 void OnEnsureArchivesDirCreatedDone(); 246 void OnEnsureArchivesDirCreatedDone();
235 247
236 // Callback for loading pages from the offline page metadata store. 248 // Callback for loading pages from the offline page metadata store.
237 void OnLoadDone(OfflinePageMetadataStore::LoadStatus load_status, 249 void OnLoadDone(OfflinePageMetadataStore::LoadStatus load_status,
238 const std::vector<OfflinePageItem>& offline_pages); 250 const std::vector<OfflinePageItem>& offline_pages);
239 251
240 // Steps for saving a page offline. 252 // Steps for saving a page offline.
241 void OnCreateArchiveDone(const GURL& requested_url, 253 void OnCreateArchiveDone(const GURL& requested_url,
242 int64_t bookmark_id, 254 int64_t offline_id,
255 const ClientId& client_id,
243 const base::Time& start_time, 256 const base::Time& start_time,
244 const SavePageCallback& callback, 257 const SavePageCallback& callback,
245 OfflinePageArchiver* archiver, 258 OfflinePageArchiver* archiver,
246 OfflinePageArchiver::ArchiverResult result, 259 OfflinePageArchiver::ArchiverResult result,
247 const GURL& url, 260 const GURL& url,
248 const base::FilePath& file_path, 261 const base::FilePath& file_path,
249 int64_t file_size); 262 int64_t file_size);
250 void OnAddOfflinePageDone(OfflinePageArchiver* archiver, 263 void OnAddOfflinePageDone(OfflinePageArchiver* archiver,
251 const SavePageCallback& callback, 264 const SavePageCallback& callback,
252 const OfflinePageItem& offline_page, 265 const OfflinePageItem& offline_page,
253 bool success); 266 bool success);
254 void InformSavePageDone(const SavePageCallback& callback, 267 void InformSavePageDone(const SavePageCallback& callback,
255 SavePageResult result); 268 SavePageResult result,
269 int64_t offline_id);
256 void DeletePendingArchiver(OfflinePageArchiver* archiver); 270 void DeletePendingArchiver(OfflinePageArchiver* archiver);
257 271
258 // Steps for deleting files and data for an offline page. 272 // Steps for deleting files and data for an offline page.
259 void OnDeleteArchiveFilesDone(const std::vector<int64_t>& bookmark_ids, 273 void OnDeleteArchiveFilesDone(const std::vector<int64_t>& offline_ids,
260 const DeletePageCallback& callback, 274 const DeletePageCallback& callback,
261 const bool* success); 275 const bool* success);
262 void OnRemoveOfflinePagesDone(const std::vector<int64_t>& bookmark_ids, 276 void OnRemoveOfflinePagesDone(const std::vector<int64_t>& offline_ids,
263 const DeletePageCallback& callback, 277 const DeletePageCallback& callback,
264 bool success); 278 bool success);
265 void InformDeletePageDone(const DeletePageCallback& callback, 279 void InformDeletePageDone(const DeletePageCallback& callback,
266 DeletePageResult result); 280 DeletePageResult result);
267 281
268 void OnMarkPageAccesseDone(const OfflinePageItem& offline_page_item, 282 void OnMarkPageAccesseDone(const OfflinePageItem& offline_page_item,
269 bool success); 283 bool success);
270 284
271 // Steps for marking an offline page for deletion that can be undone. 285 // Steps for marking an offline page for deletion that can be undone.
272 void OnMarkPageForDeletionDone(const OfflinePageItem& offline_page_item, 286 void OnMarkPageForDeletionDone(const OfflinePageItem& offline_page_item,
273 const DeletePageCallback& callback, 287 const DeletePageCallback& callback,
274 bool success); 288 bool success);
275 void FinalizePageDeletion(); 289 void FinalizePageDeletion();
276 290
277 // Steps for undoing an offline page deletion. 291 // Steps for undoing an offline page deletion.
278 void UndoPageDeletion(int64_t bookmark_id); 292 void UndoPageDeletion(int64_t offline_id);
279 void OnUndoOfflinePageDone(const OfflinePageItem& offline_page, bool success); 293 void OnUndoOfflinePageDone(const OfflinePageItem& offline_page, bool success);
280 294
281 // Callbacks for checking if offline pages are missing archive files. 295 // Callbacks for checking if offline pages are missing archive files.
282 void OnFindPagesMissingArchiveFile( 296 void OnFindPagesMissingArchiveFile(
283 const std::vector<int64_t>* pages_missing_archive_file); 297 const std::vector<int64_t>* pages_missing_archive_file);
284 void OnRemoveOfflinePagesMissingArchiveFileDone( 298 void OnRemoveOfflinePagesMissingArchiveFileDone(
285 const std::vector<int64_t>& bookmark_ids, 299 const std::vector<int64_t>& offline_ids,
286 OfflinePageModel::DeletePageResult result); 300 OfflinePageModel::DeletePageResult result);
287 301
288 // Steps for clearing all. 302 // Steps for clearing all.
289 void OnRemoveAllFilesDoneForClearAll(const base::Closure& callback, 303 void OnRemoveAllFilesDoneForClearAll(const base::Closure& callback,
290 DeletePageResult result); 304 DeletePageResult result);
291 void OnResetStoreDoneForClearAll(const base::Closure& callback, bool success); 305 void OnResetStoreDoneForClearAll(const base::Closure& callback, bool success);
292 void OnReloadStoreDoneForClearAll( 306 void OnReloadStoreDoneForClearAll(
293 const base::Closure& callback, 307 const base::Closure& callback,
294 OfflinePageMetadataStore::LoadStatus load_status, 308 OfflinePageMetadataStore::LoadStatus load_status,
295 const std::vector<OfflinePageItem>& offline_pages); 309 const std::vector<OfflinePageItem>& offline_pages);
(...skipping 26 matching lines...) Expand all
322 scoped_observer_; 336 scoped_observer_;
323 337
324 base::WeakPtrFactory<OfflinePageModel> weak_ptr_factory_; 338 base::WeakPtrFactory<OfflinePageModel> weak_ptr_factory_;
325 339
326 DISALLOW_COPY_AND_ASSIGN(OfflinePageModel); 340 DISALLOW_COPY_AND_ASSIGN(OfflinePageModel);
327 }; 341 };
328 342
329 } // namespace offline_pages 343 } // namespace offline_pages
330 344
331 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_H_ 345 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698