Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(278)

Side by Side Diff: components/offline_pages/offline_page_model.h

Issue 1968563003: [Offline pages] Extracting callbacks from the Offline Page Model (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adding a missing fix to gypi file Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/offline_pages/BUILD.gn ('k') | components/offline_pages/offline_page_model.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_types.h"
28 29
29 class GURL; 30 class GURL;
30 namespace base { 31 namespace base {
31 class SequencedTaskRunner; 32 class SequencedTaskRunner;
32 class Time; 33 class Time;
33 class TimeDelta; 34 class TimeDelta;
34 class TimeTicks; 35 class TimeTicks;
35 } 36 }
36 37
37 namespace offline_pages { 38 namespace offline_pages {
(...skipping 20 matching lines...) Expand all
58 // 59 //
59 // // In code using the OfflinePagesModel to save a page: 60 // // In code using the OfflinePagesModel to save a page:
60 // std::unique_ptr<ArchiverImpl> archiver(new ArchiverImpl()); 61 // std::unique_ptr<ArchiverImpl> archiver(new ArchiverImpl());
61 // // Callback is of type SavePageCallback. 62 // // Callback is of type SavePageCallback.
62 // model->SavePage(url, std::move(archiver), callback); 63 // model->SavePage(url, std::move(archiver), callback);
63 // 64 //
64 // TODO(fgorski): Things to describe: 65 // TODO(fgorski): Things to describe:
65 // * how to cancel requests and what to expect 66 // * how to cancel requests and what to expect
66 class OfflinePageModel : public KeyedService, public base::SupportsUserData { 67 class OfflinePageModel : public KeyedService, public base::SupportsUserData {
67 public: 68 public:
68 // Result of saving a page offline.
69 // A Java counterpart will be generated for this enum.
70 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.components.offlinepages
71 enum class SavePageResult {
72 SUCCESS,
73 CANCELLED,
74 DEVICE_FULL,
75 CONTENT_UNAVAILABLE,
76 ARCHIVE_CREATION_FAILED,
77 STORE_FAILURE,
78 ALREADY_EXISTS,
79 // Certain pages, i.e. file URL or NTP, will not be saved because these
80 // are already locally accessible.
81 SKIPPED,
82 SECURITY_CERTIFICATE_ERROR,
83 // NOTE: always keep this entry at the end. Add new result types only
84 // immediately above this line. Make sure to update the corresponding
85 // histogram enum accordingly.
86 RESULT_COUNT,
87 };
88
89 // Result of deleting an offline page.
90 // A Java counterpart will be generated for this enum.
91 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.components.offlinepages
92 enum class DeletePageResult {
93 SUCCESS,
94 CANCELLED,
95 STORE_FAILURE,
96 DEVICE_FAILURE,
97 NOT_FOUND,
98 // NOTE: always keep this entry at the end. Add new result types only
99 // immediately above this line. Make sure to update the corresponding
100 // histogram enum accordingly.
101 RESULT_COUNT,
102 };
103
104 // Result of loading all pages.
105 enum class LoadResult {
106 SUCCESS,
107 CANCELLED,
108 STORE_FAILURE,
109 };
110
111 // Observer of the OfflinePageModel. 69 // Observer of the OfflinePageModel.
112 class Observer { 70 class Observer {
113 public: 71 public:
114 // Invoked when the model has finished loading. 72 // Invoked when the model has finished loading.
115 virtual void OfflinePageModelLoaded(OfflinePageModel* model) = 0; 73 virtual void OfflinePageModelLoaded(OfflinePageModel* model) = 0;
116 74
117 // 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
118 // updating an offline page. 76 // updating an offline page.
119 virtual void OfflinePageModelChanged(OfflinePageModel* model) = 0; 77 virtual void OfflinePageModelChanged(OfflinePageModel* model) = 0;
120 78
121 // Invoked when an offline copy related to |offline_id| was deleted. 79 // Invoked when an offline copy related to |offline_id| was deleted.
122 // In can be invoked as a result of |CheckForExternalFileDeletion|, if a 80 // In can be invoked as a result of |CheckForExternalFileDeletion|, if a
123 // deleted page is detected. 81 // deleted page is detected.
124 virtual void OfflinePageDeleted(int64_t offline_id, 82 virtual void OfflinePageDeleted(int64_t offline_id,
125 const ClientId& client_id) = 0; 83 const ClientId& client_id) = 0;
126 84
127 protected: 85 protected:
128 virtual ~Observer() {} 86 virtual ~Observer() {}
129 }; 87 };
130 88
131 typedef std::set<GURL> CheckPagesExistOfflineResult; 89 using CheckPagesExistOfflineResult =
132 typedef std::vector<int64_t> MultipleOfflineIdResult; 90 offline_pages::CheckPagesExistOfflineResult;
133 typedef base::Optional<OfflinePageItem> SingleOfflinePageItemResult; 91 using MultipleOfflinePageItemResult =
134 typedef std::vector<OfflinePageItem> MultipleOfflinePageItemResult; 92 offline_pages::MultipleOfflinePageItemResult;
135 93
136 typedef base::Callback<void(SavePageResult, int64_t)> SavePageCallback; 94 //using DeletePageCallback = offline_pages::DeletePageCallback;
137 typedef base::Callback<void(DeletePageResult)> DeletePageCallback; 95 using DeletePageResult = offline_pages::DeletePageResult;
138 typedef base::Callback<void(const CheckPagesExistOfflineResult&)> 96 using SavePageResult = offline_pages::SavePageResult;
139 CheckPagesExistOfflineCallback;
140 typedef base::Callback<void(bool)> HasPagesCallback;
141 typedef base::Callback<void(const MultipleOfflineIdResult&)>
142 MultipleOfflineIdCallback;
143 typedef base::Callback<void(const SingleOfflinePageItemResult&)>
144 SingleOfflinePageItemCallback;
145 typedef base::Callback<void(const MultipleOfflinePageItemResult&)>
146 MultipleOfflinePageItemCallback;
147 97
148 // Generates a new offline id 98 // Generates a new offline id
149 static int64_t GenerateOfflineId(); 99 static int64_t GenerateOfflineId();
150 100
151 // Returns true if an offline copy can be saved for the given URL. 101 // Returns true if an offline copy can be saved for the given URL.
152 static bool CanSavePage(const GURL& url); 102 static bool CanSavePage(const GURL& url);
153 103
154 static base::TimeDelta GetFinalDeletionDelayForTesting(); 104 static base::TimeDelta GetFinalDeletionDelayForTesting();
155 105
156 // All blocking calls/disk access will happen on the provided |task_runner|. 106 // All blocking calls/disk access will happen on the provided |task_runner|.
(...skipping 23 matching lines...) Expand all
180 130
181 // Deletes offline pages related to the passed |offline_ids|. 131 // Deletes offline pages related to the passed |offline_ids|.
182 // Making virtual for test purposes. 132 // Making virtual for test purposes.
183 virtual void DeletePagesByOfflineId(const std::vector<int64_t>& offline_ids, 133 virtual void DeletePagesByOfflineId(const std::vector<int64_t>& offline_ids,
184 const DeletePageCallback& callback); 134 const DeletePageCallback& callback);
185 135
186 // Wipes out all the data by deleting all saved files and clearing the store. 136 // Wipes out all the data by deleting all saved files and clearing the store.
187 void ClearAll(const base::Closure& callback); 137 void ClearAll(const base::Closure& callback);
188 138
189 // Deletes offline pages matching the URL predicate. 139 // Deletes offline pages matching the URL predicate.
190 void DeletePagesByURLPredicate( 140 void DeletePagesByURLPredicate(const UrlPredicate& predicate,
191 const base::Callback<bool(const GURL&)>& predicate, 141 const DeletePageCallback& callback);
192 const DeletePageCallback& callback);
193 142
194 // Returns true via callback if there are offline pages in the given 143 // Returns true via callback if there are offline pages in the given
195 // |name_space|. 144 // |name_space|.
196 void HasPages(const std::string& name_space, 145 void HasPages(const std::string& name_space,
197 const HasPagesCallback& callback); 146 const HasPagesCallback& callback);
198 147
199 // Returns via callback all GURLs in |urls| that are equal to the online URL 148 // Returns via callback all GURLs in |urls| that are equal to the online URL
200 // of any offline page. 149 // of any offline page.
201 void CheckPagesExistOffline(const std::set<GURL>& urls, 150 void CheckPagesExistOffline(const std::set<GURL>& urls,
202 const CheckPagesExistOfflineCallback& callback); 151 const CheckPagesExistOfflineCallback& callback);
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 DeletePageResult result); 295 DeletePageResult result);
347 296
348 void OnMarkPageAccesseDone(const OfflinePageItem& offline_page_item, 297 void OnMarkPageAccesseDone(const OfflinePageItem& offline_page_item,
349 bool success); 298 bool success);
350 299
351 // Callbacks for checking if offline pages are missing archive files. 300 // Callbacks for checking if offline pages are missing archive files.
352 void OnFindPagesMissingArchiveFile( 301 void OnFindPagesMissingArchiveFile(
353 const std::vector<int64_t>* ids_of_pages_missing_archive_file); 302 const std::vector<int64_t>* ids_of_pages_missing_archive_file);
354 void OnRemoveOfflinePagesMissingArchiveFileDone( 303 void OnRemoveOfflinePagesMissingArchiveFileDone(
355 const std::vector<std::pair<int64_t, ClientId>>& offline_client_id_pairs, 304 const std::vector<std::pair<int64_t, ClientId>>& offline_client_id_pairs,
356 OfflinePageModel::DeletePageResult result); 305 DeletePageResult result);
357 306
358 // Steps for clearing all. 307 // Steps for clearing all.
359 void OnRemoveAllFilesDoneForClearAll(const base::Closure& callback, 308 void OnRemoveAllFilesDoneForClearAll(const base::Closure& callback,
360 DeletePageResult result); 309 DeletePageResult result);
361 void OnResetStoreDoneForClearAll(const base::Closure& callback, bool success); 310 void OnResetStoreDoneForClearAll(const base::Closure& callback, bool success);
362 void OnReloadStoreDoneForClearAll( 311 void OnReloadStoreDoneForClearAll(
363 const base::Closure& callback, 312 const base::Closure& callback,
364 OfflinePageMetadataStore::LoadStatus load_status, 313 OfflinePageMetadataStore::LoadStatus load_status,
365 const std::vector<OfflinePageItem>& offline_pages); 314 const std::vector<OfflinePageItem>& offline_pages);
366 315
367 void CacheLoadedData(const std::vector<OfflinePageItem>& offline_pages); 316 void CacheLoadedData(const std::vector<OfflinePageItem>& offline_pages);
368 317
369 // Actually does the work of deleting, requires the model is loaded. 318 // Actually does the work of deleting, requires the model is loaded.
370 void DoDeletePagesByOfflineId(const std::vector<int64_t>& offline_ids, 319 void DoDeletePagesByOfflineId(const std::vector<int64_t>& offline_ids,
371 const DeletePageCallback& callback); 320 const DeletePageCallback& callback);
372 321
373 // Similar to DoDeletePagesByOfflineId, does actual work of deleting, and 322 // Similar to DoDeletePagesByOfflineId, does actual work of deleting, and
374 // requires that the model is loaded. 323 // requires that the model is loaded.
375 void DoDeletePagesByURLPredicate( 324 void DoDeletePagesByURLPredicate(const UrlPredicate& predicate,
376 const base::Callback<bool(const GURL&)>& predicate, 325 const DeletePageCallback& callback);
377 const DeletePageCallback& callback);
378 326
379 void RunWhenLoaded(const base::Closure& job); 327 void RunWhenLoaded(const base::Closure& job);
380 328
381 // Persistent store for offline page metadata. 329 // Persistent store for offline page metadata.
382 std::unique_ptr<OfflinePageMetadataStore> store_; 330 std::unique_ptr<OfflinePageMetadataStore> store_;
383 331
384 // Location where all of the archive files will be stored. 332 // Location where all of the archive files will be stored.
385 base::FilePath archives_dir_; 333 base::FilePath archives_dir_;
386 334
387 // The observers. 335 // The observers.
(...skipping 20 matching lines...) Expand all
408 std::unique_ptr<OfflinePageStorageManager> storage_manager_; 356 std::unique_ptr<OfflinePageStorageManager> storage_manager_;
409 357
410 base::WeakPtrFactory<OfflinePageModel> weak_ptr_factory_; 358 base::WeakPtrFactory<OfflinePageModel> weak_ptr_factory_;
411 359
412 DISALLOW_COPY_AND_ASSIGN(OfflinePageModel); 360 DISALLOW_COPY_AND_ASSIGN(OfflinePageModel);
413 }; 361 };
414 362
415 } // namespace offline_pages 363 } // namespace offline_pages
416 364
417 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_H_ 365 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_H_
OLDNEW
« no previous file with comments | « components/offline_pages/BUILD.gn ('k') | components/offline_pages/offline_page_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698