blob: ef5ecc70f5fa5756bb978eb4700216d028031991 [file] [log] [blame]
Mohamed Amir Yosefb3f9a662018-06-19 17:04:301// Copyright 2018 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef COMPONENTS_SYNC_BOOKMARKS_BOOKMARK_MODEL_OBSERVER_IMPL_H_
6#define COMPONENTS_SYNC_BOOKMARKS_BOOKMARK_MODEL_OBSERVER_IMPL_H_
7
8#include <set>
Mohamed Amir Yosefc7097a12018-07-02 18:24:169#include <string>
Mohamed Amir Yosefb3f9a662018-06-19 17:04:3010
11#include "base/callback.h"
12#include "components/bookmarks/browser/bookmark_model_observer.h"
Mohamed Amir Yosef90986552018-07-03 15:34:4513#include "components/bookmarks/browser/bookmark_node.h"
Mohamed Amir Yosefb3f9a662018-06-19 17:04:3014#include "url/gurl.h"
15
Mohamed Amir Yosefc7097a12018-07-02 18:24:1616namespace syncer {
17class UniquePosition;
18}
19
Mohamed Amir Yosefb3f9a662018-06-19 17:04:3020namespace sync_bookmarks {
21
22class SyncedBookmarkTracker;
23
24// Class for listening to local changes in the bookmark model and updating
25// metadata in SyncedBookmarkTracker, such that ultimately the processor exposes
26// those local changes to the sync engine.
27class BookmarkModelObserverImpl : public bookmarks::BookmarkModelObserver {
28 public:
29 // |bookmark_tracker_| must not be null and must outlive this object.
30 BookmarkModelObserverImpl(
31 const base::RepeatingClosure& nudge_for_commit_closure,
32 SyncedBookmarkTracker* bookmark_tracker);
33 ~BookmarkModelObserverImpl() override;
34
35 // BookmarkModelObserver:
36 void BookmarkModelLoaded(bookmarks::BookmarkModel* model,
37 bool ids_reassigned) override;
38 void BookmarkModelBeingDeleted(bookmarks::BookmarkModel* model) override;
39 void BookmarkNodeMoved(bookmarks::BookmarkModel* model,
40 const bookmarks::BookmarkNode* old_parent,
41 int old_index,
42 const bookmarks::BookmarkNode* new_parent,
43 int new_index) override;
44 void BookmarkNodeAdded(bookmarks::BookmarkModel* model,
45 const bookmarks::BookmarkNode* parent,
46 int index) override;
Mohamed Amir Yosef3fd347d2018-07-18 13:37:5147 void OnWillRemoveBookmarks(bookmarks::BookmarkModel* model,
48 const bookmarks::BookmarkNode* parent,
49 int old_index,
50 const bookmarks::BookmarkNode* node) override;
Mohamed Amir Yosefb3f9a662018-06-19 17:04:3051 void BookmarkNodeRemoved(bookmarks::BookmarkModel* model,
52 const bookmarks::BookmarkNode* parent,
53 int old_index,
54 const bookmarks::BookmarkNode* node,
55 const std::set<GURL>& removed_urls) override;
56 void BookmarkAllUserNodesRemoved(bookmarks::BookmarkModel* model,
57 const std::set<GURL>& removed_urls) override;
58 void BookmarkNodeChanged(bookmarks::BookmarkModel* model,
59 const bookmarks::BookmarkNode* node) override;
Mohamed Amir Yosef90986552018-07-03 15:34:4560 void BookmarkMetaInfoChanged(bookmarks::BookmarkModel* model,
61 const bookmarks::BookmarkNode* node) override;
Mohamed Amir Yosefb3f9a662018-06-19 17:04:3062 void BookmarkNodeFaviconChanged(bookmarks::BookmarkModel* model,
63 const bookmarks::BookmarkNode* node) override;
64 void BookmarkNodeChildrenReordered(
65 bookmarks::BookmarkModel* model,
66 const bookmarks::BookmarkNode* node) override;
67
68 private:
Mohamed Amir Yosefc7097a12018-07-02 18:24:1669 syncer::UniquePosition ComputePosition(const bookmarks::BookmarkNode& parent,
70 int index,
71 const std::string& sync_id);
72
Mohamed Amir Yosef3fd347d2018-07-18 13:37:5173 // Processes the deletion of a bookmake node and updates the
74 // |bookmark_tracker_| accordingly. If |node| is a bookmark, it gets marked
75 // as deleted and that it requires a commit. If it's a folder, it recurses
76 // over all children before processing the folder itself.
77 void ProcessDelete(const bookmarks::BookmarkNode* parent,
78 const bookmarks::BookmarkNode* node);
79
Mohamed Amir Yosefb3f9a662018-06-19 17:04:3080 // Points to the tracker owned by the processor. It keeps the mapping between
81 // bookmark nodes and corresponding sync server entities.
82 SyncedBookmarkTracker* const bookmark_tracker_;
83
84 // The callback used to inform the sync engine that there are local changes to
85 // be committed.
86 const base::RepeatingClosure nudge_for_commit_closure_;
87
88 DISALLOW_COPY_AND_ASSIGN(BookmarkModelObserverImpl);
89};
90
91} // namespace sync_bookmarks
92
93#endif // COMPONENTS_SYNC_BOOKMARKS_BOOKMARK_MODEL_OBSERVER_IMPL_H_