Commit c9340dfb authored by tfarina@chromium.org's avatar tfarina@chromium.org

sync: Make BaseNode::GetTitle() return std::string.

Note: This was a TODO for akalin.

BUG=None
TEST=None

R=akalin@chromium.org

Review URL: http://codereview.chromium.org/7612015

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@96382 0039d316-1c4b-4281-b951-d872f2087c98
parent fa1f56d9
......@@ -181,15 +181,14 @@ static void SyncAPINameToServerName(const std::wstring& sync_api_name,
// server-illegal name followed by one or more spaces, remove the trailing
// space.
static void ServerNameToSyncAPIName(const std::string& server_name,
std::wstring* out) {
std::string* out) {
CHECK(out);
int length_to_copy = server_name.length();
if (IsNameServerIllegalAfterTrimming(server_name) &&
EndsWithSpace(server_name)) {
--length_to_copy;
}
if (!UTF8ToWide(server_name.c_str(), length_to_copy, out)) {
NOTREACHED() << "Could not convert server name from UTF8 to wide";
}
*out = std::string(server_name.c_str(), length_to_copy);
}
// Compare the values of two EntitySpecifics, accounting for encryption.
......@@ -370,8 +369,8 @@ bool BaseNode::GetIsFolder() const {
return GetEntry()->Get(syncable::IS_DIR);
}
std::wstring BaseNode::GetTitle() const {
std::wstring result;
std::string BaseNode::GetTitle() const {
std::string result;
// TODO(zea): refactor bookmarks to not need this functionality.
if (syncable::BOOKMARKS == GetModelType() &&
GetEntry()->Get(syncable::SPECIFICS).has_encrypted()) {
......@@ -379,7 +378,7 @@ std::wstring BaseNode::GetTitle() const {
ServerNameToSyncAPIName(GetBookmarkSpecifics().title(), &result);
} else {
ServerNameToSyncAPIName(GetEntry()->Get(syncable::NON_UNIQUE_NAME),
&result);
&result);
}
return result;
}
......@@ -416,8 +415,7 @@ DictionaryValue* BaseNode::GetSummaryAsValue() const {
DictionaryValue* node_info = new DictionaryValue();
node_info->SetString("id", base::Int64ToString(GetId()));
node_info->SetBoolean("isFolder", GetIsFolder());
// TODO(akalin): Add a std::string accessor for the title.
node_info->SetString("title", WideToUTF8(GetTitle()));
node_info->SetString("title", GetTitle());
node_info->Set("type", ModelTypeToValue(GetModelType()));
return node_info;
}
......
......@@ -205,7 +205,7 @@ class BaseNode {
// Returns the title of the object.
// Uniqueness of the title is not enforced on siblings -- it is not an error
// for two children to share a title.
std::wstring GetTitle() const;
std::string GetTitle() const;
// Returns the model type of this object. The model type is set at node
// creation time and is expected never to change.
......
......@@ -292,7 +292,7 @@ TEST_F(SyncApiTest, ReadMissingTagsFails) {
TEST_F(SyncApiTest, TestDeleteBehavior) {
int64 node_id;
int64 folder_id;
std::wstring test_title(L"test1");
std::string test_title("test1");
{
WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
......@@ -309,7 +309,7 @@ TEST_F(SyncApiTest, TestDeleteBehavior) {
EXPECT_TRUE(wnode.InitUniqueByCreation(syncable::BOOKMARKS,
root_node, "testtag"));
wnode.SetIsFolder(false);
wnode.SetTitle(test_title);
wnode.SetTitle(UTF8ToWide(test_title));
node_id = wnode.GetId();
}
......@@ -351,7 +351,7 @@ TEST_F(SyncApiTest, TestDeleteBehavior) {
EXPECT_EQ(wnode.GetParentId(), folder_node.GetId());
EXPECT_EQ(wnode.GetId(), node_id);
EXPECT_NE(wnode.GetTitle(), test_title); // Title should be cleared
wnode.SetTitle(test_title);
wnode.SetTitle(UTF8ToWide(test_title));
}
// Now look up should work.
......@@ -445,7 +445,7 @@ void CheckNodeValue(const BaseNode& node, const DictionaryValue& value,
EXPECT_TRUE(value.GetBoolean("isFolder", &is_folder));
EXPECT_EQ(node.GetIsFolder(), is_folder);
}
ExpectDictStringValue(WideToUTF8(node.GetTitle()), value, "title");
ExpectDictStringValue(node.GetTitle(), value, "title");
{
ModelType expected_model_type = node.GetModelType();
std::string type_str;
......
......@@ -474,7 +474,7 @@ const BookmarkNode* BookmarkChangeProcessor::CreateOrUpdateBookmarkNode(
if (!src->GetIsFolder())
model->SetURL(dst, src->GetURL());
model->SetTitle(dst, WideToUTF16Hack(src->GetTitle()));
model->SetTitle(dst, UTF8ToUTF16(src->GetTitle()));
SetBookmarkFavicon(src, dst, model);
}
......@@ -496,10 +496,10 @@ const BookmarkNode* BookmarkChangeProcessor::CreateBookmarkNode(
const BookmarkNode* node;
if (sync_node->GetIsFolder()) {
node = model->AddFolder(parent, index,
WideToUTF16Hack(sync_node->GetTitle()));
UTF8ToUTF16(sync_node->GetTitle()));
} else {
node = model->AddURL(parent, index,
WideToUTF16Hack(sync_node->GetTitle()),
UTF8ToUTF16(sync_node->GetTitle()),
sync_node->GetURL());
SetBookmarkFavicon(sync_node, node, model);
}
......
......@@ -103,7 +103,7 @@ const BookmarkNode* BookmarkNodeFinder::FindBookmarkNode(
const sync_api::BaseNode& sync_node) {
// Create a bookmark node from the given sync node.
BookmarkNode temp_node(sync_node.GetURL());
temp_node.set_title(WideToUTF16Hack(sync_node.GetTitle()));
temp_node.set_title(UTF8ToUTF16(sync_node.GetTitle()));
if (sync_node.GetIsFolder())
temp_node.set_type(BookmarkNode::FOLDER);
else
......@@ -280,9 +280,10 @@ bool BookmarkModelAssociator::SyncModelHasUserCreatedNodes(bool* has_nodes) {
return true;
}
bool BookmarkModelAssociator::NodesMatch(const BookmarkNode* bookmark,
bool BookmarkModelAssociator::NodesMatch(
const BookmarkNode* bookmark,
const sync_api::BaseNode* sync_node) const {
if (bookmark->GetTitle() != WideToUTF16Hack(sync_node->GetTitle()))
if (bookmark->GetTitle() != UTF8ToUTF16(sync_node->GetTitle()))
return false;
if (bookmark->is_folder() != sync_node->GetIsFolder())
return false;
......
......@@ -58,12 +58,7 @@ class TestBookmarkModelAssociator : public BookmarkModelAssociator {
// requested. A better way would be to have utility functions to
// create sync nodes from some bookmark structure and to use that.
virtual bool GetSyncIdForTaggedNode(const std::string& tag, int64* sync_id) {
std::wstring tag_wide;
if (!UTF8ToWide(tag.c_str(), tag.length(), &tag_wide)) {
NOTREACHED() << "Unable to convert UTF8 to wide for string: " << tag;
return false;
}
std::string tag_str = std::string(tag.c_str(), tag.length());
bool root_exists = false;
syncable::ModelType type = model_type();
{
......@@ -98,7 +93,7 @@ class TestBookmarkModelAssociator : public BookmarkModelAssociator {
sync_api::ReadNode child(&trans);
child.InitByIdLookup(id);
last_child_id = id;
if (tag_wide == child.GetTitle()) {
if (tag_str == child.GetTitle()) {
*sync_id = id;
return true;
}
......@@ -115,7 +110,7 @@ class TestBookmarkModelAssociator : public BookmarkModelAssociator {
// Create new fake tagged nodes at the end of the ordering.
node.InitByCreation(type, root, predecessor);
node.SetIsFolder(true);
node.SetTitle(tag_wide);
node.SetTitle(UTF8ToWide(tag_str));
node.SetExternalId(0);
*sync_id = node.GetId();
return true;
......@@ -213,10 +208,10 @@ class FakeServerChange {
std::wstring ModifyTitle(int64 id, const std::wstring& new_title) {
sync_api::WriteNode node(trans_);
EXPECT_TRUE(node.InitByIdLookup(id));
std::wstring old_title = node.GetTitle();
std::string old_title = node.GetTitle();
node.SetTitle(new_title);
SetModified(id);
return old_title;
return UTF8ToWide(old_title);
}
// Set a new parent and predecessor value. Return the old parent id.
......@@ -370,7 +365,7 @@ class ProfileSyncServiceBookmarkTest : public TestingBrowserProcessTest {
ASSERT_TRUE(InitSyncNodeFromChromeNode(bnode, &gnode));
// Non-root node titles and parents must match.
if (!model_->is_permanent_node(bnode)) {
EXPECT_EQ(bnode->GetTitle(), WideToUTF16Hack(gnode.GetTitle()));
EXPECT_EQ(bnode->GetTitle(), UTF8ToUTF16(gnode.GetTitle()));
EXPECT_EQ(
model_associator_->GetChromeNodeFromSyncId(gnode.GetParentId()),
bnode->parent());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment