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

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

Issue 2185973003: [Offline Pages] Delete associated page along with bookmark. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moving to c++. Created 4 years, 4 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_IMPL_H_ 5 #ifndef COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_IMPL_H_
6 #define COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_IMPL_H_ 6 #define COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_IMPL_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 <string> 13 #include <string>
14 #include <utility> 14 #include <utility>
15 #include <vector> 15 #include <vector>
16 16
17 #include "base/callback.h" 17 #include "base/callback.h"
18 #include "base/files/file_path.h" 18 #include "base/files/file_path.h"
19 #include "base/gtest_prod_util.h" 19 #include "base/gtest_prod_util.h"
20 #include "base/macros.h" 20 #include "base/macros.h"
21 #include "base/memory/ref_counted.h" 21 #include "base/memory/ref_counted.h"
22 #include "base/memory/scoped_vector.h" 22 #include "base/memory/scoped_vector.h"
23 #include "base/memory/weak_ptr.h" 23 #include "base/memory/weak_ptr.h"
24 #include "base/observer_list.h" 24 #include "base/observer_list.h"
25 #include "base/optional.h" 25 #include "base/optional.h"
26 #include "components/bookmarks/browser/bookmark_model.h"
27 #include "components/bookmarks/browser/bookmark_model_observer.h"
26 #include "components/keyed_service/core/keyed_service.h" 28 #include "components/keyed_service/core/keyed_service.h"
27 #include "components/offline_pages/offline_page_archiver.h" 29 #include "components/offline_pages/offline_page_archiver.h"
28 #include "components/offline_pages/offline_page_metadata_store.h" 30 #include "components/offline_pages/offline_page_metadata_store.h"
29 #include "components/offline_pages/offline_page_model.h" 31 #include "components/offline_pages/offline_page_model.h"
30 #include "components/offline_pages/offline_page_model_event_logger.h" 32 #include "components/offline_pages/offline_page_model_event_logger.h"
31 #include "components/offline_pages/offline_page_storage_manager.h" 33 #include "components/offline_pages/offline_page_storage_manager.h"
32 #include "components/offline_pages/offline_page_types.h" 34 #include "components/offline_pages/offline_page_types.h"
33 35
34 class GURL; 36 class GURL;
35 namespace base { 37 namespace base {
36 class SequencedTaskRunner; 38 class SequencedTaskRunner;
37 class Time; 39 class Time;
38 class TimeDelta; 40 class TimeDelta;
39 class TimeTicks; 41 class TimeTicks;
40 } // namespace base 42 } // namespace base
41 43
44 namespace bookmarks {
45 class BookmarkNode;
46 }
47
42 namespace offline_pages { 48 namespace offline_pages {
43 49
44 static const int64_t kInvalidOfflineId = 0; 50 static const int64_t kInvalidOfflineId = 0;
45 51
46 struct ClientId; 52 struct ClientId;
47 struct OfflinePageItem; 53 struct OfflinePageItem;
48 54
49 class ArchiveManager; 55 class ArchiveManager;
50 class ClientPolicyController; 56 class ClientPolicyController;
51 class OfflinePageMetadataStore; 57 class OfflinePageMetadataStore;
52 class OfflinePageStorageManager; 58 class OfflinePageStorageManager;
53 59
54 // Implementation of service for saving pages offline, storing the offline 60 // Implementation of service for saving pages offline, storing the offline
55 // copy and metadata, and retrieving them upon request. 61 // copy and metadata, and retrieving them upon request.
56 class OfflinePageModelImpl : public OfflinePageModel, public KeyedService { 62 class OfflinePageModelImpl : public OfflinePageModel,
63 public KeyedService,
64 public bookmarks::BookmarkModelObserver {
Dmitry Titov 2016/08/01 23:46:58 If you use BaseBookmarkModelObserver as base class
57 public: 65 public:
58 // All blocking calls/disk access will happen on the provided |task_runner|. 66 // All blocking calls/disk access will happen on the provided |task_runner|.
59 OfflinePageModelImpl( 67 OfflinePageModelImpl(
60 std::unique_ptr<OfflinePageMetadataStore> store, 68 std::unique_ptr<OfflinePageMetadataStore> store,
61 const base::FilePath& archives_dir, 69 const base::FilePath& archives_dir,
62 const scoped_refptr<base::SequencedTaskRunner>& task_runner); 70 const scoped_refptr<base::SequencedTaskRunner>& task_runner);
63 ~OfflinePageModelImpl() override; 71 ~OfflinePageModelImpl() override;
64 72
73 // Implemented bookmarks::bookmarks::bookmarks::BookmarkModelObserver:
74 void BookmarkModelLoaded(bookmarks::BookmarkModel* model,
75 bool ids_reassigned) override {}
76 void BookmarkNodeMoved(bookmarks::BookmarkModel* model,
77 const bookmarks::BookmarkNode* old_parent,
78 int old_index,
79 const bookmarks::BookmarkNode* new_parent,
80 int new_index) override {}
81 void BookmarkNodeAdded(bookmarks::BookmarkModel* model,
82 const bookmarks::BookmarkNode* parent,
83 int index) override {}
84 void BookmarkNodeRemoved(bookmarks::BookmarkModel* model,
85 const bookmarks::BookmarkNode* parent,
86 int old_index,
87 const bookmarks::BookmarkNode* node,
88 const std::set<GURL>& no_longer_bookmarked) override;
89 void BookmarkNodeChanged(bookmarks::BookmarkModel* model,
90 const bookmarks::BookmarkNode* node) override {}
91 void BookmarkNodeFaviconChanged(
92 bookmarks::BookmarkModel* model,
93 const bookmarks::BookmarkNode* node) override {}
94 void BookmarkNodeChildrenReordered(
95 bookmarks::BookmarkModel* model,
96 const bookmarks::BookmarkNode* node) override {}
97 void BookmarkAllUserNodesRemoved(
98 bookmarks::BookmarkModel* model,
99 const std::set<GURL>& removed_urls) override {}
100
65 // Implemented methods: 101 // Implemented methods:
66 void AddObserver(Observer* observer) override; 102 void AddObserver(Observer* observer) override;
67 void RemoveObserver(Observer* observer) override; 103 void RemoveObserver(Observer* observer) override;
68 void SavePage(const GURL& url, 104 void SavePage(const GURL& url,
69 const ClientId& client_id, 105 const ClientId& client_id,
70 std::unique_ptr<OfflinePageArchiver> archiver, 106 std::unique_ptr<OfflinePageArchiver> archiver,
71 const SavePageCallback& callback) override; 107 const SavePageCallback& callback) override;
72 void MarkPageAccessed(int64_t offline_id) override; 108 void MarkPageAccessed(int64_t offline_id) override;
73 void ClearAll(const base::Closure& callback) override; 109 void ClearAll(const base::Closure& callback) override;
74 void DeletePagesByOfflineId(const std::vector<int64_t>& offline_ids, 110 void DeletePagesByOfflineId(const std::vector<int64_t>& offline_ids,
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 void ClearStorageIfNeeded( 293 void ClearStorageIfNeeded(
258 const OfflinePageStorageManager::ClearStorageCallback& callback); 294 const OfflinePageStorageManager::ClearStorageCallback& callback);
259 295
260 // Callback completing storage clearing. 296 // Callback completing storage clearing.
261 void OnStorageCleared(size_t expired_page_count, 297 void OnStorageCleared(size_t expired_page_count,
262 OfflinePageStorageManager::ClearStorageResult result); 298 OfflinePageStorageManager::ClearStorageResult result);
263 299
264 // Post task to clear storage. 300 // Post task to clear storage.
265 void PostClearStorageIfNeededTask(); 301 void PostClearStorageIfNeededTask();
266 302
303 // Expire associate pages when a bookmark gets deleted.
304 void ExpireRemovedBookmarkPages(const std::vector<int64_t>& offline_ids);
305 void OnRemovedBookmarkPagesExpired(bool result);
306
267 void RunWhenLoaded(const base::Closure& job); 307 void RunWhenLoaded(const base::Closure& job);
268 308
269 // Persistent store for offline page metadata. 309 // Persistent store for offline page metadata.
270 std::unique_ptr<OfflinePageMetadataStore> store_; 310 std::unique_ptr<OfflinePageMetadataStore> store_;
271 311
272 // Location where all of the archive files will be stored. 312 // Location where all of the archive files will be stored.
273 base::FilePath archives_dir_; 313 base::FilePath archives_dir_;
274 314
275 // The observers. 315 // The observers.
276 base::ObserverList<Observer> observers_; 316 base::ObserverList<Observer> observers_;
(...skipping 23 matching lines...) Expand all
300 OfflinePageModelEventLogger offline_event_logger_; 340 OfflinePageModelEventLogger offline_event_logger_;
301 341
302 base::WeakPtrFactory<OfflinePageModelImpl> weak_ptr_factory_; 342 base::WeakPtrFactory<OfflinePageModelImpl> weak_ptr_factory_;
303 343
304 DISALLOW_COPY_AND_ASSIGN(OfflinePageModelImpl); 344 DISALLOW_COPY_AND_ASSIGN(OfflinePageModelImpl);
305 }; 345 };
306 346
307 } // namespace offline_pages 347 } // namespace offline_pages
308 348
309 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_IMPL_H_ 349 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698