Refactor FakeServer::CreateDefaultPermanentItems()
Removing some copy-paste code reuse. It's not that bad
here, but in Opera we have more folders we fake this way
and the copies start looking silly.
BUG=
Review URL: https://codereview.chromium.org/833243007
Cr-Commit-Position: refs/heads/master@{#311066}
diff --git a/sync/test/fake_server/fake_server.cc b/sync/test/fake_server/fake_server.cc
index 74637035..45d03b4f 100644
--- a/sync/test/fake_server/fake_server.cc
+++ b/sync/test/fake_server/fake_server.cc
@@ -161,6 +161,18 @@
STLDeleteContainerPairSecondPointers(entities_.begin(), entities_.end());
}
+bool FakeServer::CreatePermanentBookmarkFolder(const char* server_tag,
+ const char* name) {
+ FakeServerEntity* entity =
+ PermanentEntity::Create(syncer::BOOKMARKS, server_tag, name,
+ ModelTypeToRootTag(syncer::BOOKMARKS));
+ if (entity == NULL)
+ return false;
+
+ SaveEntity(entity);
+ return true;
+}
+
bool FakeServer::CreateDefaultPermanentItems() {
ModelTypeSet all_types = syncer::ProtocolTypes();
for (ModelTypeSet::Iterator it = all_types.First(); it.Good(); it.Inc()) {
@@ -173,25 +185,10 @@
SaveEntity(top_level_entity);
if (model_type == syncer::BOOKMARKS) {
- FakeServerEntity* bookmark_bar_entity =
- PermanentEntity::Create(syncer::BOOKMARKS,
- "bookmark_bar",
- "Bookmark Bar",
- ModelTypeToRootTag(syncer::BOOKMARKS));
- if (bookmark_bar_entity == NULL) {
+ if (!CreatePermanentBookmarkFolder("bookmark_bar", "Bookmark Bar"))
return false;
- }
- SaveEntity(bookmark_bar_entity);
-
- FakeServerEntity* other_bookmarks_entity =
- PermanentEntity::Create(syncer::BOOKMARKS,
- "other_bookmarks",
- "Other Bookmarks",
- ModelTypeToRootTag(syncer::BOOKMARKS));
- if (other_bookmarks_entity == NULL) {
+ if (!CreatePermanentBookmarkFolder("other_bookmarks", "Other Bookmarks"))
return false;
- }
- SaveEntity(other_bookmarks_entity);
}
}
diff --git a/sync/test/fake_server/fake_server.h b/sync/test/fake_server/fake_server.h
index 338ce5a..83b38f5e 100644
--- a/sync/test/fake_server/fake_server.h
+++ b/sync/test/fake_server/fake_server.h
@@ -121,6 +121,8 @@
const std::string& invalidator_client_id,
sync_pb::CommitResponse* response);
+ bool CreatePermanentBookmarkFolder(const char* server_tag, const char* name);
+
// Inserts the default permanent items in |entities_|.
bool CreateDefaultPermanentItems();