#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
-#include "chrome/browser/bookmarks/base_bookmark_model_observer.h"
#include "chrome/browser/extensions/chrome_extension_function.h"
+#include "components/bookmarks/browser/base_bookmark_model_observer.h"
+#include "components/bookmarks/browser/bookmark_node.h"
#include "extensions/browser/browser_context_keyed_api_factory.h"
#include "extensions/browser/event_router.h"
#include "ui/shell_dialogs/select_file_dialog.h"
+class ChromeBookmarkClient;
+
namespace base {
class FilePath;
class ListValue;
namespace extensions {
+namespace api {
+namespace bookmarks {
+struct CreateDetails;
+}
+}
+
// Observes BookmarkModel and then routes the notifications as events to
// the extension system.
class BookmarkEventRouter : public BookmarkModelObserver {
public:
- BookmarkEventRouter(content::BrowserContext* context, BookmarkModel* model);
- virtual ~BookmarkEventRouter();
+ explicit BookmarkEventRouter(Profile* profile);
+ ~BookmarkEventRouter() override;
// BookmarkModelObserver:
- virtual void BookmarkModelLoaded(BookmarkModel* model,
- bool ids_reassigned) OVERRIDE;
- virtual void BookmarkModelBeingDeleted(BookmarkModel* model) OVERRIDE;
- virtual void BookmarkNodeMoved(BookmarkModel* model,
- const BookmarkNode* old_parent,
- int old_index,
- const BookmarkNode* new_parent,
- int new_index) OVERRIDE;
- virtual void BookmarkNodeAdded(BookmarkModel* model,
- const BookmarkNode* parent,
- int index) OVERRIDE;
- virtual void BookmarkNodeRemoved(BookmarkModel* model,
- const BookmarkNode* parent,
- int old_index,
- const BookmarkNode* node) OVERRIDE;
- virtual void BookmarkAllNodesRemoved(BookmarkModel* model) OVERRIDE;
- virtual void BookmarkNodeChanged(BookmarkModel* model,
- const BookmarkNode* node) OVERRIDE;
- virtual void BookmarkNodeFaviconChanged(BookmarkModel* model,
- const BookmarkNode* node) OVERRIDE;
- virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
- const BookmarkNode* node) OVERRIDE;
- virtual void ExtensiveBookmarkChangesBeginning(BookmarkModel* model) OVERRIDE;
- virtual void ExtensiveBookmarkChangesEnded(BookmarkModel* model) OVERRIDE;
+ void BookmarkModelLoaded(BookmarkModel* model, bool ids_reassigned) override;
+ void BookmarkModelBeingDeleted(BookmarkModel* model) override;
+ void BookmarkNodeMoved(BookmarkModel* model,
+ const BookmarkNode* old_parent,
+ int old_index,
+ const BookmarkNode* new_parent,
+ int new_index) override;
+ void BookmarkNodeAdded(BookmarkModel* model,
+ const BookmarkNode* parent,
+ int index) override;
+ void BookmarkNodeRemoved(BookmarkModel* model,
+ const BookmarkNode* parent,
+ int old_index,
+ const BookmarkNode* node,
+ const std::set<GURL>& removed_urls) override;
+ void BookmarkAllUserNodesRemoved(BookmarkModel* model,
+ const std::set<GURL>& removed_urls) override;
+ void BookmarkNodeChanged(BookmarkModel* model,
+ const BookmarkNode* node) override;
+ void BookmarkNodeFaviconChanged(BookmarkModel* model,
+ const BookmarkNode* node) override;
+ void BookmarkNodeChildrenReordered(BookmarkModel* model,
+ const BookmarkNode* node) override;
+ void ExtensiveBookmarkChangesBeginning(BookmarkModel* model) override;
+ void ExtensiveBookmarkChangesEnded(BookmarkModel* model) override;
private:
// Helper to actually dispatch an event to extension listeners.
content::BrowserContext* browser_context_;
BookmarkModel* model_;
+ ChromeBookmarkClient* client_;
DISALLOW_COPY_AND_ASSIGN(BookmarkEventRouter);
};
public EventRouter::Observer {
public:
explicit BookmarksAPI(content::BrowserContext* context);
- virtual ~BookmarksAPI();
+ ~BookmarksAPI() override;
// KeyedService implementation.
- virtual void Shutdown() OVERRIDE;
+ void Shutdown() override;
// BrowserContextKeyedAPI implementation.
static BrowserContextKeyedAPIFactory<BookmarksAPI>* GetFactoryInstance();
// EventRouter::Observer implementation.
- virtual void OnListenerAdded(
- const EventListenerInfo& details) OVERRIDE;
+ void OnListenerAdded(const EventListenerInfo& details) override;
private:
friend class BrowserContextKeyedAPIFactory<BookmarksAPI>;
public BaseBookmarkModelObserver {
public:
// AsyncExtensionFunction:
- virtual void Run() OVERRIDE;
+ bool RunAsync() override;
protected:
- virtual ~BookmarksFunction() {}
+ ~BookmarksFunction() override {}
+
+ // RunAsync semantic equivalent called when the bookmarks are ready.
+ virtual bool RunOnReady() = 0;
+
+ // Helper to get the BookmarkModel.
+ BookmarkModel* GetBookmarkModel();
+
+ // Helper to get the ChromeBookmarkClient.
+ ChromeBookmarkClient* GetChromeBookmarkClient();
// Helper to get the bookmark id as int64 from the given string id.
// Sets error_ to an error string if the given id string can't be parsed
// error_ and returns NULL.
const BookmarkNode* GetBookmarkNodeFromId(const std::string& id_string);
+ // Helper to create a bookmark node from a CreateDetails object. If a node
+ // can't be created based on the given details, sets error_ and returns NULL.
+ const BookmarkNode* CreateBookmarkNode(
+ BookmarkModel* model,
+ const api::bookmarks::CreateDetails& details,
+ const BookmarkNode::MetaInfoMap* meta_info);
+
// Helper that checks if bookmark editing is enabled. If it's not, this sets
// error_ to the appropriate error string.
bool EditBookmarksEnabled();
+ // Helper that checks if |node| can be modified. Returns false if |node|
+ // is NULL, or a managed node, or the root node. In these cases the node
+ // can't be edited, can't have new child nodes appended, and its direct
+ // children can't be moved or reordered.
+ bool CanBeModified(const BookmarkNode* node);
+
private:
// BaseBookmarkModelObserver:
- virtual void BookmarkModelChanged() OVERRIDE;
- virtual void BookmarkModelLoaded(BookmarkModel* model,
- bool ids_reassigned) OVERRIDE;
+ void BookmarkModelChanged() override;
+ void BookmarkModelLoaded(BookmarkModel* model, bool ids_reassigned) override;
+
+ void RunAndSendResponse();
};
class BookmarksGetFunction : public BookmarksFunction {
DECLARE_EXTENSION_FUNCTION("bookmarks.get", BOOKMARKS_GET)
protected:
- virtual ~BookmarksGetFunction() {}
+ ~BookmarksGetFunction() override {}
- // ExtensionFunction:
- virtual bool RunImpl() OVERRIDE;
+ // BookmarksFunction:
+ bool RunOnReady() override;
};
class BookmarksGetChildrenFunction : public BookmarksFunction {
DECLARE_EXTENSION_FUNCTION("bookmarks.getChildren", BOOKMARKS_GETCHILDREN)
protected:
- virtual ~BookmarksGetChildrenFunction() {}
+ ~BookmarksGetChildrenFunction() override {}
- // ExtensionFunction:
- virtual bool RunImpl() OVERRIDE;
+ // BookmarksFunction:
+ bool RunOnReady() override;
};
class BookmarksGetRecentFunction : public BookmarksFunction {
DECLARE_EXTENSION_FUNCTION("bookmarks.getRecent", BOOKMARKS_GETRECENT)
protected:
- virtual ~BookmarksGetRecentFunction() {}
+ ~BookmarksGetRecentFunction() override {}
- // ExtensionFunction:
- virtual bool RunImpl() OVERRIDE;
+ // BookmarksFunction:
+ bool RunOnReady() override;
};
class BookmarksGetTreeFunction : public BookmarksFunction {
DECLARE_EXTENSION_FUNCTION("bookmarks.getTree", BOOKMARKS_GETTREE)
protected:
- virtual ~BookmarksGetTreeFunction() {}
+ ~BookmarksGetTreeFunction() override {}
- // ExtensionFunction:
- virtual bool RunImpl() OVERRIDE;
+ // BookmarksFunction:
+ bool RunOnReady() override;
};
class BookmarksGetSubTreeFunction : public BookmarksFunction {
DECLARE_EXTENSION_FUNCTION("bookmarks.getSubTree", BOOKMARKS_GETSUBTREE)
protected:
- virtual ~BookmarksGetSubTreeFunction() {}
+ ~BookmarksGetSubTreeFunction() override {}
- // ExtensionFunction:
- virtual bool RunImpl() OVERRIDE;
+ // BookmarksFunction:
+ bool RunOnReady() override;
};
class BookmarksSearchFunction : public BookmarksFunction {
DECLARE_EXTENSION_FUNCTION("bookmarks.search", BOOKMARKS_SEARCH)
protected:
- virtual ~BookmarksSearchFunction() {}
+ ~BookmarksSearchFunction() override {}
- // ExtensionFunction:
- virtual bool RunImpl() OVERRIDE;
+ // BookmarksFunction:
+ bool RunOnReady() override;
};
class BookmarksRemoveFunction : public BookmarksFunction {
static bool ExtractIds(const base::ListValue* args,
std::list<int64>* ids,
bool* invalid_id);
- // ExtensionFunction:
- virtual void GetQuotaLimitHeuristics(
- QuotaLimitHeuristics* heuristics) const OVERRIDE;
protected:
- virtual ~BookmarksRemoveFunction() {}
+ ~BookmarksRemoveFunction() override {}
- // ExtensionFunction:
- virtual bool RunImpl() OVERRIDE;
+ // BookmarksFunction:
+ bool RunOnReady() override;
};
class BookmarksRemoveTreeFunction : public BookmarksRemoveFunction {
DECLARE_EXTENSION_FUNCTION("bookmarks.removeTree", BOOKMARKS_REMOVETREE)
protected:
- virtual ~BookmarksRemoveTreeFunction() {}
+ ~BookmarksRemoveTreeFunction() override {}
};
class BookmarksCreateFunction : public BookmarksFunction {
public:
DECLARE_EXTENSION_FUNCTION("bookmarks.create", BOOKMARKS_CREATE)
- // ExtensionFunction:
- virtual void GetQuotaLimitHeuristics(
- QuotaLimitHeuristics* heuristics) const OVERRIDE;
-
protected:
- virtual ~BookmarksCreateFunction() {}
+ ~BookmarksCreateFunction() override {}
- // ExtensionFunction:
- virtual bool RunImpl() OVERRIDE;
+ // BookmarksFunction:
+ bool RunOnReady() override;
};
class BookmarksMoveFunction : public BookmarksFunction {
std::list<int64>* ids,
bool* invalid_id);
- // ExtensionFunction:
- virtual void GetQuotaLimitHeuristics(
- QuotaLimitHeuristics* heuristics) const OVERRIDE;
-
protected:
- virtual ~BookmarksMoveFunction() {}
+ ~BookmarksMoveFunction() override {}
- // ExtensionFunction:
- virtual bool RunImpl() OVERRIDE;
+ // BookmarksFunction:
+ bool RunOnReady() override;
};
class BookmarksUpdateFunction : public BookmarksFunction {
std::list<int64>* ids,
bool* invalid_id);
- // ExtensionFunction:
- virtual void GetQuotaLimitHeuristics(
- QuotaLimitHeuristics* heuristics) const OVERRIDE;
-
protected:
- virtual ~BookmarksUpdateFunction() {}
+ ~BookmarksUpdateFunction() override {}
- // ExtensionFunction:
- virtual bool RunImpl() OVERRIDE;
+ // BookmarksFunction:
+ bool RunOnReady() override;
};
class BookmarksIOFunction : public BookmarksFunction,
virtual void FileSelected(const base::FilePath& path, int index, void* params) = 0;
// ui::SelectFileDialog::Listener:
- virtual void MultiFilesSelected(const std::vector<base::FilePath>& files,
- void* params) OVERRIDE;
- virtual void FileSelectionCanceled(void* params) OVERRIDE;
+ void MultiFilesSelected(const std::vector<base::FilePath>& files,
+ void* params) override;
+ void FileSelectionCanceled(void* params) override;
void SelectFile(ui::SelectFileDialog::Type type);
protected:
- virtual ~BookmarksIOFunction();
+ ~BookmarksIOFunction() override;
private:
void ShowSelectFileDialog(
DECLARE_EXTENSION_FUNCTION("bookmarks.import", BOOKMARKS_IMPORT)
// BookmarkManagerIOFunction:
- virtual void FileSelected(const base::FilePath& path,
- int index,
- void* params) OVERRIDE;
+ void FileSelected(const base::FilePath& path,
+ int index,
+ void* params) override;
private:
- virtual ~BookmarksImportFunction() {}
+ ~BookmarksImportFunction() override {}
- // ExtensionFunction:
- virtual bool RunImpl() OVERRIDE;
+ // BookmarksFunction:
+ bool RunOnReady() override;
};
class BookmarksExportFunction : public BookmarksIOFunction {
DECLARE_EXTENSION_FUNCTION("bookmarks.export", BOOKMARKS_EXPORT)
// BookmarkManagerIOFunction:
- virtual void FileSelected(const base::FilePath& path,
- int index,
- void* params) OVERRIDE;
+ void FileSelected(const base::FilePath& path,
+ int index,
+ void* params) override;
private:
- virtual ~BookmarksExportFunction() {}
+ ~BookmarksExportFunction() override {}
- // ExtensionFunction:
- virtual bool RunImpl() OVERRIDE;
+ // BookmarksFunction:
+ bool RunOnReady() override;
};
} // namespace extensions