| 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> |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 class TimeDelta; | 33 class TimeDelta; |
| 34 } | 34 } |
| 35 | 35 |
| 36 namespace offline_pages { | 36 namespace offline_pages { |
| 37 | 37 |
| 38 static const char* const kBookmarkNamespace = "bookmark"; | 38 static const char* const kBookmarkNamespace = "bookmark"; |
| 39 static const int64_t kInvalidOfflineId = 0; | 39 static const int64_t kInvalidOfflineId = 0; |
| 40 | 40 |
| 41 struct ClientId; | 41 struct ClientId; |
| 42 | 42 |
| 43 class ClientPolicyController; |
| 43 struct OfflinePageItem; | 44 struct OfflinePageItem; |
| 44 class OfflinePageMetadataStore; | 45 class OfflinePageMetadataStore; |
| 46 class OfflinePageStorageManager; |
| 45 | 47 |
| 46 // Service for saving pages offline, storing the offline copy and metadata, and | 48 // Service for saving pages offline, storing the offline copy and metadata, and |
| 47 // retrieving them upon request. | 49 // retrieving them upon request. |
| 48 // | 50 // |
| 49 // Example usage: | 51 // Example usage: |
| 50 // class ArchiverImpl : public OfflinePageArchiver { | 52 // class ArchiverImpl : public OfflinePageArchiver { |
| 51 // // This is a class that knows how to create archiver | 53 // // This is a class that knows how to create archiver |
| 52 // void CreateArchiver(...) override; | 54 // void CreateArchiver(...) override; |
| 53 // ... | 55 // ... |
| 54 // } | 56 // } |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 // Marks that the offline page related to the passed |offline_id| has been | 170 // Marks that the offline page related to the passed |offline_id| has been |
| 169 // accessed. Its access info, including last access time and access count, | 171 // accessed. Its access info, including last access time and access count, |
| 170 // will be updated. Requires that the model is loaded. | 172 // will be updated. Requires that the model is loaded. |
| 171 void MarkPageAccessed(int64_t offline_id); | 173 void MarkPageAccessed(int64_t offline_id); |
| 172 | 174 |
| 173 // Deletes an offline page related to the passed |offline_id|. | 175 // Deletes an offline page related to the passed |offline_id|. |
| 174 void DeletePageByOfflineId(int64_t offline_id, | 176 void DeletePageByOfflineId(int64_t offline_id, |
| 175 const DeletePageCallback& callback); | 177 const DeletePageCallback& callback); |
| 176 | 178 |
| 177 // Deletes offline pages related to the passed |offline_ids|. | 179 // Deletes offline pages related to the passed |offline_ids|. |
| 178 void DeletePagesByOfflineId(const std::vector<int64_t>& offline_ids, | 180 // Making virtual for test purposes. |
| 179 const DeletePageCallback& callback); | 181 virtual void DeletePagesByOfflineId(const std::vector<int64_t>& offline_ids, |
| 182 const DeletePageCallback& callback); |
| 180 | 183 |
| 181 // Wipes out all the data by deleting all saved files and clearing the store. | 184 // Wipes out all the data by deleting all saved files and clearing the store. |
| 182 void ClearAll(const base::Closure& callback); | 185 void ClearAll(const base::Closure& callback); |
| 183 | 186 |
| 184 // Deletes offline pages matching the URL predicate. | 187 // Deletes offline pages matching the URL predicate. |
| 185 void DeletePagesByURLPredicate( | 188 void DeletePagesByURLPredicate( |
| 186 const base::Callback<bool(const GURL&)>& predicate, | 189 const base::Callback<bool(const GURL&)>& predicate, |
| 187 const DeletePageCallback& callback); | 190 const DeletePageCallback& callback); |
| 188 | 191 |
| 189 // Returns true via callback if there are offline pages in the given | 192 // Returns true via callback if there are offline pages in the given |
| 190 // |name_space|. | 193 // |name_space|. |
| 191 void HasPages(const std::string& name_space, | 194 void HasPages(const std::string& name_space, |
| 192 const HasPagesCallback& callback); | 195 const HasPagesCallback& callback); |
| 193 | 196 |
| 194 // Returns via callback all GURLs in |urls| that are equal to the online URL | 197 // Returns via callback all GURLs in |urls| that are equal to the online URL |
| 195 // of any offline page. | 198 // of any offline page. |
| 196 void CheckPagesExistOffline(const std::set<GURL>& urls, | 199 void CheckPagesExistOffline(const std::set<GURL>& urls, |
| 197 const CheckPagesExistOfflineCallback& callback); | 200 const CheckPagesExistOfflineCallback& callback); |
| 198 | 201 |
| 199 // Gets all available offline pages. | 202 // Gets all available offline pages. |
| 200 void GetAllPages(const MultipleOfflinePageItemCallback& callback); | 203 // Making virtual for test purposes. |
| 204 virtual void GetAllPages(const MultipleOfflinePageItemCallback& callback); |
| 201 | 205 |
| 202 // Gets all offline ids where the offline page has the matching client id. | 206 // Gets all offline ids where the offline page has the matching client id. |
| 203 void GetOfflineIdsForClientId(const ClientId& client_id, | 207 void GetOfflineIdsForClientId(const ClientId& client_id, |
| 204 const MultipleOfflineIdCallback& callback); | 208 const MultipleOfflineIdCallback& callback); |
| 205 | 209 |
| 206 // Gets all offline ids where the offline page has the matching client id. | 210 // Gets all offline ids where the offline page has the matching client id. |
| 207 // Requires that the model is loaded. May not return matching IDs depending | 211 // Requires that the model is loaded. May not return matching IDs depending |
| 208 // on the internal state of the model. | 212 // on the internal state of the model. |
| 209 // | 213 // |
| 210 // This function is deprecated. Use |GetOfflineIdsForClientId| instead. | 214 // This function is deprecated. Use |GetOfflineIdsForClientId| instead. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 // pages. Method is to be called after a page was saved or some pages are | 254 // pages. Method is to be called after a page was saved or some pages are |
| 251 // deleted. In the latter case |reporting_after_delete| is set to true. | 255 // deleted. In the latter case |reporting_after_delete| is set to true. |
| 252 // Caller is supposed to provide the current |total_space_bytes| on drive | 256 // Caller is supposed to provide the current |total_space_bytes| on drive |
| 253 // where the pages are stored, as well as |free_space_bytes| after the | 257 // where the pages are stored, as well as |free_space_bytes| after the |
| 254 // operation was taken. The method will report total size of all pages, and | 258 // operation was taken. The method will report total size of all pages, and |
| 255 // percentage of size of pages as compared to total space and free space. | 259 // percentage of size of pages as compared to total space and free space. |
| 256 void RecordStorageHistograms(int64_t total_space_bytes, | 260 void RecordStorageHistograms(int64_t total_space_bytes, |
| 257 int64_t free_space_bytes, | 261 int64_t free_space_bytes, |
| 258 bool reporting_after_delete); | 262 bool reporting_after_delete); |
| 259 | 263 |
| 264 // Returns the policy controller. |
| 265 // Making virtual for test purposes. |
| 266 virtual ClientPolicyController* GetPolicyController(); |
| 267 |
| 260 // Methods for testing only: | 268 // Methods for testing only: |
| 261 OfflinePageMetadataStore* GetStoreForTesting(); | 269 OfflinePageMetadataStore* GetStoreForTesting(); |
| 262 | 270 |
| 263 bool is_loaded() const { return is_loaded_; } | 271 OfflinePageStorageManager* GetStorageManager(); |
| 272 |
| 273 // Making virtual for test purposes. |
| 274 virtual bool is_loaded() const; |
| 275 |
| 276 protected: |
| 277 // Adding a protected constructor for testing-only purposes in |
| 278 // offline_page_storage_manager_unittest.cc |
| 279 OfflinePageModel(); |
| 264 | 280 |
| 265 private: | 281 private: |
| 266 FRIEND_TEST_ALL_PREFIXES(OfflinePageModelTest, MarkPageForDeletion); | 282 FRIEND_TEST_ALL_PREFIXES(OfflinePageModelTest, MarkPageForDeletion); |
| 267 | 283 |
| 268 typedef ScopedVector<OfflinePageArchiver> PendingArchivers; | 284 typedef ScopedVector<OfflinePageArchiver> PendingArchivers; |
| 269 | 285 |
| 270 // Callback for ensuring archive directory is created. | 286 // Callback for ensuring archive directory is created. |
| 271 void OnEnsureArchivesDirCreatedDone(); | 287 void OnEnsureArchivesDirCreatedDone(); |
| 272 | 288 |
| 273 void GetAllPagesAfterLoadDone( | 289 void GetAllPagesAfterLoadDone( |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 std::map<int64_t, OfflinePageItem> offline_pages_; | 390 std::map<int64_t, OfflinePageItem> offline_pages_; |
| 375 | 391 |
| 376 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 392 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| 377 | 393 |
| 378 // Pending archivers owned by this model. | 394 // Pending archivers owned by this model. |
| 379 PendingArchivers pending_archivers_; | 395 PendingArchivers pending_archivers_; |
| 380 | 396 |
| 381 // Delayed tasks that should be invoked after the loading is done. | 397 // Delayed tasks that should be invoked after the loading is done. |
| 382 std::vector<base::Closure> delayed_tasks_; | 398 std::vector<base::Closure> delayed_tasks_; |
| 383 | 399 |
| 400 // Controller of the client policies. |
| 401 std::unique_ptr<ClientPolicyController> policy_controller_; |
| 402 |
| 403 // Manager for the storage consumed by archives and responsible for |
| 404 // automatic page clearing. |
| 405 std::unique_ptr<OfflinePageStorageManager> storage_manager_; |
| 406 |
| 384 base::WeakPtrFactory<OfflinePageModel> weak_ptr_factory_; | 407 base::WeakPtrFactory<OfflinePageModel> weak_ptr_factory_; |
| 385 | 408 |
| 386 DISALLOW_COPY_AND_ASSIGN(OfflinePageModel); | 409 DISALLOW_COPY_AND_ASSIGN(OfflinePageModel); |
| 387 }; | 410 }; |
| 388 | 411 |
| 389 } // namespace offline_pages | 412 } // namespace offline_pages |
| 390 | 413 |
| 391 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_H_ | 414 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_H_ |
| OLD | NEW |