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

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

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