1 // Copyright 2018 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_SYNC_BOOKMARKS_BOOKMARK_SPECIFICS_CONVERSIONS_H_
6 #define COMPONENTS_SYNC_BOOKMARKS_BOOKMARK_SPECIFICS_CONVERSIONS_H_
12 #include "components/sync/protocol/bookmark_specifics.pb.h"
21 } // namespace bookmarks
24 class EntitySpecifics;
26 } // namespace sync_pb
35 } // namespace favicon
37 namespace sync_bookmarks {
39 // Canonicalize |node_title| similar to legacy client's implementation by
40 // truncating and the appending ' ' in some cases.
41 std::string FullTitleToLegacyCanonicalizedTitle(const std::string& node_title);
43 // Used to decide if entity needs to be reuploaded for each remote change.
44 bool IsBookmarkEntityReuploadNeeded(
45 const syncer::EntityData& remote_entity_data);
47 sync_pb::EntitySpecifics CreateSpecificsFromBookmarkNode(
48 const bookmarks::BookmarkNode* node,
49 bookmarks::BookmarkModel* model,
50 const sync_pb::UniquePosition& unique_position,
51 bool force_favicon_load);
53 // Creates a bookmark node under the given parent node from the given specifics.
54 // Returns the newly created node. Callers must verify that
55 // |specifics| passes the IsValidBookmarkSpecifics().
56 const bookmarks::BookmarkNode* CreateBookmarkNodeFromSpecifics(
57 const sync_pb::BookmarkSpecifics& specifics,
58 const bookmarks::BookmarkNode* parent,
60 bookmarks::BookmarkModel* model,
61 favicon::FaviconService* favicon_service);
63 // Updates the bookmark node |node| with the data in |specifics|. Callers must
64 // verify that |specifics| passes the IsValidBookmarkSpecifics().
65 void UpdateBookmarkNodeFromSpecifics(
66 const sync_pb::BookmarkSpecifics& specifics,
67 const bookmarks::BookmarkNode* node,
68 bookmarks::BookmarkModel* model,
69 favicon::FaviconService* favicon_service);
71 // Convnience function that returns BookmarkSpecifics::URL or
72 // BookmarkSpecifics::FOLDER based on whether the input node is a folder. |node|
74 sync_pb::BookmarkSpecifics::Type GetProtoTypeFromBookmarkNode(
75 const bookmarks::BookmarkNode* node);
77 // Replaces |node| with a BookmarkNode of equal properties and original node
78 // creation timestamp but a different GUID, set to |guid|, which must be a
79 // valid version 4 GUID. Intended to be used in cases where the GUID must be
80 // modified despite being immutable within the BookmarkNode itself. Returns
81 // the newly created node, and the original node gets deleted.
82 const bookmarks::BookmarkNode* ReplaceBookmarkNodeGUID(
83 const bookmarks::BookmarkNode* node,
84 const base::GUID& guid,
85 bookmarks::BookmarkModel* model);
87 // Checks if a bookmark specifics represents a valid bookmark. Valid specifics
88 // must not be empty, non-folders must contains a valid url, and all keys in the
89 // meta_info must be unique.
90 bool IsValidBookmarkSpecifics(const sync_pb::BookmarkSpecifics& specifics);
92 // Returns the inferred GUID for given remote update's originator information.
93 base::GUID InferGuidFromLegacyOriginatorId(
94 const std::string& originator_cache_guid,
95 const std::string& originator_client_item_id);
97 // Checks if bookmark specifics contain a GUID that matches the value that would
98 // be inferred from other redundant fields. |specifics| must be valid as per
99 // IsValidBookmarkSpecifics().
100 bool HasExpectedBookmarkGuid(const sync_pb::BookmarkSpecifics& specifics,
101 const syncer::ClientTagHash& client_tag_hash,
102 const std::string& originator_cache_guid,
103 const std::string& originator_client_item_id);
105 } // namespace sync_bookmarks
107 #endif // COMPONENTS_SYNC_BOOKMARKS_BOOKMARK_SPECIFICS_CONVERSIONS_H_