| 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 <memory> | 10 #include <memory> |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 // | 40 // |
| 41 // // In code using the OfflinePagesModel to save a page: | 41 // // In code using the OfflinePagesModel to save a page: |
| 42 // std::unique_ptr<ArchiverImpl> archiver(new ArchiverImpl()); | 42 // std::unique_ptr<ArchiverImpl> archiver(new ArchiverImpl()); |
| 43 // // Callback is of type SavePageCallback. | 43 // // Callback is of type SavePageCallback. |
| 44 // model->SavePage(url, std::move(archiver), callback); | 44 // model->SavePage(url, std::move(archiver), callback); |
| 45 // | 45 // |
| 46 // TODO(fgorski): Things to describe: | 46 // TODO(fgorski): Things to describe: |
| 47 // * how to cancel requests and what to expect | 47 // * how to cancel requests and what to expect |
| 48 class OfflinePageModel : public base::SupportsUserData { | 48 class OfflinePageModel : public base::SupportsUserData { |
| 49 public: | 49 public: |
| 50 // Describes the parameters to control how to save a page. |
| 51 struct SavePageParams { |
| 52 SavePageParams(); |
| 53 SavePageParams(const SavePageParams& other); |
| 54 |
| 55 // The last committed URL of the page to save. |
| 56 GURL url; |
| 57 |
| 58 // The identification used by the client. |
| 59 ClientId client_id; |
| 60 |
| 61 // Used for the offline_id for the saved file if non-zero. If it is |
| 62 // kInvalidOfflineId, a new, random ID will be generated. |
| 63 int64_t proposed_offline_id; |
| 64 |
| 65 // The original URL of the page to save. Empty if no redirect occurs. |
| 66 GURL original_url; |
| 67 }; |
| 68 |
| 50 // Observer of the OfflinePageModel. | 69 // Observer of the OfflinePageModel. |
| 51 class Observer { | 70 class Observer { |
| 52 public: | 71 public: |
| 53 // Invoked when the model has finished loading. | 72 // Invoked when the model has finished loading. |
| 54 virtual void OfflinePageModelLoaded(OfflinePageModel* model) = 0; | 73 virtual void OfflinePageModelLoaded(OfflinePageModel* model) = 0; |
| 55 | 74 |
| 56 // Invoked when the model is being updated, due to adding, removing or | 75 // Invoked when the model is being updated, due to adding, removing or |
| 57 // updating an offline page. | 76 // updating an offline page. |
| 58 virtual void OfflinePageModelChanged(OfflinePageModel* model) = 0; | 77 virtual void OfflinePageModelChanged(OfflinePageModel* model) = 0; |
| 59 | 78 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 76 static bool CanSaveURL(const GURL& url); | 95 static bool CanSaveURL(const GURL& url); |
| 77 | 96 |
| 78 OfflinePageModel(); | 97 OfflinePageModel(); |
| 79 ~OfflinePageModel() override; | 98 ~OfflinePageModel() override; |
| 80 | 99 |
| 81 virtual void AddObserver(Observer* observer) = 0; | 100 virtual void AddObserver(Observer* observer) = 0; |
| 82 virtual void RemoveObserver(Observer* observer) = 0; | 101 virtual void RemoveObserver(Observer* observer) = 0; |
| 83 | 102 |
| 84 static const int64_t kInvalidOfflineId = 0; | 103 static const int64_t kInvalidOfflineId = 0; |
| 85 | 104 |
| 86 // Attempts to save a page addressed by |url| offline. Requires that the model | 105 // Attempts to save a page offline per |save_page_params|. Requires that the |
| 87 // is loaded. Generates a new offline id and returns | 106 // model is loaded. Generates a new offline id or uses the proposed offline |
| 88 // it. |proposed_offline_id| is used for the offline_id for the saved file if | 107 // id in |save_page_params| and returns it. |
| 89 // it is non-zero. If it is kInvalidOfflineId, a new, random ID will be | 108 virtual void SavePage(const SavePageParams& save_page_params, |
| 90 // generated. | |
| 91 virtual void SavePage(const GURL& url, | |
| 92 const ClientId& client_id, | |
| 93 int64_t proposed_offline_id, | |
| 94 std::unique_ptr<OfflinePageArchiver> archiver, | 109 std::unique_ptr<OfflinePageArchiver> archiver, |
| 95 const SavePageCallback& callback) = 0; | 110 const SavePageCallback& callback) = 0; |
| 96 | 111 |
| 97 // Marks that the offline page related to the passed |offline_id| has been | 112 // Marks that the offline page related to the passed |offline_id| has been |
| 98 // accessed. Its access info, including last access time and access count, | 113 // accessed. Its access info, including last access time and access count, |
| 99 // will be updated. Requires that the model is loaded. | 114 // will be updated. Requires that the model is loaded. |
| 100 virtual void MarkPageAccessed(int64_t offline_id) = 0; | 115 virtual void MarkPageAccessed(int64_t offline_id) = 0; |
| 101 | 116 |
| 102 // Deletes pages based on |offline_ids|. | 117 // Deletes pages based on |offline_ids|. |
| 103 virtual void DeletePagesByOfflineId(const std::vector<int64_t>& offline_ids, | 118 virtual void DeletePagesByOfflineId(const std::vector<int64_t>& offline_ids, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 // TODO(dougarnett): Remove this and its uses. | 172 // TODO(dougarnett): Remove this and its uses. |
| 158 virtual bool is_loaded() const = 0; | 173 virtual bool is_loaded() const = 0; |
| 159 | 174 |
| 160 // Returns the logger. Ownership is retained by the model. | 175 // Returns the logger. Ownership is retained by the model. |
| 161 virtual OfflineEventLogger* GetLogger() = 0; | 176 virtual OfflineEventLogger* GetLogger() = 0; |
| 162 }; | 177 }; |
| 163 | 178 |
| 164 } // namespace offline_pages | 179 } // namespace offline_pages |
| 165 | 180 |
| 166 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_H_ | 181 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_H_ |
| OLD | NEW |