Index: chrome/browser/sync/engine/syncapi.cc |
diff --git a/chrome/browser/sync/engine/syncapi.cc b/chrome/browser/sync/engine/syncapi.cc |
index 72491200a05f16da6c28f2d5001f67bc24d34604..5261732a6faa13dfb7cb7d3ac74a19d4cbe9eed7 100644 |
--- a/chrome/browser/sync/engine/syncapi.cc |
+++ b/chrome/browser/sync/engine/syncapi.cc |
@@ -1548,7 +1548,10 @@ class SyncManager::SyncInternal |
void OnIPAddressChangedImpl(); |
// Functions called by ProcessMessage(). |
- browser_sync::JsArgList ProcessGetNodeByIdMessage( |
+ browser_sync::JsArgList ProcessGetNodesByIdMessage( |
+ const browser_sync::JsArgList& args); |
+ |
+ browser_sync::JsArgList ProcessGetChildNodeIdsMessage( |
const browser_sync::JsArgList& args); |
browser_sync::JsArgList ProcessFindNodesContainingString( |
@@ -2712,13 +2715,20 @@ void SyncManager::SyncInternal::ProcessMessage( |
return_args.Append(root.ToValue()); |
parent_router_->RouteJsMessageReply( |
name, browser_sync::JsArgList(&return_args), sender); |
- } else if (name == "getNodeById") { |
+ } else if (name == "getNodesById") { |
+ if (!parent_router_) { |
+ LogNoRouter(name, args); |
+ return; |
+ } |
+ parent_router_->RouteJsMessageReply( |
+ name, ProcessGetNodesByIdMessage(args), sender); |
+ } else if (name == "getChildNodeIds") { |
if (!parent_router_) { |
LogNoRouter(name, args); |
return; |
} |
parent_router_->RouteJsMessageReply( |
- name, ProcessGetNodeByIdMessage(args), sender); |
+ name, ProcessGetChildNodeIdsMessage(args), sender); |
} else if (name == "findNodesContainingString") { |
if (!parent_router_) { |
LogNoRouter(name, args); |
@@ -2751,29 +2761,70 @@ void SyncManager::SyncInternal::RouteJsMessageReply( |
parent_router_->RouteJsMessageReply(name, args, target); |
} |
-browser_sync::JsArgList SyncManager::SyncInternal::ProcessGetNodeByIdMessage( |
- const browser_sync::JsArgList& args) { |
- ListValue null_return_args_list; |
- null_return_args_list.Append(Value::CreateNullValue()); |
- browser_sync::JsArgList null_return_args(&null_return_args_list); |
+namespace { |
+ |
+bool GetId(const ListValue& ids, int i, int64* id) { |
std::string id_str; |
- if (!args.Get().GetString(0, &id_str)) { |
- return null_return_args; |
+ if (!ids.GetString(i, &id_str)) { |
+ return false; |
} |
- int64 id; |
- if (!base::StringToInt64(id_str, &id)) { |
- return null_return_args; |
+ if (!base::StringToInt64(id_str, id)) { |
+ return false; |
} |
- if (id == kInvalidId) { |
- return null_return_args; |
+ if (*id == kInvalidId) { |
+ return false; |
} |
+ return true; |
+} |
+ |
+} // namespace |
+ |
+browser_sync::JsArgList SyncManager::SyncInternal::ProcessGetNodesByIdMessage( |
+ const browser_sync::JsArgList& args) { |
+ ListValue return_args; |
+ ListValue* nodes = new ListValue(); |
+ return_args.Append(nodes); |
+ ListValue* id_list = NULL; |
ReadTransaction trans(GetUserShare()); |
- ReadNode node(&trans); |
- if (!node.InitByIdLookup(id)) { |
- return null_return_args; |
+ if (args.Get().GetList(0, &id_list)) { |
+ for (size_t i = 0; i < id_list->GetSize(); ++i) { |
+ int64 id = kInvalidId; |
+ if (!GetId(*id_list, i, &id)) { |
+ continue; |
+ } |
+ ReadNode node(&trans); |
+ if (!node.InitByIdLookup(id)) { |
+ continue; |
+ } |
+ nodes->Append(node.ToValue()); |
+ } |
} |
+ return browser_sync::JsArgList(&return_args); |
+} |
+ |
+browser_sync::JsArgList SyncManager::SyncInternal:: |
+ ProcessGetChildNodeIdsMessage( |
+ const browser_sync::JsArgList& args) { |
ListValue return_args; |
- return_args.Append(node.ToValue()); |
+ ListValue* child_ids = new ListValue(); |
+ return_args.Append(child_ids); |
+ int64 id = kInvalidId; |
+ if (GetId(args.Get(), 0, &id)) { |
+ ReadTransaction trans(GetUserShare()); |
+ ReadNode node(&trans); |
+ if (node.InitByIdLookup(id)) { |
+ int64 child_id = node.GetFirstChildId(); |
+ while (child_id != kInvalidId) { |
+ ReadNode child_node(&trans); |
+ if (!child_node.InitByIdLookup(child_id)) { |
+ break; |
+ } |
+ child_ids->Append(Value::CreateStringValue( |
+ base::Int64ToString(child_id))); |
+ child_id = child_node.GetSuccessorId(); |
+ } |
+ } |
+ } |
return browser_sync::JsArgList(&return_args); |
} |