Commit 73d3a86c authored by munjal@chromium.org's avatar munjal@chromium.org

Some fixups for app notifications:

- Generate STATE_CHANGED notification in the Add method instead of
  in other places which call Add.
- Generate STATE_CHANGED notification in ClearAll and Remove methods.
- Hook up the bubble close button action with code that calls ClearAll.
Review URL: http://codereview.chromium.org/8382010

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@107063 0039d316-1c4b-4281-b951-d872f2087c98
parent 2a824a0c
...@@ -110,6 +110,12 @@ bool AppNotificationManager::Add(AppNotification* item) { ...@@ -110,6 +110,12 @@ bool AppNotificationManager::Add(AppNotification* item) {
base::Bind(&AppNotificationManager::SaveOnFileThread, base::Bind(&AppNotificationManager::SaveOnFileThread,
this, extension_id, CopyAppNotificationList(list))); this, extension_id, CopyAppNotificationList(list)));
} }
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_APP_NOTIFICATION_STATE_CHANGED,
content::Source<Profile>(profile_),
content::Details<const std::string>(&extension_id));
return true; return true;
} }
...@@ -141,6 +147,8 @@ const AppNotification* AppNotificationManager::GetLast( ...@@ -141,6 +147,8 @@ const AppNotification* AppNotificationManager::GetLast(
if (found == notifications_->end()) if (found == notifications_->end())
return NULL; return NULL;
const AppNotificationList& list = found->second; const AppNotificationList& list = found->second;
if (list.empty())
return NULL;
return list.rbegin()->get(); return list.rbegin()->get();
} }
...@@ -160,6 +168,11 @@ void AppNotificationManager::ClearAll(const std::string& extension_id) { ...@@ -160,6 +168,11 @@ void AppNotificationManager::ClearAll(const std::string& extension_id) {
base::Bind(&AppNotificationManager::DeleteOnFileThread, base::Bind(&AppNotificationManager::DeleteOnFileThread,
this, extension_id)); this, extension_id));
} }
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_APP_NOTIFICATION_STATE_CHANGED,
content::Source<Profile>(profile_),
content::Details<const std::string>(&extension_id));
} }
void AppNotificationManager::Observe( void AppNotificationManager::Observe(
...@@ -439,6 +452,11 @@ void AppNotificationManager::Remove(const std::string& extension_id, ...@@ -439,6 +452,11 @@ void AppNotificationManager::Remove(const std::string& extension_id,
base::Bind(&AppNotificationManager::SaveOnFileThread, base::Bind(&AppNotificationManager::SaveOnFileThread,
this, extension_id, CopyAppNotificationList(list))); this, extension_id, CopyAppNotificationList(list)));
} }
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_APP_NOTIFICATION_STATE_CHANGED,
content::Source<Profile>(profile_),
content::Details<const std::string>(&extension_id));
} }
// static // static
......
...@@ -146,12 +146,6 @@ class AppNotificationManagerSyncTest : public testing::Test { ...@@ -146,12 +146,6 @@ class AppNotificationManagerSyncTest : public testing::Test {
return notif; return notif;
} }
static AppNotification* CreateNotification(const AppNotification& notif) {
return CreateNotification(
notif.is_local(), notif.guid(), notif.extension_id(), notif.title(),
notif.body(), notif.link_url().spec(), notif.link_text());
}
static SyncData CreateSyncData(int suffix) { static SyncData CreateSyncData(int suffix) {
scoped_ptr<AppNotification> notif(CreateNotification(suffix)); scoped_ptr<AppNotification> notif(CreateNotification(suffix));
return AppNotificationManager::CreateSyncDataFromNotification(*notif); return AppNotificationManager::CreateSyncDataFromNotification(*notif);
...@@ -491,8 +485,7 @@ TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesNonEmptyModel) { ...@@ -491,8 +485,7 @@ TEST_F(AppNotificationManagerSyncTest, ProcessSyncChangesNonEmptyModel) {
SyncChangeList changes; SyncChangeList changes;
changes.push_back(CreateSyncChange( changes.push_back(CreateSyncChange(
SyncChange::ACTION_ADD, CreateNotification(3))); SyncChange::ACTION_ADD, CreateNotification(3)));
changes.push_back(CreateSyncChange( changes.push_back(CreateSyncChange(SyncChange::ACTION_DELETE, n1->Copy()));
SyncChange::ACTION_DELETE, CreateNotification(*n1)));
changes.push_back(CreateSyncChange( changes.push_back(CreateSyncChange(
SyncChange::ACTION_ADD, CreateNotification(4))); SyncChange::ACTION_ADD, CreateNotification(4)));
......
...@@ -72,11 +72,6 @@ bool AppNotifyFunction::RunImpl() { ...@@ -72,11 +72,6 @@ bool AppNotifyFunction::RunImpl() {
manager->Add(item.release()); manager->Add(item.release());
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_APP_NOTIFICATION_STATE_CHANGED,
content::Source<Profile>(profile_),
content::Details<const std::string>(&id));
return true; return true;
} }
...@@ -94,9 +89,5 @@ bool AppClearAllNotificationsFunction::RunImpl() { ...@@ -94,9 +89,5 @@ bool AppClearAllNotificationsFunction::RunImpl() {
AppNotificationManager* manager = AppNotificationManager* manager =
profile()->GetExtensionService()->app_notification_manager(); profile()->GetExtensionService()->app_notification_manager();
manager->ClearAll(id); manager->ClearAll(id);
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_APP_NOTIFICATION_STATE_CHANGED,
content::Source<Profile>(profile_),
content::Details<const std::string>(&id));
return true; return true;
} }
...@@ -301,7 +301,7 @@ cr.define('ntp4', function() { ...@@ -301,7 +301,7 @@ cr.define('ntp4', function() {
// text. // text.
setupNotification_: function(notification) { setupNotification_: function(notification) {
// Remove the old notification from this node (if any). // Remove the old notification from this node (if any).
if (this.appNotification_) if (this.appNotification_ && this.appNotification_.parentNode)
this.appNotification_.parentNode.removeChild(this.appNotification_); this.appNotification_.parentNode.removeChild(this.appNotification_);
if (notification) { if (notification) {
...@@ -455,8 +455,13 @@ cr.define('ntp4', function() { ...@@ -455,8 +455,13 @@ cr.define('ntp4', function() {
} }
var infoBubble = new cr.ui.Bubble; var infoBubble = new cr.ui.Bubble;
infoBubble.appId = this.appData_.id;
infoBubble.anchorNode = e.target; infoBubble.anchorNode = e.target;
infoBubble.content = container; infoBubble.content = container;
infoBubble.handleCloseEvent = function() {
chrome.send('closeNotification', [this.appId]);
this.hide();
};
infoBubble.show(); infoBubble.show();
}, },
......
...@@ -277,6 +277,9 @@ void AppLauncherHandler::RegisterMessages() { ...@@ -277,6 +277,9 @@ void AppLauncherHandler::RegisterMessages() {
web_ui_->RegisterMessageCallback("recordAppLaunchByURL", web_ui_->RegisterMessageCallback("recordAppLaunchByURL",
base::Bind(&AppLauncherHandler::HandleRecordAppLaunchByURL, base::Bind(&AppLauncherHandler::HandleRecordAppLaunchByURL,
base::Unretained(this))); base::Unretained(this)));
web_ui_->RegisterMessageCallback("closeNotification",
base::Bind(&AppLauncherHandler::HandleNotificationClose,
base::Unretained(this)));
} }
void AppLauncherHandler::Observe(int type, void AppLauncherHandler::Observe(int type,
...@@ -837,6 +840,20 @@ void AppLauncherHandler::HandleRecordAppLaunchByURL( ...@@ -837,6 +840,20 @@ void AppLauncherHandler::HandleRecordAppLaunchByURL(
RecordAppLaunchByURL(Profile::FromWebUI(web_ui_), url, bucket); RecordAppLaunchByURL(Profile::FromWebUI(web_ui_), url, bucket);
} }
void AppLauncherHandler::HandleNotificationClose(const ListValue* args) {
std::string extension_id;
CHECK(args->GetString(0, &extension_id));
const Extension* extension = extension_service_->GetExtensionById(
extension_id, true);
if (!extension)
return;
AppNotificationManager* notification_manager =
extension_service_->app_notification_manager();
notification_manager->ClearAll(extension_id);
}
void AppLauncherHandler::OnFaviconForApp(FaviconService::Handle handle, void AppLauncherHandler::OnFaviconForApp(FaviconService::Handle handle,
history::FaviconData data) { history::FaviconData data) {
scoped_ptr<AppInstallInfo> install_info( scoped_ptr<AppInstallInfo> install_info(
......
...@@ -111,6 +111,9 @@ class AppLauncherHandler : public WebUIMessageHandler, ...@@ -111,6 +111,9 @@ class AppLauncherHandler : public WebUIMessageHandler,
// action for UMA. // action for UMA.
void HandleRecordAppLaunchByURL(const base::ListValue* args); void HandleRecordAppLaunchByURL(const base::ListValue* args);
// Callback for "closeNotification" message.
void HandleNotificationClose(const base::ListValue* args);
// Register app launcher preferences. // Register app launcher preferences.
static void RegisterUserPrefs(PrefService* pref_service); static void RegisterUserPrefs(PrefService* pref_service);
......
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