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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 90 SUCCESS, | 90 SUCCESS, |
| 91 CANCELLED, | 91 CANCELLED, |
| 92 STORE_FAILURE, | 92 STORE_FAILURE, |
| 93 }; | 93 }; |
| 94 | 94 |
| 95 // Observer of the OfflinePageModel. | 95 // Observer of the OfflinePageModel. |
| 96 class Observer { | 96 class Observer { |
| 97 public: | 97 public: |
| 98 // Invoked when the model has finished loading. | 98 // Invoked when the model has finished loading. |
| 99 virtual void OfflinePageModelLoaded(OfflinePageModel* model) = 0; | 99 virtual void OfflinePageModelLoaded(OfflinePageModel* model) = 0; |
| 100 virtual void OfflinePageDeleted(int64 bookmark_id) = 0; | |
|
jianli
2015/10/13 00:17:54
nit: please add comment
fgorski
2015/10/13 17:39:58
Done.
| |
| 100 | 101 |
| 101 protected: | 102 protected: |
| 102 virtual ~Observer() {} | 103 virtual ~Observer() {} |
| 103 }; | 104 }; |
| 104 | 105 |
| 105 typedef base::Callback<void(SavePageResult)> SavePageCallback; | 106 typedef base::Callback<void(SavePageResult)> SavePageCallback; |
| 106 typedef base::Callback<void(DeletePageResult)> DeletePageCallback; | 107 typedef base::Callback<void(DeletePageResult)> DeletePageCallback; |
| 107 | 108 |
| 108 // All blocking calls/disk access will happen on the provided |task_runner|. | 109 // All blocking calls/disk access will happen on the provided |task_runner|. |
| 109 OfflinePageModel( | 110 OfflinePageModel( |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 149 const std::vector<OfflinePageItem> GetAllPages() const; | 150 const std::vector<OfflinePageItem> GetAllPages() const; |
| 150 | 151 |
| 151 // Gets pages that should be removed to clean up storage. Requires that the | 152 // Gets pages that should be removed to clean up storage. Requires that the |
| 152 // model is loaded. | 153 // model is loaded. |
| 153 const std::vector<OfflinePageItem> GetPagesToCleanUp() const; | 154 const std::vector<OfflinePageItem> GetPagesToCleanUp() const; |
| 154 | 155 |
| 155 // Returns an offline page associated with a specified |bookmark_id|. nullptr | 156 // Returns an offline page associated with a specified |bookmark_id|. nullptr |
| 156 // is returned if not found. | 157 // is returned if not found. |
| 157 const OfflinePageItem* GetPageByBookmarkId(int64 bookmark_id) const; | 158 const OfflinePageItem* GetPageByBookmarkId(int64 bookmark_id) const; |
| 158 | 159 |
| 159 // Returns an offline page that is stored as |offline_url|. nullptr is | 160 // Returns an offline page that is stored as |offline_url|. A nullptr is |
| 160 // returned if not found. | 161 // returned if not found. |
| 161 const OfflinePageItem* GetPageByOfflineURL(const GURL& offline_url) const; | 162 const OfflinePageItem* GetPageByOfflineURL(const GURL& offline_url) const; |
| 162 | 163 |
| 164 // Checks that all of the offline pages have corresponding offline copies. | |
| 165 void CheckMetadataConsistency(); | |
|
jianli
2015/10/13 00:17:54
Since we're only checking if the file is still the
fgorski
2015/10/13 17:39:58
I am ok with making that change in the model now,
| |
| 166 | |
| 163 // Methods for testing only: | 167 // Methods for testing only: |
| 164 OfflinePageMetadataStore* GetStoreForTesting(); | 168 OfflinePageMetadataStore* GetStoreForTesting(); |
| 165 | 169 |
| 166 bool is_loaded() const { return is_loaded_; } | 170 bool is_loaded() const { return is_loaded_; } |
| 167 | 171 |
| 168 private: | 172 private: |
| 169 typedef ScopedVector<OfflinePageArchiver> PendingArchivers; | 173 typedef ScopedVector<OfflinePageArchiver> PendingArchivers; |
| 170 | 174 |
| 171 // BaseBookmarkModelObserver: | 175 // BaseBookmarkModelObserver: |
| 172 void BookmarkModelChanged() override; | 176 void BookmarkModelChanged() override; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 204 const bool* success); | 208 const bool* success); |
| 205 void OnRemoveOfflinePagesDone(const std::vector<int64>& bookmark_ids, | 209 void OnRemoveOfflinePagesDone(const std::vector<int64>& bookmark_ids, |
| 206 const DeletePageCallback& callback, | 210 const DeletePageCallback& callback, |
| 207 bool success); | 211 bool success); |
| 208 void InformDeletePageDone(const DeletePageCallback& callback, | 212 void InformDeletePageDone(const DeletePageCallback& callback, |
| 209 DeletePageResult result); | 213 DeletePageResult result); |
| 210 | 214 |
| 211 void OnUpdateOfflinePageDone(const OfflinePageItem& offline_page_item, | 215 void OnUpdateOfflinePageDone(const OfflinePageItem& offline_page_item, |
| 212 bool success); | 216 bool success); |
| 213 | 217 |
| 218 // Callback for check if offline pages missing offline files. | |
| 219 void OnListPagesMissingOfflineCopy( | |
|
jianli
2015/10/13 00:17:54
It would be consistent with the naming "archive fi
fgorski
2015/10/13 17:39:58
Done.
| |
| 220 const std::vector<int64>* pages_missing_offline_copy); | |
| 221 | |
| 214 // Persistent store for offline page metadata. | 222 // Persistent store for offline page metadata. |
| 215 scoped_ptr<OfflinePageMetadataStore> store_; | 223 scoped_ptr<OfflinePageMetadataStore> store_; |
| 216 | 224 |
| 217 // The observers. | 225 // The observers. |
| 218 base::ObserverList<Observer> observers_; | 226 base::ObserverList<Observer> observers_; |
| 219 | 227 |
| 220 bool is_loaded_; | 228 bool is_loaded_; |
| 221 | 229 |
| 222 // In memory copy of the offline page metadata, keyed by bookmark IDs. | 230 // In memory copy of the offline page metadata, keyed by bookmark IDs. |
| 223 std::map<int64, OfflinePageItem> offline_pages_; | 231 std::map<int64, OfflinePageItem> offline_pages_; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 234 scoped_observer_; | 242 scoped_observer_; |
| 235 | 243 |
| 236 base::WeakPtrFactory<OfflinePageModel> weak_ptr_factory_; | 244 base::WeakPtrFactory<OfflinePageModel> weak_ptr_factory_; |
| 237 | 245 |
| 238 DISALLOW_COPY_AND_ASSIGN(OfflinePageModel); | 246 DISALLOW_COPY_AND_ASSIGN(OfflinePageModel); |
| 239 }; | 247 }; |
| 240 | 248 |
| 241 } // namespace offline_pages | 249 } // namespace offline_pages |
| 242 | 250 |
| 243 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_H_ | 251 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_H_ |
| OLD | NEW |