Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6524)

Unified Diff: chrome/browser/notifications/sync_notifier/synced_notification.cc

Issue 193773003: Turn on and use the AppInfo data. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Turn on app info: CR fixes per DewittJ Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/notifications/sync_notifier/synced_notification.cc
diff --git a/chrome/browser/notifications/sync_notifier/synced_notification.cc b/chrome/browser/notifications/sync_notifier/synced_notification.cc
index cddced0d0dc35641cf3f0664cc7febacee87e3db..5d4133018380536904ec7b6bcd71dc323655e5f3 100644
--- a/chrome/browser/notifications/sync_notifier/synced_notification.cc
+++ b/chrome/browser/notifications/sync_notifier/synced_notification.cc
@@ -120,8 +120,6 @@ bool SyncedNotification::AreAllBitmapsFetched() {
// dpi bitmap when appropriate.
void SyncedNotification::OnFetchComplete(const GURL url,
const SkBitmap* bitmap) {
- // TODO(petewil): Add timeout mechanism in case bitmaps take too long. Do we
- // already have one built into URLFetcher?
// Make sure we are on the thread we expect.
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
@@ -161,23 +159,21 @@ void SyncedNotification::OnFetchComplete(const GURL url,
// See if all bitmaps are already accounted for, if so call Show.
if (AreAllBitmapsFetched()) {
- Show(notification_manager_, notifier_service_, profile_);
+ Show(profile_);
}
}
void SyncedNotification::QueueBitmapFetchJobs(
- NotificationUIManager* notification_manager,
ChromeNotifierService* notifier_service,
Profile* profile) {
// If we are not using the MessageCenter, call show now, and the existing
// code will handle the bitmap fetch for us.
if (!UseRichNotifications()) {
- Show(notification_manager, notifier_service, profile);
+ Show(profile);
return;
}
// Save off the arguments for the call to Show.
- notification_manager_ = notification_manager;
notifier_service_ = notifier_service;
profile_ = profile;
@@ -186,26 +182,26 @@ void SyncedNotification::QueueBitmapFetchJobs(
for (unsigned int i = 0; i < GetButtonCount(); ++i) {
button_bitmaps_.push_back(gfx::Image());
button_bitmaps_fetch_pending_.push_back(true);
- AddBitmapToFetchQueue(GetButtonIconUrl(i));
+ CreateBitmapFetcher(GetButtonIconUrl(i));
}
// If there is a profile image bitmap, fetch it
if (GetProfilePictureCount() > 0) {
// TODO(petewil): When we have the capacity to display more than one bitmap,
// modify this code to fetch as many as we can display
- AddBitmapToFetchQueue(GetProfilePictureUrl(0));
+ CreateBitmapFetcher(GetProfilePictureUrl(0));
}
// If the URL is non-empty, add it to our queue of URLs to fetch.
- AddBitmapToFetchQueue(GetAppIconUrl());
- AddBitmapToFetchQueue(GetImageUrl());
+ CreateBitmapFetcher(GetAppIconUrl());
+ CreateBitmapFetcher(GetImageUrl());
// Check to see if we don't need to fetch images, either because we already
// did, or because the URLs are empty. If so, we can display the notification.
// See if all bitmaps are accounted for, if so call Show().
if (AreAllBitmapsFetched()) {
- Show(notification_manager_, notifier_service_, profile_);
+ Show(profile_);
}
}
@@ -217,7 +213,7 @@ void SyncedNotification::StartBitmapFetch() {
}
}
-void SyncedNotification::AddBitmapToFetchQueue(const GURL& url) {
+void SyncedNotification::CreateBitmapFetcher(const GURL& url) {
// Check for dups, ignore any request for a dup.
ScopedVector<chrome::BitmapFetcher>::iterator iter;
for (iter = fetchers_.begin(); iter != fetchers_.end(); ++iter) {
@@ -231,21 +227,19 @@ void SyncedNotification::AddBitmapToFetchQueue(const GURL& url) {
}
}
-void SyncedNotification::Show(NotificationUIManager* notification_manager,
- ChromeNotifierService* notifier_service,
- Profile* profile) {
+void SyncedNotification::Show(Profile* profile) {
// Let NotificationUIManager know that the notification has been dismissed.
if (SyncedNotification::kRead == GetReadState() ||
SyncedNotification::kDismissed == GetReadState() ) {
- notification_manager->CancelById(GetKey());
+ notification_manager_->CancelById(GetKey());
DVLOG(2) << "Dismissed or read notification arrived"
<< GetHeading() << " " << GetText();
return;
}
// |notifier_service| can be NULL in tests.
- if (UseRichNotifications() && notifier_service) {
- notifier_service->ShowWelcomeToastIfNecessary(this, notification_manager);
+ if (UseRichNotifications() && notifier_service_) {
+ notifier_service_->ShowWelcomeToastIfNecessary(this, notification_manager_);
}
// Set up the fields we need to send and create a Notification object.
@@ -264,7 +258,7 @@ void SyncedNotification::Show(NotificationUIManager* notification_manager,
// The delegate will eventually catch calls that the notification
// was read or deleted, and send the changes back to the server.
scoped_refptr<NotificationDelegate> delegate =
- new ChromeNotifierDelegate(GetKey(), notifier_service);
+ new ChromeNotifierDelegate(GetKey(), notifier_service_);
// Some inputs and fields are only used if there is a notification center.
if (UseRichNotifications()) {
@@ -364,7 +358,7 @@ void SyncedNotification::Show(NotificationUIManager* notification_manager,
// has already been shown.
ui_notification.set_shown_as_popup(!toast_state_);
- notification_manager->Add(ui_notification, profile);
+ notification_manager_->Add(ui_notification, profile);
} else {
// In this case we have a Webkit Notification, not a Rich Notification.
Notification ui_notification(GetOriginUrl(),
@@ -376,7 +370,7 @@ void SyncedNotification::Show(NotificationUIManager* notification_manager,
replace_key,
delegate.get());
- notification_manager->Add(ui_notification, profile);
+ notification_manager_->Add(ui_notification, profile);
}
DVLOG(1) << "Showing Synced Notification! " << heading << " " << text
@@ -386,6 +380,20 @@ void SyncedNotification::Show(NotificationUIManager* notification_manager,
return;
}
+// Display the notification if it has the specified app_id_name.
+void SyncedNotification::ShowAllForAppId(Profile* profile,
+ std::string app_id_name) {
+ if (app_id_name == GetAppId())
+ Show(profile);
+}
+
+// Remove the notification if it has the specified app_id_name.
+void SyncedNotification::HideAllForAppId(std::string app_id_name) {
+ if (app_id_name == GetAppId()) {
+ notification_manager_->CancelById(GetKey());
+ }
+}
+
// This should detect even small changes in case the server updated the
// notification. We ignore the timestamp if other fields match.
bool SyncedNotification::EqualsIgnoringReadState(
@@ -746,14 +754,6 @@ std::string SyncedNotification::GetContainedNotificationMessage(
collapsed_info(index).simple_collapsed_layout().description();
}
-std::string SyncedNotification::GetSendingServiceId() const {
- // TODO(petewil): We are building a new protocol (a new sync datatype) to send
- // the service name and icon from the server. For now this method is
- // hardcoded to the name of our first service using synced notifications.
- // Once the new protocol is built, remove this hardcoding.
- return kFirstSyncedNotificationServiceId;
-}
-
const gfx::Image& SyncedNotification::GetAppIcon() const {
return app_icon_bitmap_;
}

Powered by Google App Engine
This is Rietveld 408576698