| 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> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <set> | 12 #include <set> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/callback.h" | 15 #include "base/callback.h" |
| 16 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
| 17 #include "base/gtest_prod_util.h" | 17 #include "base/gtest_prod_util.h" |
| 18 #include "base/macros.h" | 18 #include "base/macros.h" |
| 19 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
| 20 #include "base/memory/scoped_vector.h" | 20 #include "base/memory/scoped_vector.h" |
| 21 #include "base/memory/weak_ptr.h" | 21 #include "base/memory/weak_ptr.h" |
| 22 #include "base/observer_list.h" | 22 #include "base/observer_list.h" |
| 23 #include "base/supports_user_data.h" | 23 #include "base/supports_user_data.h" |
| 24 #include "components/keyed_service/core/keyed_service.h" | 24 #include "components/keyed_service/core/keyed_service.h" |
| 25 #include "components/offline_pages/offline_page_archiver.h" | 25 #include "components/offline_pages/offline_page_archiver.h" |
| 26 #include "components/offline_pages/offline_page_client_policy.h" |
| 26 #include "components/offline_pages/offline_page_metadata_store.h" | 27 #include "components/offline_pages/offline_page_metadata_store.h" |
| 27 | 28 |
| 28 class GURL; | 29 class GURL; |
| 29 namespace base { | 30 namespace base { |
| 30 class SequencedTaskRunner; | 31 class SequencedTaskRunner; |
| 31 class Time; | 32 class Time; |
| 32 class TimeDelta; | 33 class TimeDelta; |
| 33 } | 34 } |
| 34 | 35 |
| 35 namespace offline_pages { | 36 namespace offline_pages { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 | 126 |
| 126 typedef std::vector<OfflinePageItem> GetAllPagesResult; | 127 typedef std::vector<OfflinePageItem> GetAllPagesResult; |
| 127 typedef std::set<GURL> CheckPagesExistOfflineResult; | 128 typedef std::set<GURL> CheckPagesExistOfflineResult; |
| 128 | 129 |
| 129 typedef base::Callback<void(SavePageResult, int64_t)> SavePageCallback; | 130 typedef base::Callback<void(SavePageResult, int64_t)> SavePageCallback; |
| 130 typedef base::Callback<void(DeletePageResult)> DeletePageCallback; | 131 typedef base::Callback<void(DeletePageResult)> DeletePageCallback; |
| 131 typedef base::Callback<void(const GetAllPagesResult&)> GetAllPagesCallback; | 132 typedef base::Callback<void(const GetAllPagesResult&)> GetAllPagesCallback; |
| 132 typedef base::Callback<void(const CheckPagesExistOfflineResult&)> | 133 typedef base::Callback<void(const CheckPagesExistOfflineResult&)> |
| 133 CheckPagesExistOfflineCallback; | 134 CheckPagesExistOfflineCallback; |
| 134 typedef base::Callback<void(bool)> HasPagesCallback; | 135 typedef base::Callback<void(bool)> HasPagesCallback; |
| 136 typedef std::map<LifetimePolicy::LifetimeType, |
| 137 const base::FilePath&> ArchiveDirs; |
| 135 | 138 |
| 136 // Generates a new offline id | 139 // Generates a new offline id |
| 137 static int64_t GenerateOfflineId(); | 140 static int64_t GenerateOfflineId(); |
| 138 | 141 |
| 139 // Returns true if an offline copy can be saved for the given URL. | 142 // Returns true if an offline copy can be saved for the given URL. |
| 140 static bool CanSavePage(const GURL& url); | 143 static bool CanSavePage(const GURL& url); |
| 141 | 144 |
| 142 static base::TimeDelta GetFinalDeletionDelayForTesting(); | 145 static base::TimeDelta GetFinalDeletionDelayForTesting(); |
| 143 | 146 |
| 144 // All blocking calls/disk access will happen on the provided |task_runner|. | 147 // All blocking calls/disk access will happen on the provided |task_runner|. |
| 145 OfflinePageModel(std::unique_ptr<OfflinePageMetadataStore> store, | 148 OfflinePageModel(std::unique_ptr<OfflinePageMetadataStore> store, |
| 146 const base::FilePath& archives_dir, | 149 const ArchiveDirs& archive_dirs, |
| 147 const scoped_refptr<base::SequencedTaskRunner>& task_runner); | 150 const scoped_refptr<base::SequencedTaskRunner>& task_runner); |
| 148 ~OfflinePageModel() override; | 151 ~OfflinePageModel() override; |
| 149 | 152 |
| 150 void AddObserver(Observer* observer); | 153 void AddObserver(Observer* observer); |
| 151 void RemoveObserver(Observer* observer); | 154 void RemoveObserver(Observer* observer); |
| 152 | 155 |
| 153 // Attempts to save a page addressed by |url| offline. Requires that the model | 156 // Attempts to save a page addressed by |url| offline. Requires that the model |
| 154 // is loaded. Generates a new offline id and returns it. | 157 // is loaded. Generates a new offline id and returns it. |
| 155 void SavePage(const GURL& url, | 158 void SavePage(const GURL& url, |
| 156 const ClientId& client_id, | 159 const ClientId& client_id, |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 // Actually does the work of deleting, requires the model is loaded. | 315 // Actually does the work of deleting, requires the model is loaded. |
| 313 void DoDeletePagesByOfflineId(const std::vector<int64_t>& offline_ids, | 316 void DoDeletePagesByOfflineId(const std::vector<int64_t>& offline_ids, |
| 314 const DeletePageCallback& callback); | 317 const DeletePageCallback& callback); |
| 315 | 318 |
| 316 // Similar to DoDeletePagesByOfflineId, does actual work of deleting, and | 319 // Similar to DoDeletePagesByOfflineId, does actual work of deleting, and |
| 317 // requires that the model is loaded. | 320 // requires that the model is loaded. |
| 318 void DoDeletePagesByURLPredicate( | 321 void DoDeletePagesByURLPredicate( |
| 319 const base::Callback<bool(const GURL&)>& predicate, | 322 const base::Callback<bool(const GURL&)>& predicate, |
| 320 const DeletePageCallback& callback); | 323 const DeletePageCallback& callback); |
| 321 | 324 |
| 325 // Get the archive directory for the client id. |
| 326 const base::FilePath& GetArchivePath(const ClientId& client_id); |
| 327 |
| 322 void RunWhenLoaded(const base::Closure& job); | 328 void RunWhenLoaded(const base::Closure& job); |
| 323 | 329 |
| 324 // Persistent store for offline page metadata. | 330 // Persistent store for offline page metadata. |
| 325 std::unique_ptr<OfflinePageMetadataStore> store_; | 331 std::unique_ptr<OfflinePageMetadataStore> store_; |
| 326 | 332 |
| 327 // Location where all of the archive files will be stored. | 333 // Location where all of the archive files will be stored based on namespace. |
| 328 base::FilePath archives_dir_; | 334 ArchiveDirs archive_dirs_; |
| 329 | 335 |
| 330 // The observers. | 336 // The observers. |
| 331 base::ObserverList<Observer> observers_; | 337 base::ObserverList<Observer> observers_; |
| 332 | 338 |
| 333 bool is_loaded_; | 339 bool is_loaded_; |
| 334 | 340 |
| 335 // In memory copy of the offline page metadata, keyed by bookmark IDs. | 341 // In memory copy of the offline page metadata, keyed by bookmark IDs. |
| 336 std::map<int64_t, OfflinePageItem> offline_pages_; | 342 std::map<int64_t, OfflinePageItem> offline_pages_; |
| 337 | 343 |
| 338 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 344 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| 339 | 345 |
| 340 // Pending archivers owned by this model. | 346 // Pending archivers owned by this model. |
| 341 PendingArchivers pending_archivers_; | 347 PendingArchivers pending_archivers_; |
| 342 | 348 |
| 343 // Delayed tasks that should be invoked after the loading is done. | 349 // Delayed tasks that should be invoked after the loading is done. |
| 344 std::vector<base::Closure> delayed_tasks_; | 350 std::vector<base::Closure> delayed_tasks_; |
| 345 | 351 |
| 346 base::WeakPtrFactory<OfflinePageModel> weak_ptr_factory_; | 352 base::WeakPtrFactory<OfflinePageModel> weak_ptr_factory_; |
| 347 | 353 |
| 348 DISALLOW_COPY_AND_ASSIGN(OfflinePageModel); | 354 DISALLOW_COPY_AND_ASSIGN(OfflinePageModel); |
| 349 }; | 355 }; |
| 350 | 356 |
| 351 } // namespace offline_pages | 357 } // namespace offline_pages |
| 352 | 358 |
| 353 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_H_ | 359 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_H_ |
| OLD | NEW |