Upload upstream chromium 108.0.5359.1
[platform/framework/web/chromium-efl.git] / components / sync_bookmarks / bookmark_specifics_conversions.h
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.
4
5 #ifndef COMPONENTS_SYNC_BOOKMARKS_BOOKMARK_SPECIFICS_CONVERSIONS_H_
6 #define COMPONENTS_SYNC_BOOKMARKS_BOOKMARK_SPECIFICS_CONVERSIONS_H_
7
8 #include <stddef.h>
9
10 #include <string>
11
12 #include "components/sync/protocol/bookmark_specifics.pb.h"
13
14 namespace base {
15 class GUID;
16 }  // namespace base
17
18 namespace bookmarks {
19 class BookmarkModel;
20 class BookmarkNode;
21 }  // namespace bookmarks
22
23 namespace sync_pb {
24 class EntitySpecifics;
25 class UniquePosition;
26 }  // namespace sync_pb
27
28 namespace syncer {
29 class ClientTagHash;
30 struct EntityData;
31 }  // namespace syncer
32
33 namespace favicon {
34 class FaviconService;
35 }  // namespace favicon
36
37 namespace sync_bookmarks {
38
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);
42
43 // Used to decide if entity needs to be reuploaded for each remote change.
44 bool IsBookmarkEntityReuploadNeeded(
45     const syncer::EntityData& remote_entity_data);
46
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);
52
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,
59     size_t index,
60     bookmarks::BookmarkModel* model,
61     favicon::FaviconService* favicon_service);
62
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);
70
71 // Convnience function that returns BookmarkSpecifics::URL or
72 // BookmarkSpecifics::FOLDER based on whether the input node is a folder. |node|
73 // must not be null.
74 sync_pb::BookmarkSpecifics::Type GetProtoTypeFromBookmarkNode(
75     const bookmarks::BookmarkNode* node);
76
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);
86
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);
91
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);
96
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);
104
105 }  // namespace sync_bookmarks
106
107 #endif  // COMPONENTS_SYNC_BOOKMARKS_BOOKMARK_SPECIFICS_CONVERSIONS_H_