Chromium Code Reviews| 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> | |
| 11 #include <memory> | 10 #include <memory> |
| 12 #include <set> | 11 #include <set> |
| 12 #include <string> | |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/callback.h" | |
| 16 #include "base/files/file_path.h" | |
| 17 #include "base/gtest_prod_util.h" | |
| 18 #include "base/macros.h" | |
| 19 #include "base/memory/ref_counted.h" | |
| 20 #include "base/memory/scoped_vector.h" | |
| 21 #include "base/memory/weak_ptr.h" | |
| 22 #include "base/observer_list.h" | |
| 23 #include "base/optional.h" | |
| 24 #include "base/supports_user_data.h" | 15 #include "base/supports_user_data.h" |
| 25 #include "components/keyed_service/core/keyed_service.h" | 16 #include "components/keyed_service/core/keyed_service.h" |
| 26 #include "components/offline_pages/offline_page_archiver.h" | 17 #include "components/offline_pages/offline_page_archiver.h" |
| 27 #include "components/offline_pages/offline_page_metadata_store.h" | |
| 28 #include "components/offline_pages/offline_page_storage_manager.h" | 18 #include "components/offline_pages/offline_page_storage_manager.h" |
| 29 #include "components/offline_pages/offline_page_types.h" | 19 #include "components/offline_pages/offline_page_types.h" |
| 30 | 20 |
| 31 class GURL; | 21 class GURL; |
| 32 namespace base { | 22 namespace base { |
| 33 class SequencedTaskRunner; | |
| 34 class Time; | 23 class Time; |
| 35 class TimeDelta; | |
| 36 class TimeTicks; | |
| 37 } // namespace base | 24 } // namespace base |
| 38 | 25 |
| 39 namespace offline_pages { | 26 namespace offline_pages { |
| 40 | 27 |
| 41 static const char* const kBookmarkNamespace = "bookmark"; | 28 static const char* const kBookmarkNamespace = "bookmark"; |
| 42 static const int64_t kInvalidOfflineId = 0; | 29 static const int64_t kInvalidOfflineId = 0; |
| 43 | 30 |
| 44 struct ClientId; | 31 struct ClientId; |
| 45 struct OfflinePageItem; | 32 struct OfflinePageItem; |
| 46 | 33 |
| 47 class ArchiveManager; | |
| 48 class ClientPolicyController; | |
| 49 class OfflinePageMetadataStore; | |
| 50 class OfflinePageStorageManager; | |
| 51 | |
| 52 // Service for saving pages offline, storing the offline copy and metadata, and | 34 // Service for saving pages offline, storing the offline copy and metadata, and |
| 53 // retrieving them upon request. | 35 // retrieving them upon request. |
| 54 // | 36 // |
| 55 // Example usage: | 37 // Example usage: |
| 56 // class ArchiverImpl : public OfflinePageArchiver { | 38 // class ArchiverImpl : public OfflinePageArchiver { |
| 57 // // This is a class that knows how to create archiver | 39 // // This is a class that knows how to create archiver |
| 58 // void CreateArchiver(...) override; | 40 // void CreateArchiver(...) override; |
| 59 // ... | 41 // ... |
| 60 // } | 42 // } |
| 61 // | 43 // |
| 62 // // In code using the OfflinePagesModel to save a page: | 44 // // In code using the OfflinePagesModel to save a page: |
| 63 // std::unique_ptr<ArchiverImpl> archiver(new ArchiverImpl()); | 45 // std::unique_ptr<ArchiverImpl> archiver(new ArchiverImpl()); |
| 64 // // Callback is of type SavePageCallback. | 46 // // Callback is of type SavePageCallback. |
| 65 // model->SavePage(url, std::move(archiver), callback); | 47 // model->SavePage(url, std::move(archiver), callback); |
| 66 // | 48 // |
| 67 // TODO(fgorski): Things to describe: | 49 // TODO(fgorski): Things to describe: |
| 68 // * how to cancel requests and what to expect | 50 // * how to cancel requests and what to expect |
| 69 class OfflinePageModel : public KeyedService, | 51 class OfflinePageModel : public KeyedService, |
|
dewittj
2016/05/26 16:38:43
I think that this inheritance is wrong. OfflinePa
dougarnett
2016/05/26 20:50:34
Moved inheritances to impl. Have TODO wrt StorageM
dougarnett
2016/05/27 15:22:29
I put StorageManager::Client and SupportsUserData
| |
| 70 public base::SupportsUserData, | 52 public base::SupportsUserData, |
| 71 public OfflinePageStorageManager::Client { | 53 public OfflinePageStorageManager::Client { |
| 72 public: | 54 public: |
| 73 // Observer of the OfflinePageModel. | 55 // Observer of the OfflinePageModel. |
| 74 class Observer { | 56 class Observer { |
| 75 public: | 57 public: |
| 76 // Invoked when the model has finished loading. | 58 // Invoked when the model has finished loading. |
| 77 virtual void OfflinePageModelLoaded(OfflinePageModel* model) = 0; | 59 virtual void OfflinePageModelLoaded(OfflinePageModel* model) = 0; |
| 78 | 60 |
| 79 // Invoked when the model is being updated, due to adding, removing or | 61 // Invoked when the model is being updated, due to adding, removing or |
| 80 // updating an offline page. | 62 // updating an offline page. |
| 81 virtual void OfflinePageModelChanged(OfflinePageModel* model) = 0; | 63 virtual void OfflinePageModelChanged(OfflinePageModel* model) = 0; |
| 82 | 64 |
| 83 // Invoked when an offline copy related to |offline_id| was deleted. | 65 // Invoked when an offline copy related to |offline_id| was deleted. |
| 84 // In can be invoked as a result of |CheckForExternalFileDeletion|, if a | 66 // In can be invoked as a result of |CheckForExternalFileDeletion|, if a |
| 85 // deleted page is detected. | 67 // deleted page is detected. |
| 86 virtual void OfflinePageDeleted(int64_t offline_id, | 68 virtual void OfflinePageDeleted(int64_t offline_id, |
| 87 const ClientId& client_id) = 0; | 69 const ClientId& client_id) = 0; |
| 88 | 70 |
| 89 protected: | 71 protected: |
| 90 virtual ~Observer() {} | 72 virtual ~Observer() {} |
| 91 }; | 73 }; |
| 92 | 74 |
| 93 using CheckPagesExistOfflineResult = | 75 using CheckPagesExistOfflineResult = |
|
dewittj
2016/05/26 16:38:43
these types can now just be declared here, and we
dougarnett
2016/05/26 20:50:34
captured in https://bugs.chromium.org/p/chromium/i
| |
| 94 offline_pages::CheckPagesExistOfflineResult; | 76 offline_pages::CheckPagesExistOfflineResult; |
| 95 using MultipleOfflinePageItemResult = | 77 using MultipleOfflinePageItemResult = |
| 96 offline_pages::MultipleOfflinePageItemResult; | 78 offline_pages::MultipleOfflinePageItemResult; |
| 97 using SingleOfflinePageItemResult = | 79 using SingleOfflinePageItemResult = |
| 98 offline_pages::SingleOfflinePageItemResult; | 80 offline_pages::SingleOfflinePageItemResult; |
| 99 | |
| 100 //using DeletePageCallback = offline_pages::DeletePageCallback; | |
| 101 using DeletePageResult = offline_pages::DeletePageResult; | 81 using DeletePageResult = offline_pages::DeletePageResult; |
| 102 using SavePageResult = offline_pages::SavePageResult; | 82 using SavePageResult = offline_pages::SavePageResult; |
| 103 | 83 |
| 104 // Generates a new offline id | |
| 105 static int64_t GenerateOfflineId(); | |
| 106 | |
| 107 // Returns true if an offline copy can be saved for the given URL. | 84 // Returns true if an offline copy can be saved for the given URL. |
| 108 static bool CanSavePage(const GURL& url); | 85 static bool CanSavePage(const GURL& url); |
|
dewittj
2016/05/26 16:38:43
Not sure that this belongs here now.
dougarnett
2016/05/26 20:50:34
captured in https://bugs.chromium.org/p/chromium/i
| |
| 109 | 86 |
| 110 static base::TimeDelta GetFinalDeletionDelayForTesting(); | 87 OfflinePageModel(); |
|
dewittj
2016/05/26 16:38:43
OfflinePageModel() = default;
dougarnett
2016/05/26 20:50:34
Done.
| |
| 111 | |
| 112 // All blocking calls/disk access will happen on the provided |task_runner|. | |
| 113 OfflinePageModel(std::unique_ptr<OfflinePageMetadataStore> store, | |
| 114 const base::FilePath& archives_dir, | |
| 115 const scoped_refptr<base::SequencedTaskRunner>& task_runner); | |
| 116 ~OfflinePageModel() override; | 88 ~OfflinePageModel() override; |
|
dewittj
2016/05/26 16:38:43
If we make this just an interface, this can become
dougarnett
2016/05/26 20:50:34
Done.
| |
| 117 | 89 |
| 118 void AddObserver(Observer* observer); | 90 virtual void AddObserver(Observer* observer) = 0; |
| 119 void RemoveObserver(Observer* observer); | 91 virtual void RemoveObserver(Observer* observer) = 0; |
| 120 | 92 |
| 121 // Attempts to save a page addressed by |url| offline. Requires that the model | 93 // Attempts to save a page addressed by |url| offline. Requires that the model |
| 122 // is loaded. Generates a new offline id and returns it. | 94 // is loaded. Generates a new offline id and returns it. |
| 123 void SavePage(const GURL& url, | 95 virtual void SavePage(const GURL& url, |
| 124 const ClientId& client_id, | 96 const ClientId& client_id, |
| 125 std::unique_ptr<OfflinePageArchiver> archiver, | 97 std::unique_ptr<OfflinePageArchiver> archiver, |
| 126 const SavePageCallback& callback); | 98 const SavePageCallback& callback) = 0; |
| 127 | 99 |
| 128 // Marks that the offline page related to the passed |offline_id| has been | 100 // Marks that the offline page related to the passed |offline_id| has been |
| 129 // accessed. Its access info, including last access time and access count, | 101 // accessed. Its access info, including last access time and access count, |
| 130 // will be updated. Requires that the model is loaded. | 102 // will be updated. Requires that the model is loaded. |
| 131 void MarkPageAccessed(int64_t offline_id); | 103 virtual void MarkPageAccessed(int64_t offline_id) = 0; |
| 132 | 104 |
| 133 // Deletes an offline page related to the passed |offline_id|. | 105 // TODO(romax): Pull this interface up from OfflinePageStorageManager::Client |
|
dewittj
2016/05/26 16:38:43
Probably should just do that in this refactor.
dougarnett
2016/05/26 20:50:34
captured in https://bugs.chromium.org/p/chromium/i
| |
| 134 void DeletePageByOfflineId(int64_t offline_id, | 106 // void DeletePagesByOfflineId(const std::vector<int64_t>& offline_ids, |
| 135 const DeletePageCallback& callback); | 107 // const DeletePageCallback& callback); |
| 136 | |
| 137 // Deletes offline pages related to the passed |offline_ids|. | |
| 138 void DeletePagesByOfflineId(const std::vector<int64_t>& offline_ids, | |
| 139 const DeletePageCallback& callback) override; | |
| 140 | 108 |
| 141 // Wipes out all the data by deleting all saved files and clearing the store. | 109 // Wipes out all the data by deleting all saved files and clearing the store. |
| 142 void ClearAll(const base::Closure& callback); | 110 virtual void ClearAll(const base::Closure& callback) = 0; |
| 143 | 111 |
| 144 // Deletes offline pages matching the URL predicate. | 112 // Deletes offline pages matching the URL predicate. |
| 145 void DeletePagesByURLPredicate(const UrlPredicate& predicate, | 113 virtual void DeletePagesByURLPredicate( |
| 146 const DeletePageCallback& callback); | 114 const UrlPredicate& predicate, |
| 115 const DeletePageCallback& callback) = 0; | |
| 147 | 116 |
| 148 // Returns true via callback if there are offline pages in the given | 117 // Returns true via callback if there are offline pages in the given |
| 149 // |name_space|. | 118 // |name_space|. |
| 150 void HasPages(const std::string& name_space, | 119 virtual void HasPages(const std::string& name_space, |
| 151 const HasPagesCallback& callback); | 120 const HasPagesCallback& callback) = 0; |
| 152 | 121 |
| 153 // Returns via callback all GURLs in |urls| that are equal to the online URL | 122 // Returns via callback all GURLs in |urls| that are equal to the online URL |
| 154 // of any offline page. | 123 // of any offline page. |
| 155 void CheckPagesExistOffline(const std::set<GURL>& urls, | 124 virtual void CheckPagesExistOffline( |
| 156 const CheckPagesExistOfflineCallback& callback); | 125 const std::set<GURL>& urls, |
| 157 | 126 const CheckPagesExistOfflineCallback& callback) = 0; |
| 158 // Gets all available offline pages. | |
| 159 void GetAllPages(const MultipleOfflinePageItemCallback& callback) override; | |
| 160 | 127 |
| 161 // Gets all offline ids where the offline page has the matching client id. | 128 // Gets all offline ids where the offline page has the matching client id. |
| 162 void GetOfflineIdsForClientId(const ClientId& client_id, | 129 virtual void GetOfflineIdsForClientId( |
| 163 const MultipleOfflineIdCallback& callback); | 130 const ClientId& client_id, |
| 131 const MultipleOfflineIdCallback& callback) = 0; | |
| 164 | 132 |
| 165 // Gets all offline ids where the offline page has the matching client id. | 133 // Gets all offline ids where the offline page has the matching client id. |
| 166 // Requires that the model is loaded. May not return matching IDs depending | 134 // Requires that the model is loaded. May not return matching IDs depending |
| 167 // on the internal state of the model. | 135 // on the internal state of the model.#include <algorithm> |
|
dewittj
2016/05/26 16:38:43
copy/paste error?
dougarnett
2016/05/26 20:50:34
Done.
| |
| 168 // | 136 // |
| 169 // This function is deprecated. Use |GetOfflineIdsForClientId| instead. | 137 // This function is deprecated. Use |GetOfflineIdsForClientId| instead. |
| 170 const std::vector<int64_t> MaybeGetOfflineIdsForClientId( | 138 virtual const std::vector<int64_t> MaybeGetOfflineIdsForClientId( |
| 171 const ClientId& client_id) const; | 139 const ClientId& client_id) const = 0; |
| 172 | 140 |
| 173 // Returns zero or one offline pages associated with a specified |offline_id|. | 141 // Returns zero or one offline pages associated with a specified |offline_id|. |
| 174 void GetPageByOfflineId(int64_t offline_id, | 142 virtual void GetPageByOfflineId( |
| 175 const SingleOfflinePageItemCallback& callback); | 143 int64_t offline_id, |
| 144 const SingleOfflinePageItemCallback& callback) = 0; | |
| 176 | 145 |
| 177 // Returns an offline page associated with a specified |offline_id|. nullptr | 146 // Returns an offline page associated with a specified |offline_id|. nullptr |
| 178 // is returned if not found. | 147 // is returned if not found. |
| 179 const OfflinePageItem* MaybeGetPageByOfflineId(int64_t offline_id) const; | 148 virtual const OfflinePageItem* MaybeGetPageByOfflineId( |
| 149 int64_t offline_id) const = 0; | |
| 180 | 150 |
| 181 // Returns the offline page that is stored under |offline_url|, if any. | 151 // Returns the offline page that is stored under |offline_url|, if any. |
| 182 void GetPageByOfflineURL(const GURL& offline_url, | 152 virtual void GetPageByOfflineURL( |
| 183 const SingleOfflinePageItemCallback& callback); | 153 const GURL& offline_url, |
| 154 const SingleOfflinePageItemCallback& callback) = 0; | |
| 184 | 155 |
| 185 // Returns an offline page that is stored as |offline_url|. A nullptr is | 156 // Returns an offline page that is stored as |offline_url|. A nullptr is |
| 186 // returned if not found. | 157 // returned if not found. |
| 187 // | 158 // |
| 188 // This function is deprecated, and may return |nullptr| even if a page | 159 // This function is deprecated, and may return |nullptr| even if a page |
| 189 // exists, depending on the implementation details of OfflinePageModel. | 160 // exists, depending on the implementation details of OfflinePageModel. |
| 190 // Use |GetPageByOfflineURL| instead. | 161 // Use |GetPageByOfflineURL| instead. |
| 191 const OfflinePageItem* MaybeGetPageByOfflineURL( | 162 virtual const OfflinePageItem* MaybeGetPageByOfflineURL( |
| 192 const GURL& offline_url) const; | 163 const GURL& offline_url) const = 0; |
| 193 | 164 |
| 194 // Returns the offline pages that are stored under |online_url|. | 165 // Returns the offline pages that are stored under |online_url|. |
| 195 void GetPagesByOnlineURL(const GURL& online_url, | 166 virtual void GetPagesByOnlineURL( |
| 196 const MultipleOfflinePageItemCallback& callback); | 167 const GURL& online_url, |
| 168 const MultipleOfflinePageItemCallback& callback) = 0; | |
| 197 | 169 |
| 198 // Returns via callback an offline page saved for |online_url|, if any. The | 170 // Returns via callback an offline page saved for |online_url|, if any. The |
| 199 // best page is chosen based on creation date; a more recently created offline | 171 // best page is chosen based on creation date; a more recently created offline |
| 200 // page will be preferred over an older one. This API function does not | 172 // page will be preferred over an older one. This API function does not |
| 201 // respect namespaces, as it is used to choose which page is rendered in a | 173 // respect namespaces, as it is used to choose which page is rendered in a |
| 202 // tab. Today all namespaces are treated equally for the purposes of this | 174 // tab. Today all namespaces are treated equally for the purposes of this |
| 203 // selection. | 175 // selection. |
| 204 void GetBestPageForOnlineURL(const GURL& online_url, | 176 virtual void GetBestPageForOnlineURL( |
| 205 const SingleOfflinePageItemCallback callback); | 177 const GURL& online_url, |
| 178 const SingleOfflinePageItemCallback callback) = 0; | |
| 206 | 179 |
| 207 // Returns an offline page saved for |online_url|. A nullptr is returned if | 180 // Returns an offline page saved for |online_url|. A nullptr is returned if |
| 208 // not found. See |GetBestPageForOnlineURL| for selection criteria. | 181 // not found. See |GetBestPageForOnlineURL| for selection criteria. |
| 209 const OfflinePageItem* MaybeGetBestPageForOnlineURL( | 182 virtual const OfflinePageItem* MaybeGetBestPageForOnlineURL( |
| 210 const GURL& online_url) const; | 183 const GURL& online_url) const = 0; |
| 211 | 184 |
| 212 // Checks that all of the offline pages have corresponding offline copies. | 185 // Checks that all of the offline pages have corresponding offline copies. |
| 213 // If a page is discovered to be missing an offline copy, its offline page | 186 // If a page is discovered to be missing an offline copy, its offline page |
| 214 // metadata will be removed and |OfflinePageDeleted| will be sent to model | 187 // metadata will be removed and |OfflinePageDeleted| will be sent to model |
| 215 // observers. | 188 // observers. |
| 216 void CheckForExternalFileDeletion(); | 189 virtual void CheckForExternalFileDeletion() = 0; |
| 217 | 190 |
| 218 // Marks pages as expired and removes their respective files from the archive | 191 // Marks pages as expired and removes their respective files from the archive |
| 219 // directory. | 192 // directory. |
| 220 void ExpirePages(const std::vector<int64_t>& offline_ids, | 193 virtual void ExpirePages(const std::vector<int64_t>& offline_ids, |
| 221 const base::Time& expiration_time); | 194 const base::Time& expiration_time) = 0; |
| 222 | 195 |
| 223 // Returns the policy controller. | 196 // Returns the policy controller. |
| 224 ClientPolicyController* GetPolicyController(); | 197 virtual ClientPolicyController* GetPolicyController() = 0; |
| 225 | 198 |
| 226 // Methods for testing only: | 199 // Method for testing only: |
| 227 OfflinePageMetadataStore* GetStoreForTesting(); | 200 virtual bool is_loaded() const = 0; |
|
dewittj
2016/05/26 16:38:43
Since there will only be tests for the impl, this
dougarnett
2016/05/26 20:50:34
Will fix comment. Removing it captured in https://
| |
| 228 | |
| 229 OfflinePageStorageManager* GetStorageManager(); | |
| 230 | |
| 231 bool is_loaded() const; | |
| 232 | |
| 233 protected: | |
| 234 // Adding a protected constructor for testing-only purposes in | |
| 235 // offline_page_storage_manager_unittest.cc | |
| 236 OfflinePageModel(); | |
| 237 | 201 |
| 238 private: | 202 private: |
| 239 FRIEND_TEST_ALL_PREFIXES(OfflinePageModelTest, MarkPageForDeletion); | |
| 240 | |
| 241 typedef ScopedVector<OfflinePageArchiver> PendingArchivers; | |
| 242 | |
| 243 // Callback for ensuring archive directory is created. | |
| 244 void OnEnsureArchivesDirCreatedDone(const base::TimeTicks& start_time); | |
| 245 | |
| 246 void GetAllPagesAfterLoadDone( | |
| 247 const MultipleOfflinePageItemCallback& callback); | |
| 248 void CheckPagesExistOfflineAfterLoadDone( | |
| 249 const std::set<GURL>& urls, | |
| 250 const CheckPagesExistOfflineCallback& callback); | |
| 251 void GetOfflineIdsForClientIdWhenLoadDone( | |
| 252 const ClientId& client_id, | |
| 253 const MultipleOfflineIdCallback& callback) const; | |
| 254 void GetPageByOfflineIdWhenLoadDone( | |
| 255 int64_t offline_id, | |
| 256 const SingleOfflinePageItemCallback& callback) const; | |
| 257 void GetPagesByOnlineURLWhenLoadDone( | |
| 258 const GURL& offline_url, | |
| 259 const MultipleOfflinePageItemCallback& callback) const; | |
| 260 void GetPageByOfflineURLWhenLoadDone( | |
| 261 const GURL& offline_url, | |
| 262 const SingleOfflinePageItemCallback& callback) const; | |
| 263 void GetBestPageForOnlineURLWhenLoadDone( | |
| 264 const GURL& online_url, | |
| 265 const SingleOfflinePageItemCallback& callback) const; | |
| 266 | |
| 267 // Callback for checking whether we have offline pages. | |
| 268 void HasPagesAfterLoadDone(const std::string& name_space, | |
| 269 const HasPagesCallback& callback) const; | |
| 270 | |
| 271 // Callback for loading pages from the offline page metadata store. | |
| 272 void OnLoadDone(const base::TimeTicks& start_time, | |
| 273 OfflinePageMetadataStore::LoadStatus load_status, | |
| 274 const std::vector<OfflinePageItem>& offline_pages); | |
| 275 | |
| 276 // Steps for saving a page offline. | |
| 277 void OnCreateArchiveDone(const GURL& requested_url, | |
| 278 int64_t offline_id, | |
| 279 const ClientId& client_id, | |
| 280 const base::Time& start_time, | |
| 281 const SavePageCallback& callback, | |
| 282 OfflinePageArchiver* archiver, | |
| 283 OfflinePageArchiver::ArchiverResult result, | |
| 284 const GURL& url, | |
| 285 const base::FilePath& file_path, | |
| 286 int64_t file_size); | |
| 287 void OnAddOfflinePageDone(OfflinePageArchiver* archiver, | |
| 288 const SavePageCallback& callback, | |
| 289 const OfflinePageItem& offline_page, | |
| 290 bool success); | |
| 291 void InformSavePageDone(const SavePageCallback& callback, | |
| 292 SavePageResult result, | |
| 293 const ClientId& client_id, | |
| 294 int64_t offline_id); | |
| 295 void DeletePendingArchiver(OfflinePageArchiver* archiver); | |
| 296 | |
| 297 // Steps for deleting files and data for an offline page. | |
| 298 void OnDeleteArchiveFilesDone(const std::vector<int64_t>& offline_ids, | |
| 299 const DeletePageCallback& callback, | |
| 300 bool success); | |
| 301 void OnRemoveOfflinePagesDone(const std::vector<int64_t>& offline_ids, | |
| 302 const DeletePageCallback& callback, | |
| 303 bool success); | |
| 304 void InformDeletePageDone(const DeletePageCallback& callback, | |
| 305 DeletePageResult result); | |
| 306 | |
| 307 void OnMarkPageAccesseDone(const OfflinePageItem& offline_page_item, | |
| 308 bool success); | |
| 309 | |
| 310 // Callbacks for checking if offline pages are missing archive files. | |
| 311 void ScanForMissingArchiveFiles( | |
| 312 const std::set<base::FilePath>& archive_paths); | |
| 313 void OnRemoveOfflinePagesMissingArchiveFileDone( | |
| 314 const std::vector<std::pair<int64_t, ClientId>>& offline_client_id_pairs, | |
| 315 DeletePageResult result); | |
| 316 | |
| 317 // Steps for clearing all. | |
| 318 void OnRemoveAllFilesDoneForClearAll(const base::Closure& callback, | |
| 319 DeletePageResult result); | |
| 320 void OnResetStoreDoneForClearAll(const base::Closure& callback, bool success); | |
| 321 void OnReloadStoreDoneForClearAll( | |
| 322 const base::Closure& callback, | |
| 323 OfflinePageMetadataStore::LoadStatus load_status, | |
| 324 const std::vector<OfflinePageItem>& offline_pages); | |
| 325 | |
| 326 void CacheLoadedData(const std::vector<OfflinePageItem>& offline_pages); | |
| 327 | |
| 328 // Actually does the work of deleting, requires the model is loaded. | |
| 329 void DoDeletePagesByOfflineId(const std::vector<int64_t>& offline_ids, | |
| 330 const DeletePageCallback& callback); | |
| 331 | |
| 332 // Similar to DoDeletePagesByOfflineId, does actual work of deleting, and | |
| 333 // requires that the model is loaded. | |
| 334 void DoDeletePagesByURLPredicate(const UrlPredicate& predicate, | |
| 335 const DeletePageCallback& callback); | |
| 336 | |
| 337 // Callback completing page expiration. | |
| 338 void OnExpirePageDone(int64_t offline_id, | |
| 339 const base::Time& expiration_time, | |
| 340 bool success); | |
| 341 | |
| 342 void RunWhenLoaded(const base::Closure& job); | |
| 343 | |
| 344 // Persistent store for offline page metadata. | |
| 345 std::unique_ptr<OfflinePageMetadataStore> store_; | |
| 346 | |
| 347 // Location where all of the archive files will be stored. | |
| 348 base::FilePath archives_dir_; | |
| 349 | |
| 350 // The observers. | |
| 351 base::ObserverList<Observer> observers_; | |
| 352 | |
| 353 bool is_loaded_; | |
| 354 | |
| 355 // In memory copy of the offline page metadata, keyed by bookmark IDs. | |
| 356 std::map<int64_t, OfflinePageItem> offline_pages_; | |
| 357 | |
| 358 // Pending archivers owned by this model. | |
| 359 PendingArchivers pending_archivers_; | |
| 360 | |
| 361 // Delayed tasks that should be invoked after the loading is done. | |
| 362 std::vector<base::Closure> delayed_tasks_; | |
| 363 | |
| 364 // Controller of the client policies. | |
| 365 std::unique_ptr<ClientPolicyController> policy_controller_; | |
| 366 | |
| 367 // Manager for the storage consumed by archives and responsible for | |
| 368 // automatic page clearing. | |
| 369 std::unique_ptr<OfflinePageStorageManager> storage_manager_; | |
| 370 | |
| 371 // Manager for the offline archive files and directory. | |
| 372 std::unique_ptr<ArchiveManager> archive_manager_; | |
| 373 | |
| 374 base::WeakPtrFactory<OfflinePageModel> weak_ptr_factory_; | |
| 375 | |
| 376 DISALLOW_COPY_AND_ASSIGN(OfflinePageModel); | 203 DISALLOW_COPY_AND_ASSIGN(OfflinePageModel); |
|
Dmitry Titov
2016/05/26 18:27:29
Don't think this is needed for pure abstract inter
dougarnett
2016/05/26 20:50:34
Done.
| |
| 377 }; | 204 }; |
| 378 | 205 |
| 379 } // namespace offline_pages | 206 } // namespace offline_pages |
| 380 | 207 |
| 381 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_H_ | 208 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_H_ |
| OLD | NEW |