diff options
author | asargent@chromium.org <asargent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-26 21:03:43 +0000 |
---|---|---|
committer | asargent@chromium.org <asargent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-26 21:03:43 +0000 |
commit | 015ce6ebccb611b40e09c237042912840d2d1a4f (patch) | |
tree | e8b3d0db17999c58be3efef6a946f2eeb6a4d3b6 /chrome/browser/extensions/extension_app_api.cc | |
parent | d4cba0a8cbcead734975d7fe995856b7a40a76ed (diff) | |
download | chromium_src-015ce6ebccb611b40e09c237042912840d2d1a4f.zip chromium_src-015ce6ebccb611b40e09c237042912840d2d1a4f.tar.gz chromium_src-015ce6ebccb611b40e09c237042912840d2d1a4f.tar.bz2 |
Move AppNotification and AppNotificationManager into their own files.
Previously they were defined inside extension_app_api.{h,cc}.
Also:
-Change AppNotification from a struct to a class.
-Remove iconData parameter from notify function (support was never actually implemented)
This CL is preparation for persisting the app notifications to disk.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/8041007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@102796 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension_app_api.cc')
-rw-r--r-- | chrome/browser/extensions/extension_app_api.cc | 93 |
1 files changed, 12 insertions, 81 deletions
diff --git a/chrome/browser/extensions/extension_app_api.cc b/chrome/browser/extensions/extension_app_api.cc index cc545fa..95c2b6f 100644 --- a/chrome/browser/extensions/extension_app_api.cc +++ b/chrome/browser/extensions/extension_app_api.cc @@ -4,19 +4,14 @@ #include "chrome/browser/extensions/extension_app_api.h" -#include "base/stl_util.h" #include "base/values.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/extensions/extension.h" -#include "chrome/common/render_messages.h" -#include "content/common/notification_service.h" - const char kBodyTextKey[] = "bodyText"; const char kExtensionIdKey[] = "extensionId"; -const char kIconDataKey[] = "iconData"; const char kLinkTextKey[] = "linkText"; const char kLinkUrlKey[] = "linkUrl"; const char kTitleKey[] = "title"; @@ -26,68 +21,11 @@ const char kInvalidExtensionIdError[] = const char kMissingLinkTextError[] = "You must specify linkText if you use linkUrl"; -AppNotification::AppNotification() {} - -AppNotification::~AppNotification() {} - -AppNotificationManager::AppNotificationManager() { - registrar_.Add(this, - chrome::NOTIFICATION_EXTENSION_UNINSTALLED, - NotificationService::AllSources()); -} - -AppNotificationManager::~AppNotificationManager() {} - -void AppNotificationManager::Add(AppNotification* item) { - CHECK(!item->extension_id.empty()); - NotificationMap::iterator found = notifications_.find(item->extension_id); - if (found == notifications_.end()) { - notifications_[item->extension_id] = AppNotificationList(); - found = notifications_.find(item->extension_id); - } - CHECK(found != notifications_.end()); - AppNotificationList& list = (*found).second; - list.push_back(linked_ptr<AppNotification>(item)); -} - -const AppNotificationList* AppNotificationManager::GetAll( - const std::string& extension_id) { - if (ContainsKey(notifications_, extension_id)) - return ¬ifications_[extension_id]; - return NULL; -} - -const AppNotification* AppNotificationManager::GetLast( - const std::string& extension_id) { - NotificationMap::iterator found = notifications_.find(extension_id); - if (found == notifications_.end()) - return NULL; - const AppNotificationList& list = found->second; - return list.rbegin()->get(); -} - -void AppNotificationManager::ClearAll(const std::string& extension_id) { - NotificationMap::iterator found = notifications_.find(extension_id); - if (found != notifications_.end()) - notifications_.erase(found); -} - -void AppNotificationManager::Observe(int type, - const NotificationSource& source, - const NotificationDetails& details) { - CHECK(type == chrome::NOTIFICATION_EXTENSION_UNINSTALLED); - const std::string& id = - Details<UninstalledExtensionInfo>(details)->extension_id; - ClearAll(id); -} - bool AppNotifyFunction::RunImpl() { DictionaryValue* details; EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); EXTENSION_FUNCTION_VALIDATE(details != NULL); - scoped_ptr<AppNotification> item(new AppNotification()); - // TODO(asargent) remove this before the API leaves experimental. std::string id = extension_id(); if (details->HasKey(kExtensionIdKey)) { @@ -98,19 +36,21 @@ bool AppNotifyFunction::RunImpl() { } } - item->extension_id = id; - + std::string title; if (details->HasKey(kTitleKey)) - EXTENSION_FUNCTION_VALIDATE(details->GetString(kTitleKey, &item->title)); + EXTENSION_FUNCTION_VALIDATE(details->GetString(kTitleKey, &title)); + std::string body; if (details->HasKey(kBodyTextKey)) - EXTENSION_FUNCTION_VALIDATE(details->GetString(kBodyTextKey, &item->body)); + EXTENSION_FUNCTION_VALIDATE(details->GetString(kBodyTextKey, &body)); + + scoped_ptr<AppNotification> item(new AppNotification(title, body)); if (details->HasKey(kLinkUrlKey)) { std::string link_url; EXTENSION_FUNCTION_VALIDATE(details->GetString(kLinkUrlKey, &link_url)); - item->linkUrl = GURL(link_url); - if (!item->linkUrl.is_valid()) { + item->set_link_url(GURL(link_url)); + if (!item->link_url().is_valid()) { error_ = "Invalid url: " + link_url; return false; } @@ -118,25 +58,16 @@ bool AppNotifyFunction::RunImpl() { error_ = kMissingLinkTextError; return false; } + std::string link_text; EXTENSION_FUNCTION_VALIDATE(details->GetString(kLinkTextKey, - &item->linkText)); - } - - if (details->HasKey(kIconDataKey)) { - base::BinaryValue* binary = NULL; - EXTENSION_FUNCTION_VALIDATE(details->GetBinary(kIconDataKey, &binary)); - IPC::Message bitmap_pickle(binary->GetBuffer(), binary->GetSize()); - void* iter = NULL; - SkBitmap bitmap; - EXTENSION_FUNCTION_VALIDATE( - IPC::ReadParam(&bitmap_pickle, &iter, &bitmap)); - // TODO(asargent) - use the bitmap to set the NTP icon! + &link_text)); + item->set_link_text(link_text); } AppNotificationManager* manager = profile()->GetExtensionService()->app_notification_manager(); - manager->Add(item.release()); + manager->Add(id, item.release()); NotificationService::current()->Notify( chrome::NOTIFICATION_APP_NOTIFICATION_STATE_CHANGED, |