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 <stdint.h> |
| 9 |
8 #include <map> | 10 #include <map> |
9 #include <vector> | 11 #include <vector> |
10 | 12 |
11 #include "base/callback.h" | 13 #include "base/callback.h" |
12 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
13 #include "base/gtest_prod_util.h" | 15 #include "base/gtest_prod_util.h" |
14 #include "base/macros.h" | 16 #include "base/macros.h" |
15 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
16 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
17 #include "base/memory/scoped_vector.h" | 19 #include "base/memory/scoped_vector.h" |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 // Invoked when the model has finished loading. | 108 // Invoked when the model has finished loading. |
107 virtual void OfflinePageModelLoaded(OfflinePageModel* model) = 0; | 109 virtual void OfflinePageModelLoaded(OfflinePageModel* model) = 0; |
108 | 110 |
109 // Invoked when the model is being updated, due to adding, removing or | 111 // Invoked when the model is being updated, due to adding, removing or |
110 // updating an offline page. | 112 // updating an offline page. |
111 virtual void OfflinePageModelChanged(OfflinePageModel* model) = 0; | 113 virtual void OfflinePageModelChanged(OfflinePageModel* model) = 0; |
112 | 114 |
113 // Invoked when an offline copy related to |bookmark_id| was deleted. | 115 // Invoked when an offline copy related to |bookmark_id| was deleted. |
114 // In can be invoked as a result of |CheckForExternalFileDeletion|, if a | 116 // In can be invoked as a result of |CheckForExternalFileDeletion|, if a |
115 // deleted page is detected. | 117 // deleted page is detected. |
116 virtual void OfflinePageDeleted(int64 bookmark_id) = 0; | 118 virtual void OfflinePageDeleted(int64_t bookmark_id) = 0; |
117 | 119 |
118 protected: | 120 protected: |
119 virtual ~Observer() {} | 121 virtual ~Observer() {} |
120 }; | 122 }; |
121 | 123 |
122 typedef base::Callback<void(SavePageResult)> SavePageCallback; | 124 typedef base::Callback<void(SavePageResult)> SavePageCallback; |
123 typedef base::Callback<void(DeletePageResult)> DeletePageCallback; | 125 typedef base::Callback<void(DeletePageResult)> DeletePageCallback; |
124 | 126 |
125 // Returns true if an offline copy can be saved for the given URL. | 127 // Returns true if an offline copy can be saved for the given URL. |
126 static bool CanSavePage(const GURL& url); | 128 static bool CanSavePage(const GURL& url); |
(...skipping 14 matching lines...) Expand all Loading... |
141 | 143 |
142 // KeyedService implementation. | 144 // KeyedService implementation. |
143 void Shutdown() override; | 145 void Shutdown() override; |
144 | 146 |
145 void AddObserver(Observer* observer); | 147 void AddObserver(Observer* observer); |
146 void RemoveObserver(Observer* observer); | 148 void RemoveObserver(Observer* observer); |
147 | 149 |
148 // Attempts to save a page addressed by |url| offline. Requires that the model | 150 // Attempts to save a page addressed by |url| offline. Requires that the model |
149 // is loaded. | 151 // is loaded. |
150 void SavePage(const GURL& url, | 152 void SavePage(const GURL& url, |
151 int64 bookmark_id, | 153 int64_t bookmark_id, |
152 scoped_ptr<OfflinePageArchiver> archiver, | 154 scoped_ptr<OfflinePageArchiver> archiver, |
153 const SavePageCallback& callback); | 155 const SavePageCallback& callback); |
154 | 156 |
155 // Marks that the offline page related to the passed |bookmark_id| has been | 157 // Marks that the offline page related to the passed |bookmark_id| has been |
156 // accessed. Its access info, including last access time and access count, | 158 // accessed. Its access info, including last access time and access count, |
157 // will be updated. Requires that the model is loaded. | 159 // will be updated. Requires that the model is loaded. |
158 void MarkPageAccessed(int64 bookmark_id); | 160 void MarkPageAccessed(int64_t bookmark_id); |
159 | 161 |
160 // Marks that the offline page related to the passed |bookmark_id| was going | 162 // Marks that the offline page related to the passed |bookmark_id| was going |
161 // to be deleted. The deletion will occur in a short while. The undo can be | 163 // to be deleted. The deletion will occur in a short while. The undo can be |
162 // done before this. Requires that the model is loaded. | 164 // done before this. Requires that the model is loaded. |
163 void MarkPageForDeletion(int64 bookmark_id, | 165 void MarkPageForDeletion(int64_t bookmark_id, |
164 const DeletePageCallback& callback); | 166 const DeletePageCallback& callback); |
165 | 167 |
166 // Deletes an offline page related to the passed |bookmark_id|. Requires that | 168 // Deletes an offline page related to the passed |bookmark_id|. Requires that |
167 // the model is loaded. | 169 // the model is loaded. |
168 void DeletePageByBookmarkId(int64 bookmark_id, | 170 void DeletePageByBookmarkId(int64_t bookmark_id, |
169 const DeletePageCallback& callback); | 171 const DeletePageCallback& callback); |
170 | 172 |
171 // Deletes offline pages related to the passed |bookmark_ids|. Requires that | 173 // Deletes offline pages related to the passed |bookmark_ids|. Requires that |
172 // the model is loaded. | 174 // the model is loaded. |
173 void DeletePagesByBookmarkId(const std::vector<int64>& bookmark_ids, | 175 void DeletePagesByBookmarkId(const std::vector<int64_t>& bookmark_ids, |
174 const DeletePageCallback& callback); | 176 const DeletePageCallback& callback); |
175 | 177 |
176 // Wipes out all the data by deleting all saved files and clearing the store. | 178 // Wipes out all the data by deleting all saved files and clearing the store. |
177 void ClearAll(const base::Closure& callback); | 179 void ClearAll(const base::Closure& callback); |
178 | 180 |
179 // Returns true if there're offline pages. | 181 // Returns true if there're offline pages. |
180 bool HasOfflinePages() const; | 182 bool HasOfflinePages() const; |
181 | 183 |
182 // Gets all available offline pages. Requires that the model is loaded. | 184 // Gets all available offline pages. Requires that the model is loaded. |
183 const std::vector<OfflinePageItem> GetAllPages() const; | 185 const std::vector<OfflinePageItem> GetAllPages() const; |
184 | 186 |
185 // Gets pages that should be removed to clean up storage. Requires that the | 187 // Gets pages that should be removed to clean up storage. Requires that the |
186 // model is loaded. | 188 // model is loaded. |
187 const std::vector<OfflinePageItem> GetPagesToCleanUp() const; | 189 const std::vector<OfflinePageItem> GetPagesToCleanUp() const; |
188 | 190 |
189 // Returns an offline page associated with a specified |bookmark_id|. nullptr | 191 // Returns an offline page associated with a specified |bookmark_id|. nullptr |
190 // is returned if not found. | 192 // is returned if not found. |
191 const OfflinePageItem* GetPageByBookmarkId(int64 bookmark_id) const; | 193 const OfflinePageItem* GetPageByBookmarkId(int64_t bookmark_id) const; |
192 | 194 |
193 // Returns an offline page that is stored as |offline_url|. A nullptr is | 195 // Returns an offline page that is stored as |offline_url|. A nullptr is |
194 // returned if not found. | 196 // returned if not found. |
195 const OfflinePageItem* GetPageByOfflineURL(const GURL& offline_url) const; | 197 const OfflinePageItem* GetPageByOfflineURL(const GURL& offline_url) const; |
196 | 198 |
197 // Returns an offline page saved for |online_url|. A nullptr is returned if | 199 // Returns an offline page saved for |online_url|. A nullptr is returned if |
198 // not found. | 200 // not found. |
199 const OfflinePageItem* GetPageByOnlineURL(const GURL& online_url) const; | 201 const OfflinePageItem* GetPageByOnlineURL(const GURL& online_url) const; |
200 | 202 |
201 // Checks that all of the offline pages have corresponding offline copies. | 203 // Checks that all of the offline pages have corresponding offline copies. |
(...skipping 28 matching lines...) Expand all Loading... |
230 | 232 |
231 // Callback for ensuring archive directory is created. | 233 // Callback for ensuring archive directory is created. |
232 void OnEnsureArchivesDirCreatedDone(); | 234 void OnEnsureArchivesDirCreatedDone(); |
233 | 235 |
234 // Callback for loading pages from the offline page metadata store. | 236 // Callback for loading pages from the offline page metadata store. |
235 void OnLoadDone(OfflinePageMetadataStore::LoadStatus load_status, | 237 void OnLoadDone(OfflinePageMetadataStore::LoadStatus load_status, |
236 const std::vector<OfflinePageItem>& offline_pages); | 238 const std::vector<OfflinePageItem>& offline_pages); |
237 | 239 |
238 // Steps for saving a page offline. | 240 // Steps for saving a page offline. |
239 void OnCreateArchiveDone(const GURL& requested_url, | 241 void OnCreateArchiveDone(const GURL& requested_url, |
240 int64 bookmark_id, | 242 int64_t bookmark_id, |
241 const base::Time& start_time, | 243 const base::Time& start_time, |
242 const SavePageCallback& callback, | 244 const SavePageCallback& callback, |
243 OfflinePageArchiver* archiver, | 245 OfflinePageArchiver* archiver, |
244 OfflinePageArchiver::ArchiverResult result, | 246 OfflinePageArchiver::ArchiverResult result, |
245 const GURL& url, | 247 const GURL& url, |
246 const base::FilePath& file_path, | 248 const base::FilePath& file_path, |
247 int64 file_size); | 249 int64_t file_size); |
248 void OnAddOfflinePageDone(OfflinePageArchiver* archiver, | 250 void OnAddOfflinePageDone(OfflinePageArchiver* archiver, |
249 const SavePageCallback& callback, | 251 const SavePageCallback& callback, |
250 const OfflinePageItem& offline_page, | 252 const OfflinePageItem& offline_page, |
251 bool success); | 253 bool success); |
252 void InformSavePageDone(const SavePageCallback& callback, | 254 void InformSavePageDone(const SavePageCallback& callback, |
253 SavePageResult result); | 255 SavePageResult result); |
254 void DeletePendingArchiver(OfflinePageArchiver* archiver); | 256 void DeletePendingArchiver(OfflinePageArchiver* archiver); |
255 | 257 |
256 // Steps for deleting files and data for an offline page. | 258 // Steps for deleting files and data for an offline page. |
257 void OnDeleteArchiveFilesDone( | 259 void OnDeleteArchiveFilesDone(const std::vector<int64_t>& bookmark_ids, |
258 const std::vector<int64>& bookmark_ids, | 260 const DeletePageCallback& callback, |
259 const DeletePageCallback& callback, | 261 const bool* success); |
260 const bool* success); | 262 void OnRemoveOfflinePagesDone(const std::vector<int64_t>& bookmark_ids, |
261 void OnRemoveOfflinePagesDone(const std::vector<int64>& bookmark_ids, | |
262 const DeletePageCallback& callback, | 263 const DeletePageCallback& callback, |
263 bool success); | 264 bool success); |
264 void InformDeletePageDone(const DeletePageCallback& callback, | 265 void InformDeletePageDone(const DeletePageCallback& callback, |
265 DeletePageResult result); | 266 DeletePageResult result); |
266 | 267 |
267 void OnMarkPageAccesseDone(const OfflinePageItem& offline_page_item, | 268 void OnMarkPageAccesseDone(const OfflinePageItem& offline_page_item, |
268 bool success); | 269 bool success); |
269 | 270 |
270 // Steps for marking an offline page for deletion that can be undone. | 271 // Steps for marking an offline page for deletion that can be undone. |
271 void OnMarkPageForDeletionDone(const OfflinePageItem& offline_page_item, | 272 void OnMarkPageForDeletionDone(const OfflinePageItem& offline_page_item, |
272 const DeletePageCallback& callback, | 273 const DeletePageCallback& callback, |
273 bool success); | 274 bool success); |
274 void FinalizePageDeletion(); | 275 void FinalizePageDeletion(); |
275 | 276 |
276 // Steps for undoing an offline page deletion. | 277 // Steps for undoing an offline page deletion. |
277 void UndoPageDeletion(int64 bookmark_id); | 278 void UndoPageDeletion(int64_t bookmark_id); |
278 void OnUndoOfflinePageDone(const OfflinePageItem& offline_page, bool success); | 279 void OnUndoOfflinePageDone(const OfflinePageItem& offline_page, bool success); |
279 | 280 |
280 // Callbacks for checking if offline pages are missing archive files. | 281 // Callbacks for checking if offline pages are missing archive files. |
281 void OnFindPagesMissingArchiveFile( | 282 void OnFindPagesMissingArchiveFile( |
282 const std::vector<int64>* pages_missing_archive_file); | 283 const std::vector<int64_t>* pages_missing_archive_file); |
283 void OnRemoveOfflinePagesMissingArchiveFileDone( | 284 void OnRemoveOfflinePagesMissingArchiveFileDone( |
284 const std::vector<int64>& bookmark_ids, | 285 const std::vector<int64_t>& bookmark_ids, |
285 OfflinePageModel::DeletePageResult result); | 286 OfflinePageModel::DeletePageResult result); |
286 | 287 |
287 // Steps for clearing all. | 288 // Steps for clearing all. |
288 void OnRemoveAllFilesDoneForClearAll(const base::Closure& callback, | 289 void OnRemoveAllFilesDoneForClearAll(const base::Closure& callback, |
289 DeletePageResult result); | 290 DeletePageResult result); |
290 void OnResetStoreDoneForClearAll(const base::Closure& callback, bool success); | 291 void OnResetStoreDoneForClearAll(const base::Closure& callback, bool success); |
291 void OnReloadStoreDoneForClearAll( | 292 void OnReloadStoreDoneForClearAll( |
292 const base::Closure& callback, | 293 const base::Closure& callback, |
293 OfflinePageMetadataStore::LoadStatus load_status, | 294 OfflinePageMetadataStore::LoadStatus load_status, |
294 const std::vector<OfflinePageItem>& offline_pages); | 295 const std::vector<OfflinePageItem>& offline_pages); |
295 | 296 |
296 void CacheLoadedData(const std::vector<OfflinePageItem>& offline_pages); | 297 void CacheLoadedData(const std::vector<OfflinePageItem>& offline_pages); |
297 | 298 |
298 // Persistent store for offline page metadata. | 299 // Persistent store for offline page metadata. |
299 scoped_ptr<OfflinePageMetadataStore> store_; | 300 scoped_ptr<OfflinePageMetadataStore> store_; |
300 | 301 |
301 // Location where all of the archive files will be stored. | 302 // Location where all of the archive files will be stored. |
302 base::FilePath archives_dir_; | 303 base::FilePath archives_dir_; |
303 | 304 |
304 // The observers. | 305 // The observers. |
305 base::ObserverList<Observer> observers_; | 306 base::ObserverList<Observer> observers_; |
306 | 307 |
307 bool is_loaded_; | 308 bool is_loaded_; |
308 | 309 |
309 // In memory copy of the offline page metadata, keyed by bookmark IDs. | 310 // In memory copy of the offline page metadata, keyed by bookmark IDs. |
310 std::map<int64, OfflinePageItem> offline_pages_; | 311 std::map<int64_t, OfflinePageItem> offline_pages_; |
311 | 312 |
312 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 313 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
313 | 314 |
314 // Pending archivers owned by this model. | 315 // Pending archivers owned by this model. |
315 PendingArchivers pending_archivers_; | 316 PendingArchivers pending_archivers_; |
316 | 317 |
317 // Delayed tasks that should be invoked after the loading is done. | 318 // Delayed tasks that should be invoked after the loading is done. |
318 std::vector<base::Closure> delayed_tasks_; | 319 std::vector<base::Closure> delayed_tasks_; |
319 | 320 |
320 ScopedObserver<bookmarks::BookmarkModel, bookmarks::BookmarkModelObserver> | 321 ScopedObserver<bookmarks::BookmarkModel, bookmarks::BookmarkModelObserver> |
321 scoped_observer_; | 322 scoped_observer_; |
322 | 323 |
323 base::WeakPtrFactory<OfflinePageModel> weak_ptr_factory_; | 324 base::WeakPtrFactory<OfflinePageModel> weak_ptr_factory_; |
324 | 325 |
325 DISALLOW_COPY_AND_ASSIGN(OfflinePageModel); | 326 DISALLOW_COPY_AND_ASSIGN(OfflinePageModel); |
326 }; | 327 }; |
327 | 328 |
328 } // namespace offline_pages | 329 } // namespace offline_pages |
329 | 330 |
330 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_H_ | 331 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_H_ |
OLD | NEW |