[SyncFS] Build indexes from FileTracker entries on disk.
[chromium-blink-merge.git] / sync / test / fake_server / bookmark_entity.cc
blobae7a3b53ef714c5cd74226f3f0ac7e29d312b004
1 // Copyright 2014 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.
5 #include "sync/test/fake_server/bookmark_entity.h"
7 #include <string>
9 #include "base/basictypes.h"
10 #include "base/guid.h"
11 #include "sync/internal_api/public/base/model_type.h"
12 #include "sync/protocol/sync.pb.h"
13 #include "sync/test/fake_server/fake_server_entity.h"
15 using std::string;
17 namespace fake_server {
19 namespace {
21 // Returns true if and only if |client_entity| is a bookmark.
22 bool IsBookmark(const sync_pb::SyncEntity& client_entity) {
23 return syncer::GetModelType(client_entity) == syncer::BOOKMARKS;
26 } // namespace
28 BookmarkEntity::~BookmarkEntity() { }
30 // static
31 FakeServerEntity* BookmarkEntity::CreateNew(
32 const sync_pb::SyncEntity& client_entity,
33 const string& parent_id,
34 const string& client_guid) {
35 CHECK(client_entity.version() == 0) << "New entities must have version = 0.";
36 CHECK(IsBookmark(client_entity)) << "The given entity must be a bookmark.";
38 string id = FakeServerEntity::CreateId(syncer::BOOKMARKS,
39 base::GenerateGUID());
40 string originator_cache_guid = client_guid;
41 string originator_client_item_id = client_entity.id_string();
43 return new BookmarkEntity(id,
44 client_entity.version(),
45 client_entity.name(),
46 originator_cache_guid,
47 originator_client_item_id,
48 client_entity.unique_position(),
49 client_entity.specifics(),
50 client_entity.folder(),
51 parent_id,
52 client_entity.ctime(),
53 client_entity.mtime());
56 // static
57 FakeServerEntity* BookmarkEntity::CreateUpdatedVersion(
58 const sync_pb::SyncEntity& client_entity,
59 FakeServerEntity* current_server_entity,
60 const string& parent_id) {
61 CHECK(client_entity.version() != 0) << "Existing entities must not have a "
62 << "version = 0.";
63 CHECK(IsBookmark(client_entity)) << "The given entity must be a bookmark.";
65 BookmarkEntity* current_bookmark_entity =
66 static_cast<BookmarkEntity*>(current_server_entity);
67 string originator_cache_guid =
68 current_bookmark_entity->originator_cache_guid_;
69 string originator_client_item_id =
70 current_bookmark_entity->originator_client_item_id_;
72 return new BookmarkEntity(client_entity.id_string(),
73 client_entity.version(),
74 client_entity.name(),
75 originator_cache_guid,
76 originator_client_item_id,
77 client_entity.unique_position(),
78 client_entity.specifics(),
79 client_entity.folder(),
80 parent_id,
81 client_entity.ctime(),
82 client_entity.mtime());
85 BookmarkEntity::BookmarkEntity(
86 const string& id,
87 int64 version,
88 const string& name,
89 const string& originator_cache_guid,
90 const string& originator_client_item_id,
91 const sync_pb::UniquePosition& unique_position,
92 const sync_pb::EntitySpecifics& specifics,
93 bool is_folder,
94 const string& parent_id,
95 int64 creation_time,
96 int64 last_modified_time)
97 : FakeServerEntity(id, syncer::BOOKMARKS, version, name),
98 originator_cache_guid_(originator_cache_guid),
99 originator_client_item_id_(originator_client_item_id),
100 unique_position_(unique_position),
101 specifics_(specifics),
102 is_folder_(is_folder),
103 parent_id_(parent_id),
104 creation_time_(creation_time),
105 last_modified_time_(last_modified_time) { }
107 string BookmarkEntity::GetParentId() const {
108 return parent_id_;
111 sync_pb::SyncEntity* BookmarkEntity::SerializeAsProto() {
112 sync_pb::SyncEntity* sync_entity = new sync_pb::SyncEntity();
113 FakeServerEntity::SerializeBaseProtoFields(sync_entity);
115 sync_pb::EntitySpecifics* specifics = sync_entity->mutable_specifics();
116 specifics->CopyFrom(specifics_);
118 sync_entity->set_originator_cache_guid(originator_cache_guid_);
119 sync_entity->set_originator_client_item_id(originator_client_item_id_);
121 sync_entity->set_parent_id_string(parent_id_);
122 sync_entity->set_ctime(creation_time_);
123 sync_entity->set_mtime(last_modified_time_);
125 sync_pb::UniquePosition* unique_position =
126 sync_entity->mutable_unique_position();
127 unique_position->CopyFrom(unique_position_);
129 return sync_entity;
132 bool BookmarkEntity::IsDeleted() const {
133 return false;
136 bool BookmarkEntity::IsFolder() const {
137 return is_folder_;
140 } // namespace fake_server