diff options
author | mpcomplete@google.com <mpcomplete@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-05 19:07:01 +0000 |
---|---|---|
committer | mpcomplete@google.com <mpcomplete@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-05 19:07:01 +0000 |
commit | 32dda3615ecec2a9f0ce3318658588b4103d997d (patch) | |
tree | 0705a3eeb8f48c52329a1dcc5804aee59d80966a /chrome/browser/extensions/extension_bookmarks_module.cc | |
parent | c2f5dd7f69af7a59321e5acd1aa39fea5b2b2bfd (diff) | |
download | chromium_src-32dda3615ecec2a9f0ce3318658588b4103d997d.zip chromium_src-32dda3615ecec2a9f0ce3318658588b4103d997d.tar.gz chromium_src-32dda3615ecec2a9f0ce3318658588b4103d997d.tar.bz2 |
Make AsyncExtensionFunction possible.
Change the bookmarks API to be async functions, so that they can delay their
response until the bookmark system is loaded.
BUG=12353
TEST=none
Review URL: http://codereview.chromium.org/114079
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17751 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension_bookmarks_module.cc')
-rw-r--r-- | chrome/browser/extensions/extension_bookmarks_module.cc | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/chrome/browser/extensions/extension_bookmarks_module.cc b/chrome/browser/extensions/extension_bookmarks_module.cc index bced32f..0b538bc 100644 --- a/chrome/browser/extensions/extension_bookmarks_module.cc +++ b/chrome/browser/extensions/extension_bookmarks_module.cc @@ -12,6 +12,7 @@ #include "chrome/browser/extensions/extension_bookmarks_module_constants.h" #include "chrome/browser/extensions/extension_message_service.h" #include "chrome/browser/profile.h" +#include "chrome/common/notification_service.h" #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" @@ -66,11 +67,28 @@ class ExtensionBookmarks { void BookmarksFunction::Run() { // TODO(erikkay) temporary hack until adding an event listener can notify the // browser. + BookmarkModel* model = profile()->GetBookmarkModel(); + if (!model->IsLoaded()) { + // Bookmarks are not ready yet. We'll wait. + registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED, + NotificationService::AllSources()); + AddRef(); // balanced in Observe() + return; + } + ExtensionBookmarkEventRouter* event_router = ExtensionBookmarkEventRouter::GetSingleton(); - BookmarkModel* model = profile()->GetBookmarkModel(); event_router->Observe(model); - SyncExtensionFunction::Run(); + SendResponse(RunImpl()); +} + +void BookmarksFunction::Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + DCHECK(type == NotificationType::BOOKMARK_MODEL_LOADED); + DCHECK(profile()->GetBookmarkModel()->IsLoaded()); + Run(); + Release(); // balanced in Run() } // static |