Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 SUCCESS, | 91 SUCCESS, |
| 92 CANCELLED, | 92 CANCELLED, |
| 93 STORE_FAILURE, | 93 STORE_FAILURE, |
| 94 }; | 94 }; |
| 95 | 95 |
| 96 // Observer of the OfflinePageModel. | 96 // Observer of the OfflinePageModel. |
| 97 class Observer { | 97 class Observer { |
| 98 public: | 98 public: |
| 99 // Invoked when the model has finished loading. | 99 // Invoked when the model has finished loading. |
| 100 virtual void OfflinePageModelLoaded(OfflinePageModel* model) = 0; | 100 virtual void OfflinePageModelLoaded(OfflinePageModel* model) = 0; |
| 101 // Invoked when an offline copy related to |bookmark_id| was deleted. | |
|
jianli
2015/10/20 21:56:49
nit: add blank line
Also please move this method
fgorski
2015/10/21 20:01:33
Done.
| |
| 102 virtual void OfflinePageDeleted(int64 bookmark_id) = 0; | |
| 101 | 103 |
| 102 // Invoked when the model is being updated, due to adding, removing or | 104 // Invoked when the model is being updated, due to adding, removing or |
| 103 // updating an offline page. | 105 // updating an offline page. |
| 104 virtual void OfflinePageModelChanged(OfflinePageModel* model) = 0; | 106 virtual void OfflinePageModelChanged(OfflinePageModel* model) = 0; |
| 105 | 107 |
| 106 protected: | 108 protected: |
| 107 virtual ~Observer() {} | 109 virtual ~Observer() {} |
| 108 }; | 110 }; |
| 109 | 111 |
| 110 typedef base::Callback<void(SavePageResult)> SavePageCallback; | 112 typedef base::Callback<void(SavePageResult)> SavePageCallback; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 const std::vector<OfflinePageItem> GetAllPages() const; | 164 const std::vector<OfflinePageItem> GetAllPages() const; |
| 163 | 165 |
| 164 // Gets pages that should be removed to clean up storage. Requires that the | 166 // Gets pages that should be removed to clean up storage. Requires that the |
| 165 // model is loaded. | 167 // model is loaded. |
| 166 const std::vector<OfflinePageItem> GetPagesToCleanUp() const; | 168 const std::vector<OfflinePageItem> GetPagesToCleanUp() const; |
| 167 | 169 |
| 168 // Returns an offline page associated with a specified |bookmark_id|. nullptr | 170 // Returns an offline page associated with a specified |bookmark_id|. nullptr |
| 169 // is returned if not found. | 171 // is returned if not found. |
| 170 const OfflinePageItem* GetPageByBookmarkId(int64 bookmark_id) const; | 172 const OfflinePageItem* GetPageByBookmarkId(int64 bookmark_id) const; |
| 171 | 173 |
| 172 // Returns an offline page that is stored as |offline_url|. nullptr is | 174 // Returns an offline page that is stored as |offline_url|. A nullptr is |
| 173 // returned if not found. | 175 // returned if not found. |
| 174 const OfflinePageItem* GetPageByOfflineURL(const GURL& offline_url) const; | 176 const OfflinePageItem* GetPageByOfflineURL(const GURL& offline_url) const; |
| 175 | 177 |
| 178 // Checks that all of the offline pages have corresponding offline copies. | |
| 179 // If a page is discovered to be missing an offline copy, its offline page | |
| 180 // metadata will be removed and |OfflinePageDeleted| will be sent to model | |
| 181 // observers. | |
| 182 void CheckForExternalFileDeletion(); | |
| 183 | |
| 176 // Methods for testing only: | 184 // Methods for testing only: |
| 177 OfflinePageMetadataStore* GetStoreForTesting(); | 185 OfflinePageMetadataStore* GetStoreForTesting(); |
| 178 | 186 |
| 179 bool is_loaded() const { return is_loaded_; } | 187 bool is_loaded() const { return is_loaded_; } |
| 180 | 188 |
| 181 private: | 189 private: |
| 182 FRIEND_TEST_ALL_PREFIXES(OfflinePageModelTest, MarkPageForDeletion); | 190 FRIEND_TEST_ALL_PREFIXES(OfflinePageModelTest, MarkPageForDeletion); |
| 183 | 191 |
| 184 typedef ScopedVector<OfflinePageArchiver> PendingArchivers; | 192 typedef ScopedVector<OfflinePageArchiver> PendingArchivers; |
| 185 | 193 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 222 const bool* success); | 230 const bool* success); |
| 223 void OnRemoveOfflinePagesDone(const std::vector<int64>& bookmark_ids, | 231 void OnRemoveOfflinePagesDone(const std::vector<int64>& bookmark_ids, |
| 224 const DeletePageCallback& callback, | 232 const DeletePageCallback& callback, |
| 225 bool success); | 233 bool success); |
| 226 void InformDeletePageDone(const DeletePageCallback& callback, | 234 void InformDeletePageDone(const DeletePageCallback& callback, |
| 227 DeletePageResult result); | 235 DeletePageResult result); |
| 228 | 236 |
| 229 void OnMarkPageAccesseDone(const OfflinePageItem& offline_page_item, | 237 void OnMarkPageAccesseDone(const OfflinePageItem& offline_page_item, |
| 230 bool success); | 238 bool success); |
| 231 | 239 |
| 232 // Steps for marking an offline page for deletion that can be undo-ed. | 240 // Steps for marking an offline page for deletion that can be undone. |
| 233 void OnMarkPageForDeletionDone(const OfflinePageItem& offline_page_item, | 241 void OnMarkPageForDeletionDone(const OfflinePageItem& offline_page_item, |
| 234 const DeletePageCallback& callback, | 242 const DeletePageCallback& callback, |
| 235 bool success); | 243 bool success); |
| 236 void FinalizePageDeletion(); | 244 void FinalizePageDeletion(); |
| 237 | 245 |
| 238 // Steps for undoing a offline page deletion. | 246 // Steps for undoing an offline page deletion. |
| 239 void UndoPageDeletion(int64 bookmark_id); | 247 void UndoPageDeletion(int64 bookmark_id); |
| 240 void OnUndoOfflinePageDone(const OfflinePageItem& offline_page, bool success); | 248 void OnUndoOfflinePageDone(const OfflinePageItem& offline_page, bool success); |
| 241 | 249 |
| 250 // Callbacks for checking if offline pages are missing archive files. | |
| 251 void OnListPagesMissingArchiveFileDone( | |
| 252 const std::vector<int64>* pages_missing_archive_file); | |
| 253 void OnRemovalOfPagesMissingArchiveFileDone( | |
| 254 const std::vector<int64>& bookmark_ids, | |
| 255 OfflinePageModel::DeletePageResult result); | |
| 256 | |
| 242 // Persistent store for offline page metadata. | 257 // Persistent store for offline page metadata. |
| 243 scoped_ptr<OfflinePageMetadataStore> store_; | 258 scoped_ptr<OfflinePageMetadataStore> store_; |
| 244 | 259 |
| 245 // The observers. | 260 // The observers. |
| 246 base::ObserverList<Observer> observers_; | 261 base::ObserverList<Observer> observers_; |
| 247 | 262 |
| 248 bool is_loaded_; | 263 bool is_loaded_; |
| 249 | 264 |
| 250 // In memory copy of the offline page metadata, keyed by bookmark IDs. | 265 // In memory copy of the offline page metadata, keyed by bookmark IDs. |
| 251 std::map<int64, OfflinePageItem> offline_pages_; | 266 std::map<int64, OfflinePageItem> offline_pages_; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 262 scoped_observer_; | 277 scoped_observer_; |
| 263 | 278 |
| 264 base::WeakPtrFactory<OfflinePageModel> weak_ptr_factory_; | 279 base::WeakPtrFactory<OfflinePageModel> weak_ptr_factory_; |
| 265 | 280 |
| 266 DISALLOW_COPY_AND_ASSIGN(OfflinePageModel); | 281 DISALLOW_COPY_AND_ASSIGN(OfflinePageModel); |
| 267 }; | 282 }; |
| 268 | 283 |
| 269 } // namespace offline_pages | 284 } // namespace offline_pages |
| 270 | 285 |
| 271 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_H_ | 286 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_H_ |
| OLD | NEW |