OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 #include "components/sync/test/fake_server/bookmark_entity.h" | 5 #include "components/sync/test/fake_server/bookmark_entity.h" |
6 | 6 |
7 #include "base/guid.h" | 7 #include "base/guid.h" |
8 | 8 |
9 using std::string; | 9 using std::string; |
10 | 10 |
11 namespace fake_server { | 11 namespace fake_server { |
12 namespace { | 12 namespace { |
13 | 13 |
14 // Returns true if and only if |client_entity| is a bookmark. | 14 // Returns true if and only if |client_entity| is a bookmark. |
15 bool IsBookmark(const sync_pb::SyncEntity& client_entity) { | 15 bool IsBookmark(const sync_pb::SyncEntity& client_entity) { |
16 return syncer::GetModelType(client_entity) == syncer::BOOKMARKS; | 16 return syncer::GetModelType(client_entity) == syncer::BOOKMARKS; |
17 } | 17 } |
18 | 18 |
19 } // namespace | 19 } // namespace |
20 | 20 |
21 BookmarkEntity::~BookmarkEntity() {} | 21 BookmarkEntity::~BookmarkEntity() {} |
22 | 22 |
23 // static | 23 // static |
24 std::unique_ptr<FakeServerEntity> BookmarkEntity::CreateNew( | 24 std::unique_ptr<FakeServerEntity> BookmarkEntity::CreateNew( |
25 const sync_pb::SyncEntity& client_entity, | 25 const sync_pb::SyncEntity& client_entity, |
26 const string& parent_id, | 26 const string& parent_id, |
27 const string& client_guid) { | 27 const string& client_guid) { |
28 CHECK(client_entity.version() == 0) << "New entities must have version = 0."; | 28 CHECK_EQ(0, client_entity.version()) << "New entities must have version = 0."; |
29 CHECK(IsBookmark(client_entity)) << "The given entity must be a bookmark."; | 29 CHECK(IsBookmark(client_entity)) << "The given entity must be a bookmark."; |
30 | 30 |
31 const string id = | 31 const string id = |
32 FakeServerEntity::CreateId(syncer::BOOKMARKS, base::GenerateGUID()); | 32 FakeServerEntity::CreateId(syncer::BOOKMARKS, base::GenerateGUID()); |
33 const string originator_cache_guid = client_guid; | 33 const string originator_cache_guid = client_guid; |
34 const string originator_client_item_id = client_entity.id_string(); | 34 const string originator_client_item_id = client_entity.id_string(); |
35 | 35 |
36 return std::unique_ptr<FakeServerEntity>(new BookmarkEntity( | 36 return std::unique_ptr<FakeServerEntity>(new BookmarkEntity( |
37 id, client_entity.version(), client_entity.name(), originator_cache_guid, | 37 id, client_entity.version(), client_entity.name(), originator_cache_guid, |
38 originator_client_item_id, client_entity.unique_position(), | 38 originator_client_item_id, client_entity.unique_position(), |
39 client_entity.specifics(), client_entity.folder(), parent_id, | 39 client_entity.specifics(), client_entity.folder(), parent_id, |
40 client_entity.ctime(), client_entity.mtime())); | 40 client_entity.ctime(), client_entity.mtime())); |
41 } | 41 } |
42 | 42 |
43 // static | 43 // static |
44 std::unique_ptr<FakeServerEntity> BookmarkEntity::CreateUpdatedVersion( | 44 std::unique_ptr<FakeServerEntity> BookmarkEntity::CreateUpdatedVersion( |
45 const sync_pb::SyncEntity& client_entity, | 45 const sync_pb::SyncEntity& client_entity, |
46 const FakeServerEntity& current_server_entity, | 46 const FakeServerEntity& current_server_entity, |
47 const string& parent_id) { | 47 const string& parent_id) { |
48 CHECK(client_entity.version() != 0) << "Existing entities must not have a " | 48 CHECK_NE(0, client_entity.version()) << "Existing entities must not have a " |
49 << "version = 0."; | 49 << "version = 0."; |
50 CHECK(IsBookmark(client_entity)) << "The given entity must be a bookmark."; | 50 CHECK(IsBookmark(client_entity)) << "The given entity must be a bookmark."; |
51 | 51 |
52 const BookmarkEntity& current_bookmark_entity = | 52 const BookmarkEntity& current_bookmark_entity = |
53 static_cast<const BookmarkEntity&>(current_server_entity); | 53 static_cast<const BookmarkEntity&>(current_server_entity); |
54 const string originator_cache_guid = | 54 const string originator_cache_guid = |
55 current_bookmark_entity.originator_cache_guid_; | 55 current_bookmark_entity.originator_cache_guid_; |
56 const string originator_client_item_id = | 56 const string originator_client_item_id = |
57 current_bookmark_entity.originator_client_item_id_; | 57 current_bookmark_entity.originator_client_item_id_; |
58 | 58 |
59 return std::unique_ptr<FakeServerEntity>(new BookmarkEntity( | 59 return std::unique_ptr<FakeServerEntity>(new BookmarkEntity( |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 | 110 |
111 sync_pb::UniquePosition* unique_position = proto->mutable_unique_position(); | 111 sync_pb::UniquePosition* unique_position = proto->mutable_unique_position(); |
112 unique_position->CopyFrom(unique_position_); | 112 unique_position->CopyFrom(unique_position_); |
113 } | 113 } |
114 | 114 |
115 bool BookmarkEntity::IsFolder() const { | 115 bool BookmarkEntity::IsFolder() const { |
116 return is_folder_; | 116 return is_folder_; |
117 } | 117 } |
118 | 118 |
119 } // namespace fake_server | 119 } // namespace fake_server |
OLD | NEW |