Index: components/offline_pages/offline_page_model.h |
diff --git a/components/offline_pages/offline_page_model.h b/components/offline_pages/offline_page_model.h |
index 631d522ecc3ddf22193ef195f9f6c6266a17f7d5..aba944e3951343745411e38c728c63f619732e0f 100644 |
--- a/components/offline_pages/offline_page_model.h |
+++ b/components/offline_pages/offline_page_model.h |
@@ -195,11 +195,15 @@ class OfflinePageModel : public KeyedService, |
// not found. |
const OfflinePageItem* GetPageByOnlineURL(const GURL& online_url) const; |
- // Checks that all of the offline pages have corresponding offline copies. |
- // If a page is discovered to be missing an offline copy, its offline page |
- // metadata will be removed and |OfflinePageDeleted| will be sent to model |
- // observers. |
- void CheckForExternalFileDeletion(); |
+ // Checks for and fixes the following problems with offline pages metadata: |
+ // * removes pages marked for deletion when |finalize_deletion| is set to |
+ // true, |
+ // * removes pages that don't have a corresponding bookmark mode in the |
+ // bookmarks model, |
+ // * removes pages that don't have the offline archive. |
+ // Metadata checks run only when the bookmark model is loaded. If a metadata |
+ // check is already in progress, the method returns. |
+ void CheckMetadataConsistency(bool finalize_deletion); |
// Methods for testing only: |
OfflinePageMetadataStore* GetStoreForTesting(); |
@@ -213,6 +217,9 @@ class OfflinePageModel : public KeyedService, |
typedef ScopedVector<OfflinePageArchiver> PendingArchivers; |
// BaseBookmarkModelObserver: |
+ void BookmarkModelLoaded(bookmarks::BookmarkModel* model, |
+ bool ids_reassigned) override; |
+ void BookmarkModelBeingDeleted(bookmarks::BookmarkModel* model) override; |
void BookmarkModelChanged() override; |
void BookmarkNodeAdded(bookmarks::BookmarkModel* model, |
const bookmarks::BookmarkNode* parent, |
@@ -274,7 +281,13 @@ class OfflinePageModel : public KeyedService, |
void UndoPageDeletion(int64 bookmark_id); |
void OnUndoOfflinePageDone(const OfflinePageItem& offline_page, bool success); |
- // Callbacks for checking if offline pages are missing archive files. |
+ // Callbacks and steps for checking offline page metadata consistency. |
+ // |
+ // Checks that all of the offline pages have corresponding offline copies. |
+ // If a page is discovered to be missing an offline copy, its offline page |
+ // metadata will be removed and |OfflinePageDeleted| will be sent to model |
+ // observers. |
+ void CheckForExternalFileDeletion(DeletePageResult); |
void OnFindPagesMissingArchiveFile( |
const std::vector<int64>* pages_missing_archive_file); |
void OnRemoveOfflinePagesMissingArchiveFileDone( |
@@ -303,6 +316,9 @@ class OfflinePageModel : public KeyedService, |
bool is_loaded_; |
+ // Whether a metadata check is going on right now. |
+ bool metadata_check_in_progress_; |
+ |
// In memory copy of the offline page metadata, keyed by bookmark IDs. |
std::map<int64, OfflinePageItem> offline_pages_; |
@@ -314,6 +330,8 @@ class OfflinePageModel : public KeyedService, |
// Delayed tasks that should be invoked after the loading is done. |
std::vector<base::Closure> delayed_tasks_; |
+ bookmarks::BookmarkModel* bookmarks_model_; |
+ |
ScopedObserver<bookmarks::BookmarkModel, bookmarks::BookmarkModelObserver> |
scoped_observer_; |