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

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

Powered by Google App Engine
This is Rietveld 408576698