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 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/memory/scoped_vector.h" | 16 #include "base/memory/scoped_vector.h" |
17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
18 #include "base/observer_list.h" | 18 #include "base/observer_list.h" |
19 #include "base/scoped_observer.h" | 19 #include "base/scoped_observer.h" |
20 #include "components/bookmarks/browser/base_bookmark_model_observer.h" | 20 #include "components/bookmarks/browser/base_bookmark_model_observer.h" |
21 #include "components/keyed_service/core/keyed_service.h" | 21 #include "components/keyed_service/core/keyed_service.h" |
22 #include "components/offline_pages/offline_page_archiver.h" | 22 #include "components/offline_pages/offline_page_archiver.h" |
| 23 #include "components/offline_pages/offline_page_metadata_store.h" |
23 | 24 |
24 class GURL; | 25 class GURL; |
25 namespace base { | 26 namespace base { |
26 class SequencedTaskRunner; | 27 class SequencedTaskRunner; |
27 } | 28 } |
28 namespace bookmarks { | 29 namespace bookmarks { |
29 class BookmarkModel; | 30 class BookmarkModel; |
30 } | 31 } |
31 | 32 |
32 namespace offline_pages { | 33 namespace offline_pages { |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 // Deletes an offline page related to the passed |bookmark_id|. Requires that | 161 // Deletes an offline page related to the passed |bookmark_id|. Requires that |
161 // the model is loaded. | 162 // the model is loaded. |
162 void DeletePageByBookmarkId(int64 bookmark_id, | 163 void DeletePageByBookmarkId(int64 bookmark_id, |
163 const DeletePageCallback& callback); | 164 const DeletePageCallback& callback); |
164 | 165 |
165 // Deletes offline pages related to the passed |bookmark_ids|. Requires that | 166 // Deletes offline pages related to the passed |bookmark_ids|. Requires that |
166 // the model is loaded. | 167 // the model is loaded. |
167 void DeletePagesByBookmarkId(const std::vector<int64>& bookmark_ids, | 168 void DeletePagesByBookmarkId(const std::vector<int64>& bookmark_ids, |
168 const DeletePageCallback& callback); | 169 const DeletePageCallback& callback); |
169 | 170 |
170 void UndeletePage(int64 bookmark_id, const DeletePageCallback& callback); | 171 // Wipes out all the data by deleting all saved files and clearing the store. |
| 172 void ClearAll(const base::Closure& callback); |
171 | 173 |
172 // Gets all available offline pages. Requires that the model is loaded. | 174 // Gets all available offline pages. Requires that the model is loaded. |
173 const std::vector<OfflinePageItem> GetAllPages() const; | 175 const std::vector<OfflinePageItem> GetAllPages() const; |
174 | 176 |
175 // Gets pages that should be removed to clean up storage. Requires that the | 177 // Gets pages that should be removed to clean up storage. Requires that the |
176 // model is loaded. | 178 // model is loaded. |
177 const std::vector<OfflinePageItem> GetPagesToCleanUp() const; | 179 const std::vector<OfflinePageItem> GetPagesToCleanUp() const; |
178 | 180 |
179 // Returns an offline page associated with a specified |bookmark_id|. nullptr | 181 // Returns an offline page associated with a specified |bookmark_id|. nullptr |
180 // is returned if not found. | 182 // is returned if not found. |
(...skipping 24 matching lines...) Expand all Loading... |
205 void BookmarkNodeAdded(bookmarks::BookmarkModel* model, | 207 void BookmarkNodeAdded(bookmarks::BookmarkModel* model, |
206 const bookmarks::BookmarkNode* parent, | 208 const bookmarks::BookmarkNode* parent, |
207 int index) override; | 209 int index) override; |
208 void BookmarkNodeRemoved(bookmarks::BookmarkModel* model, | 210 void BookmarkNodeRemoved(bookmarks::BookmarkModel* model, |
209 const bookmarks::BookmarkNode* parent, | 211 const bookmarks::BookmarkNode* parent, |
210 int old_index, | 212 int old_index, |
211 const bookmarks::BookmarkNode* node, | 213 const bookmarks::BookmarkNode* node, |
212 const std::set<GURL>& removed_urls) override; | 214 const std::set<GURL>& removed_urls) override; |
213 | 215 |
214 // Callback for loading pages from the offline page metadata store. | 216 // Callback for loading pages from the offline page metadata store. |
215 void OnLoadDone(bool success, | 217 void OnLoadDone(OfflinePageMetadataStore::LoadStatus load_status, |
216 const std::vector<OfflinePageItem>& offline_pages); | 218 const std::vector<OfflinePageItem>& offline_pages); |
217 | 219 |
218 // Steps for saving a page offline. | 220 // Steps for saving a page offline. |
219 void OnCreateArchiveDone(const GURL& requested_url, | 221 void OnCreateArchiveDone(const GURL& requested_url, |
220 int64 bookmark_id, | 222 int64 bookmark_id, |
221 const SavePageCallback& callback, | 223 const SavePageCallback& callback, |
222 OfflinePageArchiver* archiver, | 224 OfflinePageArchiver* archiver, |
223 OfflinePageArchiver::ArchiverResult result, | 225 OfflinePageArchiver::ArchiverResult result, |
224 const GURL& url, | 226 const GURL& url, |
225 const base::FilePath& file_path, | 227 const base::FilePath& file_path, |
(...skipping 30 matching lines...) Expand all Loading... |
256 void UndoPageDeletion(int64 bookmark_id); | 258 void UndoPageDeletion(int64 bookmark_id); |
257 void OnUndoOfflinePageDone(const OfflinePageItem& offline_page, bool success); | 259 void OnUndoOfflinePageDone(const OfflinePageItem& offline_page, bool success); |
258 | 260 |
259 // Callbacks for checking if offline pages are missing archive files. | 261 // Callbacks for checking if offline pages are missing archive files. |
260 void OnFindPagesMissingArchiveFile( | 262 void OnFindPagesMissingArchiveFile( |
261 const std::vector<int64>* pages_missing_archive_file); | 263 const std::vector<int64>* pages_missing_archive_file); |
262 void OnRemoveOfflinePagesMissingArchiveFileDone( | 264 void OnRemoveOfflinePagesMissingArchiveFileDone( |
263 const std::vector<int64>& bookmark_ids, | 265 const std::vector<int64>& bookmark_ids, |
264 OfflinePageModel::DeletePageResult result); | 266 OfflinePageModel::DeletePageResult result); |
265 | 267 |
| 268 // Steps for clearing all. |
| 269 void OnRemoveAllFilesDoneForClearAll(const base::Closure& callback, |
| 270 DeletePageResult result); |
| 271 void OnResetStoreDoneForClearAll(const base::Closure& callback, bool success); |
| 272 void OnReloadStoreDoneForClearAll( |
| 273 const base::Closure& callback, |
| 274 OfflinePageMetadataStore::LoadStatus load_status, |
| 275 const std::vector<OfflinePageItem>& offline_pages); |
| 276 |
| 277 void CacheLoadedData(const std::vector<OfflinePageItem>& offline_pages); |
| 278 |
266 // Persistent store for offline page metadata. | 279 // Persistent store for offline page metadata. |
267 scoped_ptr<OfflinePageMetadataStore> store_; | 280 scoped_ptr<OfflinePageMetadataStore> store_; |
268 | 281 |
269 // The observers. | 282 // The observers. |
270 base::ObserverList<Observer> observers_; | 283 base::ObserverList<Observer> observers_; |
271 | 284 |
272 bool is_loaded_; | 285 bool is_loaded_; |
273 | 286 |
274 // In memory copy of the offline page metadata, keyed by bookmark IDs. | 287 // In memory copy of the offline page metadata, keyed by bookmark IDs. |
275 std::map<int64, OfflinePageItem> offline_pages_; | 288 std::map<int64, OfflinePageItem> offline_pages_; |
(...skipping 10 matching lines...) Expand all Loading... |
286 scoped_observer_; | 299 scoped_observer_; |
287 | 300 |
288 base::WeakPtrFactory<OfflinePageModel> weak_ptr_factory_; | 301 base::WeakPtrFactory<OfflinePageModel> weak_ptr_factory_; |
289 | 302 |
290 DISALLOW_COPY_AND_ASSIGN(OfflinePageModel); | 303 DISALLOW_COPY_AND_ASSIGN(OfflinePageModel); |
291 }; | 304 }; |
292 | 305 |
293 } // namespace offline_pages | 306 } // namespace offline_pages |
294 | 307 |
295 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_H_ | 308 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_H_ |
OLD | NEW |