diff options
Diffstat (limited to 'chrome/browser/notifications/sync_notifier')
4 files changed, 75 insertions, 13 deletions
diff --git a/chrome/browser/notifications/sync_notifier/chrome_notifier_service.cc b/chrome/browser/notifications/sync_notifier/chrome_notifier_service.cc index 84643d3..d19153b 100644 --- a/chrome/browser/notifications/sync_notifier/chrome_notifier_service.cc +++ b/chrome/browser/notifications/sync_notifier/chrome_notifier_service.cc @@ -8,12 +8,16 @@ #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h" +#include <string> +#include <vector> + #include "chrome/browser/notifications/desktop_notification_service.h" #include "chrome/browser/notifications/desktop_notification_service_factory.h" #include "chrome/browser/notifications/notification.h" #include "chrome/browser/notifications/notification_ui_manager.h" #include "chrome/browser/profiles/profile.h" -#include "grit/ui_strings.h" +#include "grit/generated_resources.h" +#include "grit/theme_resources.h" #include "sync/api/sync_change.h" #include "sync/api/sync_change_processor.h" #include "sync/api/sync_error_factory.h" @@ -21,13 +25,14 @@ #include "sync/protocol/synced_notification_specifics.pb.h" #include "third_party/WebKit/public/web/WebTextDirection.h" #include "ui/base/l10n/l10n_util.h" +#include "ui/base/resource/resource_bundle.h" #include "ui/message_center/notifier_settings.h" #include "url/gurl.h" namespace notifier { namespace { -const char kSampleSyncedNotificationServiceId[] = "sample-synced-service"; +const char kFirstSyncedNotificationServiceId[] = "Google+"; } @@ -35,7 +40,8 @@ bool ChromeNotifierService::avoid_bitmap_fetching_for_test_ = false; ChromeNotifierService::ChromeNotifierService(Profile* profile, NotificationUIManager* manager) - : profile_(profile), notification_manager_(manager) {} + : profile_(profile), notification_manager_(manager) { +} ChromeNotifierService::~ChromeNotifierService() {} // Methods from BrowserContextKeyedService. @@ -270,20 +276,31 @@ void ChromeNotifierService::GetSyncedNotificationServices( // TODO(mukai|petewil): Check the profile's eligibility before adding the // sample app. - // Currently we just use kSampleSyncedNotificationServiceId as a place holder. - // TODO(petewil): Really obtain the list of apps from the server and create - // the list of ids here. + // TODO(petewil): Really obtain the list of synced notification sending + // services from the server and create the list of ids here. Until then, we + // are hardcoding the service names. Once that is done, remove this + // hardcoding. + // crbug.com/248337 DesktopNotificationService* desktop_notification_service = DesktopNotificationServiceFactory::GetForProfile(profile_); message_center::NotifierId notifier_id( message_center::NotifierId::SYNCED_NOTIFICATION_SERVICE, - kSampleSyncedNotificationServiceId); - notifiers->push_back(new message_center::Notifier( + kFirstSyncedNotificationServiceId); + message_center::Notifier* notifier_service = new message_center::Notifier( notifier_id, l10n_util::GetStringUTF16( - IDS_MESSAGE_CENTER_SAMPLE_SYNCED_NOTIFICATION_SERVICE_NAME), - desktop_notification_service->IsNotifierEnabled(notifier_id))); - // TODO(mukai): Add icon for the sample app. + IDS_FIRST_SYNCED_NOTIFICATION_SERVICE_NAME), + desktop_notification_service->IsNotifierEnabled(notifier_id)); + + // Add icons for our sending services. + // TODO(petewil): Replace this temporary hardcoding with a new sync datatype + // to dynamically get the name and icon for each synced notification sending + // service. Until then, we use hardcoded service icons for all services. + // crbug.com/248337 + notifier_service->icon = ui::ResourceBundle::GetSharedInstance(). + GetImageNamed(IDR_TEMPORARY_GOOGLE_PLUS_ICON); + + notifiers->push_back(notifier_service); } void ChromeNotifierService::MarkNotificationAsDismissed( @@ -311,6 +328,15 @@ void ChromeNotifierService::Add(scoped_ptr<SyncedNotification> notification) { // Take ownership of the object and put it into our local storage. notification_data_.push_back(notification.release()); + // If the user is not interested in this type of notification, ignore it. + std::vector<std::string>::iterator iter = + find(enabled_sending_services_.begin(), + enabled_sending_services_.end(), + notification_copy->GetSendingServiceId()); + if (iter == enabled_sending_services_.end()) { + return; + } + Display(notification_copy); } @@ -320,6 +346,7 @@ void ChromeNotifierService::AddForTest( } void ChromeNotifierService::Display(SyncedNotification* notification) { + // Set up to fetch the bitmaps. notification->QueueBitmapFetchJobs(notification_manager_, this, @@ -337,7 +364,23 @@ void ChromeNotifierService::Display(SyncedNotification* notification) { void ChromeNotifierService::OnSyncedNotificationServiceEnabled( const std::string& notifier_id, bool enabled) { - // TODO(petewil): start/stop syncing + std::vector<std::string>::iterator iter; + + iter = find(enabled_sending_services_.begin(), + enabled_sending_services_.end(), + notifier_id); + + // Add the notifier_id if it is enabled and not already there. + if (iter == enabled_sending_services_.end() && enabled) { + enabled_sending_services_.push_back(notifier_id); + // TODO(petewil) Check now for any outstanding notifications. + // Remove the notifier_id if it is disabled and present. + } else if (iter != enabled_sending_services_.end() && !enabled) { + enabled_sending_services_.erase(iter); + } + + // Otherwise, nothing to do, we can exit. + return; } } // namespace notifier diff --git a/chrome/browser/notifications/sync_notifier/chrome_notifier_service.h b/chrome/browser/notifications/sync_notifier/chrome_notifier_service.h index b423703..13a21f0ec 100644 --- a/chrome/browser/notifications/sync_notifier/chrome_notifier_service.h +++ b/chrome/browser/notifications/sync_notifier/chrome_notifier_service.h @@ -98,6 +98,7 @@ class ChromeNotifierService : public syncer::SyncableService, Profile* const profile_; NotificationUIManager* const notification_manager_; scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; + std::vector<std::string> enabled_sending_services_; static bool avoid_bitmap_fetching_for_test_; // TODO(petewil): Consider whether a map would better suit our data. diff --git a/chrome/browser/notifications/sync_notifier/synced_notification.cc b/chrome/browser/notifications/sync_notifier/synced_notification.cc index 851c5d6..90275e3 100644 --- a/chrome/browser/notifications/sync_notifier/synced_notification.cc +++ b/chrome/browser/notifications/sync_notifier/synced_notification.cc @@ -22,6 +22,13 @@ namespace { const char kExtensionScheme[] = "chrome-extension://"; +// The name of our first synced notification service. +// TODO(petewil): remove this hardcoding once we have the synced notification +// signalling sync data type set up to provide this. +// crbug.com/248337 +const char kFirstSyncedNotificationServiceId[] = "Google+"; + + // Today rich notifications only supports two buttons, make sure we don't // try to supply them with more than this number of buttons. const unsigned int kMaxNotificationButtonIndex = 2; @@ -470,7 +477,9 @@ int SyncedNotification::GetPriority() const { return message_center::DEFAULT_PRIORITY; } else if (protobuf_priority == sync_pb::CoalescedSyncedNotification_Priority_HIGH) { - return message_center::HIGH_PRIORITY; + // High priority synced notifications are considered default priority in + // Chrome. + return message_center::DEFAULT_PRIORITY; } else { // Complain if this is a new priority we have not seen before. DCHECK(protobuf_priority < @@ -575,4 +584,12 @@ 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; +} + } // namespace notifier diff --git a/chrome/browser/notifications/sync_notifier/synced_notification.h b/chrome/browser/notifications/sync_notifier/synced_notification.h index fd3ee55..318056b 100644 --- a/chrome/browser/notifications/sync_notifier/synced_notification.h +++ b/chrome/browser/notifications/sync_notifier/synced_notification.h @@ -71,6 +71,7 @@ class SyncedNotification : public NotificationBitmapFetcherDelegate { size_t GetButtonCount() const; std::string GetContainedNotificationTitle(int index) const; std::string GetContainedNotificationMessage(int index) const; + std::string GetSendingServiceId() const; bool EqualsIgnoringReadState(const SyncedNotification& other) const; |