| 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 <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "components/keyed_service/core/keyed_service.h" | 12 #include "components/keyed_service/core/keyed_service.h" |
| 13 #include "components/offline_pages/offline_page_archiver.h" |
| 13 | 14 |
| 14 class GURL; | 15 class GURL; |
| 15 | 16 |
| 16 namespace offline_pages { | 17 namespace offline_pages { |
| 17 | 18 |
| 18 struct OfflinePageItem; | 19 struct OfflinePageItem; |
| 19 class OfflinePageMetadataStore; | 20 class OfflinePageMetadataStore; |
| 20 | 21 |
| 21 // Serivce for saving pages offline, storing the offline copy and metadata, and | 22 // Serivce for saving pages offline, storing the offline copy and metadata, and |
| 22 // retrieving them upon request. | 23 // retrieving them upon request. |
| 23 class OfflinePageModel : public KeyedService { | 24 class OfflinePageModel : public KeyedService, |
| 25 public OfflinePageArchiver::Client { |
| 24 public: | 26 public: |
| 25 explicit OfflinePageModel(scoped_ptr<OfflinePageMetadataStore> store); | 27 OfflinePageModel(scoped_ptr<OfflinePageMetadataStore> store, |
| 28 OfflinePageArchiver* archiver); |
| 26 ~OfflinePageModel() override; | 29 ~OfflinePageModel() override; |
| 27 | 30 |
| 28 // KeyedService: | 31 // KeyedService implementation. |
| 29 void Shutdown() override; | 32 void Shutdown() override; |
| 30 | 33 |
| 34 // OfflinePageArchiver::Client implementation. |
| 35 void OnCreateArchiveSuccess(const OfflinePageArchiver::Request& request, |
| 36 const base::FilePath& file_path) override; |
| 37 void OnCreateArchiveFailure( |
| 38 const OfflinePageArchiver::Request& request) override; |
| 39 |
| 31 // Saves the page loaded in the web contents offline. | 40 // Saves the page loaded in the web contents offline. |
| 32 void SavePageOffline(const GURL& url); | 41 void SavePageOffline(const GURL& url); |
| 33 | 42 |
| 34 // Gets a set of all offline pages metadata. | 43 // Gets a set of all offline pages metadata. |
| 35 std::vector<OfflinePageItem> GetAllOfflinePages(); | 44 std::vector<OfflinePageItem> GetAllOfflinePages(); |
| 36 | 45 |
| 37 // Methods for testing only: | 46 // Methods for testing only: |
| 38 OfflinePageMetadataStore* GetStoreForTesting(); | 47 OfflinePageMetadataStore* GetStoreForTesting(); |
| 39 | 48 |
| 40 private: | 49 private: |
| 41 // Persistent store for offline page metadata. | 50 // Persistent store for offline page metadata. |
| 42 scoped_ptr<OfflinePageMetadataStore> store_; | 51 scoped_ptr<OfflinePageMetadataStore> store_; |
| 43 | 52 |
| 53 // Offline page archiver. Outlives the model. Owned by the embedder. |
| 54 OfflinePageArchiver* archiver_; |
| 55 |
| 44 DISALLOW_COPY_AND_ASSIGN(OfflinePageModel); | 56 DISALLOW_COPY_AND_ASSIGN(OfflinePageModel); |
| 45 }; | 57 }; |
| 46 | 58 |
| 47 } // namespace offline_pages | 59 } // namespace offline_pages |
| 48 | 60 |
| 49 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_H_ | 61 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_H_ |
| OLD | NEW |