| 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/optional.h" | 23 #include "base/optional.h" |
| 24 #include "base/supports_user_data.h" | 24 #include "base/supports_user_data.h" |
| 25 #include "components/keyed_service/core/keyed_service.h" | 25 #include "components/keyed_service/core/keyed_service.h" |
| 26 #include "components/offline_pages/offline_page_archiver.h" | 26 #include "components/offline_pages/offline_page_archiver.h" |
| 27 #include "components/offline_pages/offline_page_metadata_store.h" | 27 #include "components/offline_pages/offline_page_metadata_store.h" |
| 28 #include "components/offline_pages/offline_page_storage_manager.h" |
| 28 #include "components/offline_pages/offline_page_types.h" | 29 #include "components/offline_pages/offline_page_types.h" |
| 29 | 30 |
| 30 class GURL; | 31 class GURL; |
| 31 namespace base { | 32 namespace base { |
| 32 class SequencedTaskRunner; | 33 class SequencedTaskRunner; |
| 33 class Time; | 34 class Time; |
| 34 class TimeDelta; | 35 class TimeDelta; |
| 35 class TimeTicks; | 36 class TimeTicks; |
| 36 } | 37 } |
| 37 | 38 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 57 // ... | 58 // ... |
| 58 // } | 59 // } |
| 59 // | 60 // |
| 60 // // In code using the OfflinePagesModel to save a page: | 61 // // In code using the OfflinePagesModel to save a page: |
| 61 // std::unique_ptr<ArchiverImpl> archiver(new ArchiverImpl()); | 62 // std::unique_ptr<ArchiverImpl> archiver(new ArchiverImpl()); |
| 62 // // Callback is of type SavePageCallback. | 63 // // Callback is of type SavePageCallback. |
| 63 // model->SavePage(url, std::move(archiver), callback); | 64 // model->SavePage(url, std::move(archiver), callback); |
| 64 // | 65 // |
| 65 // TODO(fgorski): Things to describe: | 66 // TODO(fgorski): Things to describe: |
| 66 // * how to cancel requests and what to expect | 67 // * how to cancel requests and what to expect |
| 67 class OfflinePageModel : public KeyedService, public base::SupportsUserData { | 68 class OfflinePageModel : public KeyedService, |
| 69 public base::SupportsUserData, |
| 70 public OfflinePageStorageManager::Client { |
| 68 public: | 71 public: |
| 69 // Observer of the OfflinePageModel. | 72 // Observer of the OfflinePageModel. |
| 70 class Observer { | 73 class Observer { |
| 71 public: | 74 public: |
| 72 // Invoked when the model has finished loading. | 75 // Invoked when the model has finished loading. |
| 73 virtual void OfflinePageModelLoaded(OfflinePageModel* model) = 0; | 76 virtual void OfflinePageModelLoaded(OfflinePageModel* model) = 0; |
| 74 | 77 |
| 75 // Invoked when the model is being updated, due to adding, removing or | 78 // Invoked when the model is being updated, due to adding, removing or |
| 76 // updating an offline page. | 79 // updating an offline page. |
| 77 virtual void OfflinePageModelChanged(OfflinePageModel* model) = 0; | 80 virtual void OfflinePageModelChanged(OfflinePageModel* model) = 0; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 // Marks that the offline page related to the passed |offline_id| has been | 125 // Marks that the offline page related to the passed |offline_id| has been |
| 123 // accessed. Its access info, including last access time and access count, | 126 // accessed. Its access info, including last access time and access count, |
| 124 // will be updated. Requires that the model is loaded. | 127 // will be updated. Requires that the model is loaded. |
| 125 void MarkPageAccessed(int64_t offline_id); | 128 void MarkPageAccessed(int64_t offline_id); |
| 126 | 129 |
| 127 // Deletes an offline page related to the passed |offline_id|. | 130 // Deletes an offline page related to the passed |offline_id|. |
| 128 void DeletePageByOfflineId(int64_t offline_id, | 131 void DeletePageByOfflineId(int64_t offline_id, |
| 129 const DeletePageCallback& callback); | 132 const DeletePageCallback& callback); |
| 130 | 133 |
| 131 // Deletes offline pages related to the passed |offline_ids|. | 134 // Deletes offline pages related to the passed |offline_ids|. |
| 132 // Making virtual for test purposes. | 135 void DeletePagesByOfflineId(const std::vector<int64_t>& offline_ids, |
| 133 virtual void DeletePagesByOfflineId(const std::vector<int64_t>& offline_ids, | 136 const DeletePageCallback& callback) override; |
| 134 const DeletePageCallback& callback); | |
| 135 | 137 |
| 136 // Wipes out all the data by deleting all saved files and clearing the store. | 138 // Wipes out all the data by deleting all saved files and clearing the store. |
| 137 void ClearAll(const base::Closure& callback); | 139 void ClearAll(const base::Closure& callback); |
| 138 | 140 |
| 139 // Deletes offline pages matching the URL predicate. | 141 // Deletes offline pages matching the URL predicate. |
| 140 void DeletePagesByURLPredicate(const UrlPredicate& predicate, | 142 void DeletePagesByURLPredicate(const UrlPredicate& predicate, |
| 141 const DeletePageCallback& callback); | 143 const DeletePageCallback& callback); |
| 142 | 144 |
| 143 // Returns true via callback if there are offline pages in the given | 145 // Returns true via callback if there are offline pages in the given |
| 144 // |name_space|. | 146 // |name_space|. |
| 145 void HasPages(const std::string& name_space, | 147 void HasPages(const std::string& name_space, |
| 146 const HasPagesCallback& callback); | 148 const HasPagesCallback& callback); |
| 147 | 149 |
| 148 // Returns via callback all GURLs in |urls| that are equal to the online URL | 150 // Returns via callback all GURLs in |urls| that are equal to the online URL |
| 149 // of any offline page. | 151 // of any offline page. |
| 150 void CheckPagesExistOffline(const std::set<GURL>& urls, | 152 void CheckPagesExistOffline(const std::set<GURL>& urls, |
| 151 const CheckPagesExistOfflineCallback& callback); | 153 const CheckPagesExistOfflineCallback& callback); |
| 152 | 154 |
| 153 // Gets all available offline pages. | 155 // Gets all available offline pages. |
| 154 // Making virtual for test purposes. | 156 void GetAllPages(const MultipleOfflinePageItemCallback& callback) override; |
| 155 virtual void GetAllPages(const MultipleOfflinePageItemCallback& callback); | |
| 156 | 157 |
| 157 // Gets all offline ids where the offline page has the matching client id. | 158 // Gets all offline ids where the offline page has the matching client id. |
| 158 void GetOfflineIdsForClientId(const ClientId& client_id, | 159 void GetOfflineIdsForClientId(const ClientId& client_id, |
| 159 const MultipleOfflineIdCallback& callback); | 160 const MultipleOfflineIdCallback& callback); |
| 160 | 161 |
| 161 // Gets all offline ids where the offline page has the matching client id. | 162 // Gets all offline ids where the offline page has the matching client id. |
| 162 // Requires that the model is loaded. May not return matching IDs depending | 163 // Requires that the model is loaded. May not return matching IDs depending |
| 163 // on the internal state of the model. | 164 // on the internal state of the model. |
| 164 // | 165 // |
| 165 // This function is deprecated. Use |GetOfflineIdsForClientId| instead. | 166 // This function is deprecated. Use |GetOfflineIdsForClientId| instead. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 // deleted. In the latter case |reporting_after_delete| is set to true. | 217 // deleted. In the latter case |reporting_after_delete| is set to true. |
| 217 // Caller is supposed to provide the current |total_space_bytes| on drive | 218 // Caller is supposed to provide the current |total_space_bytes| on drive |
| 218 // where the pages are stored, as well as |free_space_bytes| after the | 219 // where the pages are stored, as well as |free_space_bytes| after the |
| 219 // operation was taken. The method will report total size of all pages, and | 220 // operation was taken. The method will report total size of all pages, and |
| 220 // percentage of size of pages as compared to total space and free space. | 221 // percentage of size of pages as compared to total space and free space. |
| 221 void RecordStorageHistograms(int64_t total_space_bytes, | 222 void RecordStorageHistograms(int64_t total_space_bytes, |
| 222 int64_t free_space_bytes, | 223 int64_t free_space_bytes, |
| 223 bool reporting_after_delete); | 224 bool reporting_after_delete); |
| 224 | 225 |
| 225 // Returns the policy controller. | 226 // Returns the policy controller. |
| 226 // Making virtual for test purposes. | 227 ClientPolicyController* GetPolicyController(); |
| 227 virtual ClientPolicyController* GetPolicyController(); | |
| 228 | 228 |
| 229 // Methods for testing only: | 229 // Methods for testing only: |
| 230 OfflinePageMetadataStore* GetStoreForTesting(); | 230 OfflinePageMetadataStore* GetStoreForTesting(); |
| 231 | 231 |
| 232 OfflinePageStorageManager* GetStorageManager(); | 232 OfflinePageStorageManager* GetStorageManager(); |
| 233 | 233 |
| 234 // Making virtual for test purposes. | 234 bool is_loaded() const; |
| 235 virtual bool is_loaded() const; | |
| 236 | 235 |
| 237 protected: | 236 protected: |
| 238 // Adding a protected constructor for testing-only purposes in | 237 // Adding a protected constructor for testing-only purposes in |
| 239 // offline_page_storage_manager_unittest.cc | 238 // offline_page_storage_manager_unittest.cc |
| 240 OfflinePageModel(); | 239 OfflinePageModel(); |
| 241 | 240 |
| 242 private: | 241 private: |
| 243 FRIEND_TEST_ALL_PREFIXES(OfflinePageModelTest, MarkPageForDeletion); | 242 FRIEND_TEST_ALL_PREFIXES(OfflinePageModelTest, MarkPageForDeletion); |
| 244 | 243 |
| 245 typedef ScopedVector<OfflinePageArchiver> PendingArchivers; | 244 typedef ScopedVector<OfflinePageArchiver> PendingArchivers; |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 std::unique_ptr<OfflinePageStorageManager> storage_manager_; | 368 std::unique_ptr<OfflinePageStorageManager> storage_manager_; |
| 370 | 369 |
| 371 base::WeakPtrFactory<OfflinePageModel> weak_ptr_factory_; | 370 base::WeakPtrFactory<OfflinePageModel> weak_ptr_factory_; |
| 372 | 371 |
| 373 DISALLOW_COPY_AND_ASSIGN(OfflinePageModel); | 372 DISALLOW_COPY_AND_ASSIGN(OfflinePageModel); |
| 374 }; | 373 }; |
| 375 | 374 |
| 376 } // namespace offline_pages | 375 } // namespace offline_pages |
| 377 | 376 |
| 378 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_H_ | 377 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_H_ |
| OLD | NEW |