diff options
author | petewil@chromium.org <petewil@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-23 18:35:02 +0000 |
---|---|---|
committer | petewil@chromium.org <petewil@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-23 18:35:02 +0000 |
commit | 04f04515266f73e5b4111d33c8cb49d39b03fc20 (patch) | |
tree | f554ad9eb256dae9c78abdbbdcabb500bc4073e7 | |
parent | 4b8e2505874f005a2d4fd9ef3fb4b84e43b38275 (diff) | |
download | chromium_src-04f04515266f73e5b4111d33c8cb49d39b03fc20.zip chromium_src-04f04515266f73e5b4111d33c8cb49d39b03fc20.tar.gz chromium_src-04f04515266f73e5b4111d33c8cb49d39b03fc20.tar.bz2 |
Enable and disable Synced Notification Client Services
Synced Notifications can be sent from web services. This checkin will allow us to enable and disable synced notifications from specific service sources. For example, sending services could include mail, calendar, and Google+. These notifications will be displayed to the user as Rich Notifications.
We are developing a protocol to send the names, app ids, and icons for these services as a new synced data type. However, until that protocol is ready, we are hardcoding the names and icons of the services into chrome. We will remove the hardcoded names and icons once the new sync datatype is ready (hopefully during the next milestone).
This change also supplies the name of our first client (Google+) and an icon to use in the synced notifications settings dialog. Due to licensing restrictions, we are checking in one icon for chromium (basically a copy of the default favicon), and another one for chrome proper (this will be a separate checkin to the chrome specific codebase).
BUG=254617
Review URL: https://chromiumcodereview.appspot.com/19056002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@213175 0039d316-1c4b-4281-b951-d872f2087c98
7 files changed, 81 insertions, 16 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index 4d0f233..6378b4a 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -15738,6 +15738,11 @@ Do you accept? More Apps </message> + <!-- Synced Notification display strings --> + <message name="IDS_FIRST_SYNCED_NOTIFICATION_SERVICE_NAME" desc="The name of the first service source for synced notifications."> + Google+ + </message> + </messages> <structures fallback_to_english="true"> diff --git a/chrome/app/theme/theme_resources.grd b/chrome/app/theme/theme_resources.grd index eae61f9..51c979f 100644 --- a/chrome/app/theme/theme_resources.grd +++ b/chrome/app/theme/theme_resources.grd @@ -839,6 +839,7 @@ <if expr="pp_ifdef('chromeos')"> <structure type="chrome_scaled_image" name="IDR_TECHNICAL_ERROR" file="cros/technical_error.png" /> </if> + <structure type="chrome_scaled_image" name="IDR_TEMPORARY_GOOGLE_PLUS_ICON" file="common/ic_gplus_color_16.png" /> <structure type="chrome_scaled_image" name="IDR_THEME_BUTTON_BACKGROUND" file="notused.png" /> <if expr="not pp_ifdef('use_ash')"> <structure type="chrome_scaled_image" name="IDR_THEME_FRAME" file="theme_frame.png" /> 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; diff --git a/ui/base/strings/ui_strings.grd b/ui/base/strings/ui_strings.grd index fd1cac9..203d936 100644 --- a/ui/base/strings/ui_strings.grd +++ b/ui/base/strings/ui_strings.grd @@ -498,9 +498,6 @@ need to be translated for each locale.--> <message name="IDS_MESSAGE_CENTER_TOOLTIP_UNREAD" desc="Tooltip for notification tray icon with unread notifications"> <ph name="product">$1<ex>Chrome</ex></ph> - Notifications (<ph name="QUANTITY">$2<ex>3</ex></ph> unread) </message> - <message name="IDS_MESSAGE_CENTER_SAMPLE_SYNCED_NOTIFICATION_SERVICE_NAME" desc="The name of the only source for synced notifications. TODO and note for translators: this text must be replaced by the real name by the branch point. See crbug.com/254617"> - Sample app - </message> <message name="IDS_MESSAGE_CENTER_NOTIFIER_SCREENSHOT_NAME" desc="The name of screenshot notifier that is a system componet"> Screenshot </message> |