diff options
author | rfevang@chromium.org <rfevang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-05 23:13:07 +0000 |
---|---|---|
committer | rfevang@chromium.org <rfevang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-05 23:13:07 +0000 |
commit | 8e698d374fac20ca24ceac872aeb6452134574ea (patch) | |
tree | 06990a75d2ffa086ec01c519cb7294181d638a17 /chrome/browser/extensions | |
parent | 143238b55c365d429caab8e9395ba416ef23522d (diff) | |
download | chromium_src-8e698d374fac20ca24ceac872aeb6452134574ea.zip chromium_src-8e698d374fac20ca24ceac872aeb6452134574ea.tar.gz chromium_src-8e698d374fac20ca24ceac872aeb6452134574ea.tar.bz2 |
Add Get/SetMetaInfo methods to BookmarkManagerPrivate Api
Adds access to the meta info bookmark field in order to fascilitate
experimenting with the bookmark manager.
BUG=312488
Review URL: https://codereview.chromium.org/54213005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@233126 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions')
5 files changed, 97 insertions, 73 deletions
diff --git a/chrome/browser/extensions/api/bookmark_manager_private/bookmark_manager_private_api.cc b/chrome/browser/extensions/api/bookmark_manager_private/bookmark_manager_private_api.cc index 81eae5d..0493a56 100644 --- a/chrome/browser/extensions/api/bookmark_manager_private/bookmark_manager_private_api.cc +++ b/chrome/browser/extensions/api/bookmark_manager_private/bookmark_manager_private_api.cc @@ -6,7 +6,6 @@ #include <vector> -#include "base/json/json_writer.h" #include "base/prefs/pref_service.h" #include "base/strings/string_number_conversions.h" #include "base/values.h" @@ -50,8 +49,10 @@ namespace Cut = api::bookmark_manager_private::Cut; namespace Drop = api::bookmark_manager_private::Drop; namespace GetSubtree = api::bookmark_manager_private::GetSubtree; namespace manager_keys = bookmark_manager_api_constants; +namespace GetMetaInfo = api::bookmark_manager_private::GetMetaInfo; namespace Paste = api::bookmark_manager_private::Paste; namespace RemoveTrees = api::bookmark_manager_private::RemoveTrees; +namespace SetMetaInfo = api::bookmark_manager_private::SetMetaInfo; namespace SortChildren = api::bookmark_manager_private::SortChildren; namespace StartDrag = api::bookmark_manager_private::StartDrag; @@ -485,23 +486,15 @@ bool BookmarkManagerPrivateGetSubtreeFunction::RunImpl() { scoped_ptr<GetSubtree::Params> params(GetSubtree::Params::Create(*args_)); EXTENSION_FUNCTION_VALIDATE(params); - BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile()); const BookmarkNode* node = NULL; if (params->id == "") { + BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile()); node = model->root_node(); } else { - int64 id; - if (!base::StringToInt64(params->id, &id)) { - error_ = bookmark_keys::kInvalidIdError; + node = GetBookmarkNodeFromId(params->id); + if (!node) return false; - } - node = model->GetNodeByID(id); - } - - if (!node) { - error_ = bookmark_keys::kNoNodeError; - return false; } scoped_ptr<base::ListValue> json(new base::ListValue()); @@ -525,6 +518,33 @@ bool BookmarkManagerPrivateRecordLaunchFunction::RunImpl() { return true; } +bool BookmarkManagerPrivateGetMetaInfoFunction::RunImpl() { + scoped_ptr<GetMetaInfo::Params> params(GetMetaInfo::Params::Create(*args_)); + EXTENSION_FUNCTION_VALIDATE(params); + + const BookmarkNode* node = GetBookmarkNodeFromId(params->id); + if (!node) + return false; + + std::string value; + if (node->GetMetaInfo(params->key, &value)) + results_ = GetMetaInfo::Results::Create(value); + return true; +} + +bool BookmarkManagerPrivateSetMetaInfoFunction::RunImpl() { + scoped_ptr<SetMetaInfo::Params> params(SetMetaInfo::Params::Create(*args_)); + EXTENSION_FUNCTION_VALIDATE(params); + + const BookmarkNode* node = GetBookmarkNodeFromId(params->id); + if (!node) + return false; + + BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile()); + model->SetNodeMetaInfo(node, params->key, params->value); + return true; +} + bool BookmarkManagerPrivateCanOpenNewWindowsFunction::RunImpl() { bool can_open_new_windows = true; @@ -544,10 +564,8 @@ bool BookmarkManagerPrivateRemoveTreesFunction::RunImpl() { BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile()); int64 id; for (size_t i = 0; i < params->id_list.size(); ++i) { - if (!base::StringToInt64(params->id_list[i], &id)) { - error_ = bookmark_api_constants::kInvalidIdError; + if (!GetBookmarkIdAsInt64(params->id_list[i], &id)) return false; - } if (!bookmark_api_helpers::RemoveNode(model, id, true, &error_)) return false; } diff --git a/chrome/browser/extensions/api/bookmark_manager_private/bookmark_manager_private_api.h b/chrome/browser/extensions/api/bookmark_manager_private/bookmark_manager_private_api.h index fef3468..dca72e8 100644 --- a/chrome/browser/extensions/api/bookmark_manager_private/bookmark_manager_private_api.h +++ b/chrome/browser/extensions/api/bookmark_manager_private/bookmark_manager_private_api.h @@ -205,6 +205,32 @@ class BookmarkManagerPrivateRecordLaunchFunction virtual bool RunImpl() OVERRIDE; }; +class BookmarkManagerPrivateGetMetaInfoFunction + : public extensions::BookmarksFunction { + public: + DECLARE_EXTENSION_FUNCTION("bookmarkManagerPrivate.getMetaInfo", + BOOKMARKMANAGERPRIVATE_GETMETAINFO) + + protected: + virtual ~BookmarkManagerPrivateGetMetaInfoFunction() {} + + // ExtensionFunction: + virtual bool RunImpl() OVERRIDE; +}; + +class BookmarkManagerPrivateSetMetaInfoFunction + : public extensions::BookmarksFunction { + public: + DECLARE_EXTENSION_FUNCTION("bookmarkManagerPrivate.setMetaInfo", + BOOKMARKMANAGERPRIVATE_SETMETAINFO) + + protected: + virtual ~BookmarkManagerPrivateSetMetaInfoFunction() {} + + // ExtensionFunction: + virtual bool RunImpl() OVERRIDE; +}; + class BookmarkManagerPrivateCanOpenNewWindowsFunction : public extensions::BookmarksFunction { public: diff --git a/chrome/browser/extensions/api/bookmarks/bookmarks_api.cc b/chrome/browser/extensions/api/bookmarks/bookmarks_api.cc index 1afca6a..25a5d7f 100644 --- a/chrome/browser/extensions/api/bookmarks/bookmarks_api.cc +++ b/chrome/browser/extensions/api/bookmarks/bookmarks_api.cc @@ -124,6 +124,20 @@ bool BookmarksFunction::GetBookmarkIdAsInt64(const std::string& id_string, return false; } +const BookmarkNode* BookmarksFunction::GetBookmarkNodeFromId( + const std::string& id_string) { + int64 id; + if (!GetBookmarkIdAsInt64(id_string, &id)) + return NULL; + + BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile()); + const BookmarkNode* node = model->GetNodeByID(id); + if (!node) + error_ = keys::kNoNodeError; + + return node; +} + bool BookmarksFunction::EditBookmarksEnabled() { PrefService* prefs = user_prefs::UserPrefs::Get(GetProfile()); if (prefs->GetBoolean(prefs::kEditBookmarksEnabled)) @@ -326,32 +340,21 @@ bool BookmarksGetFunction::RunImpl() { EXTENSION_FUNCTION_VALIDATE(params.get()); std::vector<linked_ptr<BookmarkTreeNode> > nodes; - BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile()); if (params->id_or_id_list.as_strings) { std::vector<std::string>& ids = *params->id_or_id_list.as_strings; size_t count = ids.size(); EXTENSION_FUNCTION_VALIDATE(count > 0); for (size_t i = 0; i < count; ++i) { - int64 id; - if (!GetBookmarkIdAsInt64(ids[i], &id)) + const BookmarkNode* node = GetBookmarkNodeFromId(ids[i]); + if (!node) return false; - const BookmarkNode* node = model->GetNodeByID(id); - if (!node) { - error_ = keys::kNoNodeError; - return false; - } else { - bookmark_api_helpers::AddNode(node, &nodes, false); - } + bookmark_api_helpers::AddNode(node, &nodes, false); } } else { - int64 id; - if (!GetBookmarkIdAsInt64(*params->id_or_id_list.as_string, &id)) - return false; - const BookmarkNode* node = model->GetNodeByID(id); - if (!node) { - error_ = keys::kNoNodeError; + const BookmarkNode* node = + GetBookmarkNodeFromId(*params->id_or_id_list.as_string); + if (!node) return false; - } bookmark_api_helpers::AddNode(node, &nodes, false); } @@ -364,17 +367,11 @@ bool BookmarksGetChildrenFunction::RunImpl() { bookmarks::GetChildren::Params::Create(*args_)); EXTENSION_FUNCTION_VALIDATE(params.get()); - int64 id; - if (!GetBookmarkIdAsInt64(params->id, &id)) + const BookmarkNode* node = GetBookmarkNodeFromId(params->id); + if (!node) return false; std::vector<linked_ptr<BookmarkTreeNode> > nodes; - const BookmarkNode* node = - BookmarkModelFactory::GetForProfile(GetProfile())->GetNodeByID(id); - if (!node) { - error_ = keys::kNoNodeError; - return false; - } int child_count = node->child_count(); for (int i = 0; i < child_count; ++i) { const BookmarkNode* child = node->GetChild(i); @@ -423,16 +420,9 @@ bool BookmarksGetSubTreeFunction::RunImpl() { bookmarks::GetSubTree::Params::Create(*args_)); EXTENSION_FUNCTION_VALIDATE(params.get()); - int64 id; - if (!GetBookmarkIdAsInt64(params->id, &id)) - return false; - - const BookmarkNode* node = - BookmarkModelFactory::GetForProfile(GetProfile())->GetNodeByID(id); - if (!node) { - error_ = keys::kNoNodeError; + const BookmarkNode* node = GetBookmarkNodeFromId(params->id); + if (!node) return false; - } std::vector<linked_ptr<BookmarkTreeNode> > nodes; bookmark_api_helpers::AddNode(node, &nodes, true); @@ -489,10 +479,8 @@ bool BookmarksRemoveFunction::RunImpl() { EXTENSION_FUNCTION_VALIDATE(params.get()); int64 id; - if (!base::StringToInt64(params->id, &id)) { - error_ = keys::kInvalidIdError; + if (!GetBookmarkIdAsInt64(params->id, &id)) return false; - } bool recursive = false; if (name() == BookmarksRemoveTreeFunction::function_name()) @@ -592,18 +580,11 @@ bool BookmarksMoveFunction::RunImpl() { bookmarks::Move::Params::Create(*args_)); EXTENSION_FUNCTION_VALIDATE(params.get()); - int64 id; - if (!base::StringToInt64(params->id, &id)) { - error_ = keys::kInvalidIdError; + const BookmarkNode* node = GetBookmarkNodeFromId(params->id); + if (!node) return false; - } BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile()); - const BookmarkNode* node = model->GetNodeByID(id); - if (!node) { - error_ = keys::kNoNodeError; - return false; - } if (model->is_permanent_node(node)) { error_ = keys::kModifySpecialError; return false; @@ -666,14 +647,6 @@ bool BookmarksUpdateFunction::RunImpl() { bookmarks::Update::Params::Create(*args_)); EXTENSION_FUNCTION_VALIDATE(params.get()); - int64 id; - if (!base::StringToInt64(params->id, &id)) { - error_ = keys::kInvalidIdError; - return false; - } - - BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile()); - // Optional but we need to distinguish non present from an empty title. string16 title; bool has_title = false; @@ -692,11 +665,11 @@ bool BookmarksUpdateFunction::RunImpl() { return false; } - const BookmarkNode* node = model->GetNodeByID(id); - if (!node) { - error_ = keys::kNoNodeError; + const BookmarkNode* node = GetBookmarkNodeFromId(params->id); + if (!node) return false; - } + + BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile()); if (model->is_permanent_node(node)) { error_ = keys::kModifySpecialError; return false; diff --git a/chrome/browser/extensions/api/bookmarks/bookmarks_api.h b/chrome/browser/extensions/api/bookmarks/bookmarks_api.h index 4d673c5..641a409 100644 --- a/chrome/browser/extensions/api/bookmarks/bookmarks_api.h +++ b/chrome/browser/extensions/api/bookmarks/bookmarks_api.h @@ -114,6 +114,11 @@ class BookmarksFunction : public ChromeAsyncExtensionFunction, // as an int64. In case of error, doesn't change id and returns false. bool GetBookmarkIdAsInt64(const std::string& id_string, int64* id); + // Helper to get the bookmark node from a given string id. + // If the given id can't be parsed or doesn't refer to a valid node, sets + // error_ and returns NULL. + const BookmarkNode* GetBookmarkNodeFromId(const std::string& id_string); + // Helper that checks if bookmark editing is enabled. If it's not, this sets // error_ to the appropriate error string. bool EditBookmarksEnabled(); diff --git a/chrome/browser/extensions/extension_function_histogram_value.h b/chrome/browser/extensions/extension_function_histogram_value.h index 24b7961..5ed24f8 100644 --- a/chrome/browser/extensions/extension_function_histogram_value.h +++ b/chrome/browser/extensions/extension_function_histogram_value.h @@ -684,6 +684,8 @@ enum HistogramValue { APP_CURRENTWINDOWINTERNAL_SETMAXHEIGHT, SYSTEMPRIVATE_GETAPIKEY, CHROMEOSINFOPRIVATE_SET, + BOOKMARKMANAGERPRIVATE_GETMETAINFO, + BOOKMARKMANAGERPRIVATE_SETMETAINFO, ENUM_BOUNDARY // Last entry: Add new entries above. }; |