Commit fce6ab5a authored by yefim@chromium.org's avatar yefim@chromium.org

Added option to bookmarkManagerPrivate.getMetaInfo() to get meta info from all...

Added option to bookmarkManagerPrivate.getMetaInfo() to get meta info from all bookmarks in a one function call.
Needed to improve stars extension performance.

BUG=383600

Review URL: https://codereview.chromium.org/330983002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@278231 0039d316-1c4b-4281-b951-d872f2087c98
parent 778b44b1
...@@ -666,25 +666,47 @@ bool BookmarkManagerPrivateGetMetaInfoFunction::RunOnReady() { ...@@ -666,25 +666,47 @@ bool BookmarkManagerPrivateGetMetaInfoFunction::RunOnReady() {
scoped_ptr<GetMetaInfo::Params> params(GetMetaInfo::Params::Create(*args_)); scoped_ptr<GetMetaInfo::Params> params(GetMetaInfo::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params); EXTENSION_FUNCTION_VALIDATE(params);
const BookmarkNode* node = GetBookmarkNodeFromId(params->id); if (params->id) {
if (!node) const BookmarkNode* node = GetBookmarkNodeFromId(*params->id);
return false; if (!node)
return false;
if (params->key) { if (params->key) {
std::string value; std::string value;
if (node->GetMetaInfo(*params->key, &value)) { if (node->GetMetaInfo(*params->key, &value)) {
GetMetaInfo::Results::Value result;
result.as_string.reset(new std::string(value));
results_ = GetMetaInfo::Results::Create(result);
}
} else {
GetMetaInfo::Results::Value result; GetMetaInfo::Results::Value result;
result.as_string.reset(new std::string(value)); result.as_object.reset(new GetMetaInfo::Results::Value::Object);
const BookmarkNode::MetaInfoMap* meta_info = node->GetMetaInfoMap();
if (meta_info) {
BookmarkNode::MetaInfoMap::const_iterator itr;
base::DictionaryValue& temp = result.as_object->additional_properties;
for (itr = meta_info->begin(); itr != meta_info->end(); itr++) {
temp.SetStringWithoutPathExpansion(itr->first, itr->second);
}
}
results_ = GetMetaInfo::Results::Create(result); results_ = GetMetaInfo::Results::Create(result);
} }
} else { } else {
if (params->key) {
error_ = bookmark_api_constants::kInvalidParamError;
return true;
}
BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile());
const BookmarkNode* node = model->root_node();
GetMetaInfo::Results::Value result; GetMetaInfo::Results::Value result;
result.as_meta_info_fields.reset( result.as_object.reset(new GetMetaInfo::Results::Value::Object);
new bookmark_manager_private::MetaInfoFields);
bookmark_api_helpers::GetMetaInfo(*node,
&result.as_object->additional_properties);
const BookmarkNode::MetaInfoMap* meta_info = node->GetMetaInfoMap();
if (meta_info)
result.as_meta_info_fields->additional_properties = *meta_info;
results_ = GetMetaInfo::Results::Create(result); results_ = GetMetaInfo::Results::Create(result);
} }
......
...@@ -21,6 +21,7 @@ const char kInvalidUrlError[] = "Invalid URL."; ...@@ -21,6 +21,7 @@ const char kInvalidUrlError[] = "Invalid URL.";
const char kModifySpecialError[] = "Can't modify the root bookmark folders."; const char kModifySpecialError[] = "Can't modify the root bookmark folders.";
const char kEditBookmarksDisabled[] = "Bookmark editing is disabled."; const char kEditBookmarksDisabled[] = "Bookmark editing is disabled.";
const char kModifyManagedError[] = "Can't modify managed bookmarks."; const char kModifyManagedError[] = "Can't modify managed bookmarks.";
const char kInvalidParamError[] = "Parameter 'key' is invalid.";
} // namespace bookmark_api_constants } // namespace bookmark_api_constants
} // namespace extensions } // namespace extensions
...@@ -25,6 +25,7 @@ extern const char kInvalidUrlError[]; ...@@ -25,6 +25,7 @@ extern const char kInvalidUrlError[];
extern const char kModifySpecialError[]; extern const char kModifySpecialError[];
extern const char kEditBookmarksDisabled[]; extern const char kEditBookmarksDisabled[];
extern const char kModifyManagedError[]; extern const char kModifyManagedError[];
extern const char kInvalidParamError[];
} // namespace bookmark_api_constants } // namespace bookmark_api_constants
} // namespace extensions } // namespace extensions
......
...@@ -134,5 +134,27 @@ bool RemoveNode(BookmarkModel* model, ...@@ -134,5 +134,27 @@ bool RemoveNode(BookmarkModel* model,
return true; return true;
} }
void GetMetaInfo(const BookmarkNode& node,
base::DictionaryValue* id_to_meta_info_map) {
if (!node.IsVisible())
return;
const BookmarkNode::MetaInfoMap* meta_info = node.GetMetaInfoMap();
base::DictionaryValue* value = new base::DictionaryValue();
if (meta_info) {
BookmarkNode::MetaInfoMap::const_iterator itr;
for (itr = meta_info->begin(); itr != meta_info->end(); ++itr) {
value->SetStringWithoutPathExpansion(itr->first, itr->second);
}
}
id_to_meta_info_map->Set(base::Int64ToString(node.id()), value);
if (node.is_folder()) {
for (int i = 0; i < node.child_count(); ++i) {
GetMetaInfo(*(node.GetChild(i)), id_to_meta_info_map);
}
}
}
} // namespace bookmark_api_helpers } // namespace bookmark_api_helpers
} // namespace extensions } // namespace extensions
...@@ -44,6 +44,10 @@ bool RemoveNode(BookmarkModel* model, ...@@ -44,6 +44,10 @@ bool RemoveNode(BookmarkModel* model,
bool recursive, bool recursive,
std::string* error); std::string* error);
// Get meta info from |node| and all it's children recursively.
void GetMetaInfo(const BookmarkNode& node,
base::DictionaryValue* id_to_meta_info_map);
} // namespace bookmark_api_helpers } // namespace bookmark_api_helpers
} // namespace extensions } // namespace extensions
......
...@@ -269,10 +269,12 @@ ...@@ -269,10 +269,12 @@
"name": "getMetaInfo", "name": "getMetaInfo",
"type": "function", "type": "function",
"description": "Gets meta info from a bookmark node", "description": "Gets meta info from a bookmark node",
"allowAmbiguousOptionalArguments": true,
"parameters": [ "parameters": [
{ {
"name": "id", "name": "id",
"description": "The id of the bookmark to retrieve meta info from", "description": "The id of the bookmark to retrieve meta info from. If omitted meta info for all nodes is returned.",
"optional": true,
"type": "string" "type": "string"
}, },
{ {
...@@ -287,13 +289,11 @@ ...@@ -287,13 +289,11 @@
"parameters": [ "parameters": [
{ {
"name": "value", "name": "value",
"description": "If a key was given, the value of the specified field, if present. Otherwise an object containing all meta info fields for the node.", "description": "If a key was given, the value of the specified field, if present. Otherwise an object containing all meta info fields for the node. If id is not given then meta info for all nodes as an object with node id to meta info.",
"optional": true, "optional": true,
// TODO(rfevang): Convert this to always return MetaInfoFields
// if the API is made public.
"choices": [ "choices": [
{"type": "string"}, {"type": "string"},
{"$ref": "MetaInfoFields"} {"type": "object", "additionalProperties": {"type": "any"}}
] ]
} }
] ]
......
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