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

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

Issue 1480723002: [Offline pages] Detecting offline pages missing bookmarks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
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 <map> 8 #include <map>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 const OfflinePageItem* GetPageByBookmarkId(int64 bookmark_id) const; 188 const OfflinePageItem* GetPageByBookmarkId(int64 bookmark_id) const;
189 189
190 // Returns an offline page that is stored as |offline_url|. A nullptr is 190 // Returns an offline page that is stored as |offline_url|. A nullptr is
191 // returned if not found. 191 // returned if not found.
192 const OfflinePageItem* GetPageByOfflineURL(const GURL& offline_url) const; 192 const OfflinePageItem* GetPageByOfflineURL(const GURL& offline_url) const;
193 193
194 // Returns an offline page saved for |online_url|. A nullptr is returned if 194 // Returns an offline page saved for |online_url|. A nullptr is returned if
195 // not found. 195 // not found.
196 const OfflinePageItem* GetPageByOnlineURL(const GURL& online_url) const; 196 const OfflinePageItem* GetPageByOnlineURL(const GURL& online_url) const;
197 197
198 // Checks that all of the offline pages have corresponding offline copies. 198 // Checks for and fixes the following problems with offline pages metadata:
199 // If a page is discovered to be missing an offline copy, its offline page 199 // * removes pages marked for deletion when |finalize_deletion| is set to
200 // metadata will be removed and |OfflinePageDeleted| will be sent to model 200 // true,
201 // observers. 201 // * removes pages that don't have a corresponding bookmark mode in the
202 void CheckForExternalFileDeletion(); 202 // bookmarks model,
203 // * removes pages that don't have the offline archive.
204 // Metadata checks run only when the bookmark model is loaded. If a metadata
205 // check is already in progress, the method returns.
206 void CheckMetadataConsistency(bool finalize_deletion);
203 207
204 // Methods for testing only: 208 // Methods for testing only:
205 OfflinePageMetadataStore* GetStoreForTesting(); 209 OfflinePageMetadataStore* GetStoreForTesting();
206 210
207 bool is_loaded() const { return is_loaded_; } 211 bool is_loaded() const { return is_loaded_; }
208 212
209 private: 213 private:
210 FRIEND_TEST_ALL_PREFIXES(OfflinePageModelTest, MarkPageForDeletion); 214 FRIEND_TEST_ALL_PREFIXES(OfflinePageModelTest, MarkPageForDeletion);
211 FRIEND_TEST_ALL_PREFIXES(OfflinePageModelTest, BookmarkNodeChangesUrl); 215 FRIEND_TEST_ALL_PREFIXES(OfflinePageModelTest, BookmarkNodeChangesUrl);
212 216
213 typedef ScopedVector<OfflinePageArchiver> PendingArchivers; 217 typedef ScopedVector<OfflinePageArchiver> PendingArchivers;
214 218
215 // BaseBookmarkModelObserver: 219 // BaseBookmarkModelObserver:
220 void BookmarkModelLoaded(bookmarks::BookmarkModel* model,
221 bool ids_reassigned) override;
222 void BookmarkModelBeingDeleted(bookmarks::BookmarkModel* model) override;
216 void BookmarkModelChanged() override; 223 void BookmarkModelChanged() override;
217 void BookmarkNodeAdded(bookmarks::BookmarkModel* model, 224 void BookmarkNodeAdded(bookmarks::BookmarkModel* model,
218 const bookmarks::BookmarkNode* parent, 225 const bookmarks::BookmarkNode* parent,
219 int index) override; 226 int index) override;
220 void BookmarkNodeRemoved(bookmarks::BookmarkModel* model, 227 void BookmarkNodeRemoved(bookmarks::BookmarkModel* model,
221 const bookmarks::BookmarkNode* parent, 228 const bookmarks::BookmarkNode* parent,
222 int old_index, 229 int old_index,
223 const bookmarks::BookmarkNode* node, 230 const bookmarks::BookmarkNode* node,
224 const std::set<GURL>& removed_urls) override; 231 const std::set<GURL>& removed_urls) override;
225 void BookmarkNodeChanged(bookmarks::BookmarkModel* model, 232 void BookmarkNodeChanged(bookmarks::BookmarkModel* model,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 // Steps for marking an offline page for deletion that can be undone. 274 // Steps for marking an offline page for deletion that can be undone.
268 void OnMarkPageForDeletionDone(const OfflinePageItem& offline_page_item, 275 void OnMarkPageForDeletionDone(const OfflinePageItem& offline_page_item,
269 const DeletePageCallback& callback, 276 const DeletePageCallback& callback,
270 bool success); 277 bool success);
271 void FinalizePageDeletion(); 278 void FinalizePageDeletion();
272 279
273 // Steps for undoing an offline page deletion. 280 // Steps for undoing an offline page deletion.
274 void UndoPageDeletion(int64 bookmark_id); 281 void UndoPageDeletion(int64 bookmark_id);
275 void OnUndoOfflinePageDone(const OfflinePageItem& offline_page, bool success); 282 void OnUndoOfflinePageDone(const OfflinePageItem& offline_page, bool success);
276 283
277 // Callbacks for checking if offline pages are missing archive files. 284 // Callbacks and steps for checking offline page metadata consistency.
285 //
286 // Checks that all of the offline pages have corresponding offline copies.
287 // If a page is discovered to be missing an offline copy, its offline page
288 // metadata will be removed and |OfflinePageDeleted| will be sent to model
289 // observers.
290 void CheckForExternalFileDeletion(DeletePageResult);
278 void OnFindPagesMissingArchiveFile( 291 void OnFindPagesMissingArchiveFile(
279 const std::vector<int64>* pages_missing_archive_file); 292 const std::vector<int64>* pages_missing_archive_file);
280 void OnRemoveOfflinePagesMissingArchiveFileDone( 293 void OnRemoveOfflinePagesMissingArchiveFileDone(
281 const std::vector<int64>& bookmark_ids, 294 const std::vector<int64>& bookmark_ids,
282 OfflinePageModel::DeletePageResult result); 295 OfflinePageModel::DeletePageResult result);
283 296
284 // Steps for clearing all. 297 // Steps for clearing all.
285 void OnRemoveAllFilesDoneForClearAll(const base::Closure& callback, 298 void OnRemoveAllFilesDoneForClearAll(const base::Closure& callback,
286 DeletePageResult result); 299 DeletePageResult result);
287 void OnResetStoreDoneForClearAll(const base::Closure& callback, bool success); 300 void OnResetStoreDoneForClearAll(const base::Closure& callback, bool success);
288 void OnReloadStoreDoneForClearAll( 301 void OnReloadStoreDoneForClearAll(
289 const base::Closure& callback, 302 const base::Closure& callback,
290 OfflinePageMetadataStore::LoadStatus load_status, 303 OfflinePageMetadataStore::LoadStatus load_status,
291 const std::vector<OfflinePageItem>& offline_pages); 304 const std::vector<OfflinePageItem>& offline_pages);
292 305
293 void CacheLoadedData(const std::vector<OfflinePageItem>& offline_pages); 306 void CacheLoadedData(const std::vector<OfflinePageItem>& offline_pages);
294 307
295 // Persistent store for offline page metadata. 308 // Persistent store for offline page metadata.
296 scoped_ptr<OfflinePageMetadataStore> store_; 309 scoped_ptr<OfflinePageMetadataStore> store_;
297 310
298 // Location where all of the archive files will be stored. 311 // Location where all of the archive files will be stored.
299 base::FilePath archives_dir_; 312 base::FilePath archives_dir_;
300 313
301 // The observers. 314 // The observers.
302 base::ObserverList<Observer> observers_; 315 base::ObserverList<Observer> observers_;
303 316
304 bool is_loaded_; 317 bool is_loaded_;
305 318
319 // Whether a metadata check is going on right now.
320 bool metadata_check_in_progress_;
321
306 // In memory copy of the offline page metadata, keyed by bookmark IDs. 322 // In memory copy of the offline page metadata, keyed by bookmark IDs.
307 std::map<int64, OfflinePageItem> offline_pages_; 323 std::map<int64, OfflinePageItem> offline_pages_;
308 324
309 scoped_refptr<base::SequencedTaskRunner> task_runner_; 325 scoped_refptr<base::SequencedTaskRunner> task_runner_;
310 326
311 // Pending archivers owned by this model. 327 // Pending archivers owned by this model.
312 PendingArchivers pending_archivers_; 328 PendingArchivers pending_archivers_;
313 329
314 // Delayed tasks that should be invoked after the loading is done. 330 // Delayed tasks that should be invoked after the loading is done.
315 std::vector<base::Closure> delayed_tasks_; 331 std::vector<base::Closure> delayed_tasks_;
316 332
333 bookmarks::BookmarkModel* bookmarks_model_;
334
317 ScopedObserver<bookmarks::BookmarkModel, bookmarks::BookmarkModelObserver> 335 ScopedObserver<bookmarks::BookmarkModel, bookmarks::BookmarkModelObserver>
318 scoped_observer_; 336 scoped_observer_;
319 337
320 base::WeakPtrFactory<OfflinePageModel> weak_ptr_factory_; 338 base::WeakPtrFactory<OfflinePageModel> weak_ptr_factory_;
321 339
322 DISALLOW_COPY_AND_ASSIGN(OfflinePageModel); 340 DISALLOW_COPY_AND_ASSIGN(OfflinePageModel);
323 }; 341 };
324 342
325 } // namespace offline_pages 343 } // namespace offline_pages
326 344
327 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_H_ 345 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_H_
OLDNEW
« no previous file with comments | « chrome/browser/android/offline_pages/offline_page_bridge.cc ('k') | components/offline_pages/offline_page_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698