This source file includes following definitions.
- synced_notification_first_run_
- Shutdown
- MergeDataAndStartSyncing
- StopSyncing
- GetAllSyncData
- ProcessSyncChanges
- CreateSyncDataFromNotification
- CreateNotificationFromSyncData
- FindNotificationById
- FreeNotificationById
- GetSyncedNotificationServices
- OnAddedAppIds
- OnRemovedAppIds
- MarkNotificationAsRead
- Add
- GetSendingServiceId
- AddForTest
- SetSyncedNotificationAppInfoServiceForTest
- UpdateInMessageCenter
- Display
- OnSyncedNotificationServiceEnabled
- CollectPerServiceEnablingStatistics
- BuildServiceListValueInplace
- DisplayUnreadNotificationsFromSource
- RemoveUnreadNotificationsFromSource
- OnEnabledSendingServiceListPrefChanged
- OnInitializedSendingServiceListPrefChanged
- OnSyncedNotificationFirstRunBooleanPrefChanged
- RegisterProfilePrefs
- InitializePrefs
- ShowWelcomeToastIfNecessary
- FindAppInfoByAppId
- CreateWelcomeNotificationForService
#include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h"
#include <set>
#include <string>
#include <vector>
#include "base/command_line.h"
#include "base/guid.h"
#include "base/metrics/histogram.h"
#include "base/prefs/pref_service.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#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/notifications/sync_notifier/chrome_notifier_delegate.h"
#include "chrome/browser/notifications/sync_notifier/chrome_notifier_service_factory.h"
#include "chrome/browser/notifications/sync_notifier/synced_notification_app_info.h"
#include "chrome/browser/notifications/sync_notifier/synced_notification_app_info_service.h"
#include "chrome/browser/notifications/sync_notifier/synced_notification_app_info_service_factory.h"
#include "chrome/browser/notifications/sync_notifier/welcome_delegate.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/pref_names.h"
#include "components/user_prefs/pref_registry_syncable.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/user_metrics.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"
#include "sync/protocol/sync.pb.h"
#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"
using base::UserMetricsAction;
namespace notifier {
const char kFirstSyncedNotificationServiceId[] = "Google+";
const char kSyncedNotificationsWelcomeOrigin[] =
"synced-notifications://welcome";
bool ChromeNotifierService::avoid_bitmap_fetching_for_test_ = false;
ChromeNotifierService::ChromeNotifierService(Profile* profile,
NotificationUIManager* manager)
: profile_(profile),
notification_manager_(manager),
synced_notification_first_run_(false) {
InitializePrefs();
synced_notification_app_info_service_ =
SyncedNotificationAppInfoServiceFactory::GetForProfile(
profile_, Profile::IMPLICIT_ACCESS);
DCHECK(synced_notification_app_info_service_ != NULL);
synced_notification_app_info_service_->set_chrome_notifier_service(this);
}
ChromeNotifierService::~ChromeNotifierService() {
if (synced_notification_app_info_service_)
synced_notification_app_info_service_->set_chrome_notifier_service(NULL);
}
void ChromeNotifierService::Shutdown() {}
syncer::SyncMergeResult ChromeNotifierService::MergeDataAndStartSyncing(
syncer::ModelType type,
const syncer::SyncDataList& initial_sync_data,
scoped_ptr<syncer::SyncChangeProcessor> sync_processor,
scoped_ptr<syncer::SyncErrorFactory> error_handler) {
thread_checker_.CalledOnValidThread();
DCHECK_EQ(syncer::SYNCED_NOTIFICATIONS, type);
syncer::SyncMergeResult merge_result(syncer::SYNCED_NOTIFICATIONS);
syncer::SyncChangeList new_changes;
sync_processor_ = sync_processor.Pass();
for (syncer::SyncDataList::const_iterator it = initial_sync_data.begin();
it != initial_sync_data.end(); ++it) {
const syncer::SyncData& sync_data = *it;
DCHECK_EQ(syncer::SYNCED_NOTIFICATIONS, sync_data.GetDataType());
scoped_ptr<SyncedNotification> incoming(CreateNotificationFromSyncData(
sync_data));
if (!incoming) {
NOTREACHED();
continue;
}
const std::string& key = incoming->GetKey();
DCHECK_GT(key.length(), 0U);
SyncedNotification* found = FindNotificationById(key);
if (NULL == found) {
Add(incoming.Pass());
} else {
if (incoming->EqualsIgnoringReadState(*found)) {
if (incoming->GetReadState() == found->GetReadState()) {
continue;
} else {
if (incoming->GetReadState() == SyncedNotification::kDismissed) {
found->NotificationHasBeenDismissed();
notification_manager_->CancelById(found->GetKey());
} else if (incoming->GetReadState() == SyncedNotification::kRead) {
found->NotificationHasBeenRead();
notification_manager_->CancelById(found->GetKey());
} else {
syncer::SyncData sync_data = CreateSyncDataFromNotification(*found);
new_changes.push_back(
syncer::SyncChange(FROM_HERE,
syncer::SyncChange::ACTION_UPDATE,
sync_data));
}
}
} else {
found->Update(sync_data);
UpdateInMessageCenter(found);
}
}
}
if (new_changes.size() > 0) {
merge_result.set_error(sync_processor_->ProcessSyncChanges(
FROM_HERE, new_changes));
}
if (synced_notification_first_run_) {
synced_notification_first_run_ = false;
profile_->GetPrefs()->SetBoolean(prefs::kSyncedNotificationFirstRun, false);
}
return merge_result;
}
void ChromeNotifierService::StopSyncing(syncer::ModelType type) {
DCHECK_EQ(syncer::SYNCED_NOTIFICATIONS, type);
}
syncer::SyncDataList ChromeNotifierService::GetAllSyncData(
syncer::ModelType type) const {
DCHECK_EQ(syncer::SYNCED_NOTIFICATIONS, type);
syncer::SyncDataList sync_data;
ScopedVector<SyncedNotification>::const_iterator it =
notification_data_.begin();
for (; it != notification_data_.end(); ++it) {
sync_data.push_back(CreateSyncDataFromNotification(**it));
}
return sync_data;
}
syncer::SyncError ChromeNotifierService::ProcessSyncChanges(
const tracked_objects::Location& from_here,
const syncer::SyncChangeList& change_list) {
thread_checker_.CalledOnValidThread();
syncer::SyncError error;
for (syncer::SyncChangeList::const_iterator it = change_list.begin();
it != change_list.end(); ++it) {
syncer::SyncData sync_data = it->sync_data();
DCHECK_EQ(syncer::SYNCED_NOTIFICATIONS, sync_data.GetDataType());
syncer::SyncChange::SyncChangeType change_type = it->change_type();
scoped_ptr<SyncedNotification> new_notification(
CreateNotificationFromSyncData(sync_data));
if (!new_notification.get()) {
NOTREACHED() << "Failed to read notification.";
continue;
}
const std::string& key = new_notification->GetKey();
DCHECK_GT(key.length(), 0U);
SyncedNotification* found = FindNotificationById(key);
switch (change_type) {
case syncer::SyncChange::ACTION_ADD:
case syncer::SyncChange::ACTION_UPDATE:
if (found == NULL) {
Add(new_notification.Pass());
break;
}
found->Update(sync_data);
UpdateInMessageCenter(found);
break;
case syncer::SyncChange::ACTION_DELETE:
if (found == NULL) {
break;
}
FreeNotificationById(key);
UpdateInMessageCenter(new_notification.get());
break;
default:
NOTREACHED();
break;
}
}
return error;
}
syncer::SyncData ChromeNotifierService::CreateSyncDataFromNotification(
const SyncedNotification& notification) {
return syncer::SyncData::CreateLocalData(
notification.GetKey(), notification.GetKey(),
notification.GetEntitySpecifics());
}
scoped_ptr<SyncedNotification>
ChromeNotifierService::CreateNotificationFromSyncData(
const syncer::SyncData& sync_data) {
sync_pb::SyncedNotificationSpecifics specifics =
sync_data.GetSpecifics().synced_notification();
if (!specifics.has_coalesced_notification() ||
!specifics.coalesced_notification().has_key() ||
!specifics.coalesced_notification().has_read_state()) {
DVLOG(1) << "Synced Notification missing mandatory fields "
<< "has coalesced notification? "
<< specifics.has_coalesced_notification()
<< " has key? " << specifics.coalesced_notification().has_key()
<< " has read state? "
<< specifics.coalesced_notification().has_read_state();
return scoped_ptr<SyncedNotification>();
}
bool is_well_formed_unread_notification =
(static_cast<SyncedNotification::ReadState>(
specifics.coalesced_notification().read_state()) ==
SyncedNotification::kUnread &&
specifics.coalesced_notification().has_render_info());
bool is_well_formed_read_notification =
(static_cast<SyncedNotification::ReadState>(
specifics.coalesced_notification().read_state()) ==
SyncedNotification::kRead);
bool is_well_formed_dismissed_notification =
(static_cast<SyncedNotification::ReadState>(
specifics.coalesced_notification().read_state()) ==
SyncedNotification::kDismissed);
if (!is_well_formed_unread_notification &&
!is_well_formed_read_notification &&
!is_well_formed_dismissed_notification) {
DVLOG(1) << "Synced Notification is not well formed."
<< " unread well formed? "
<< is_well_formed_unread_notification
<< " dismissed well formed? "
<< is_well_formed_dismissed_notification
<< " read well formed? "
<< is_well_formed_read_notification;
return scoped_ptr<SyncedNotification>();
}
scoped_ptr<SyncedNotification> notification(
new SyncedNotification(sync_data, this, notification_manager_));
return notification.Pass();
}
SyncedNotification* ChromeNotifierService::FindNotificationById(
const std::string& notification_id) {
ScopedVector<SyncedNotification>::const_iterator it =
notification_data_.begin();
for (; it != notification_data_.end(); ++it) {
SyncedNotification* notification = *it;
if (notification_id == notification->GetKey())
return *it;
}
return NULL;
}
void ChromeNotifierService::FreeNotificationById(
const std::string& notification_id) {
ScopedVector<SyncedNotification>::iterator it = notification_data_.begin();
for (; it != notification_data_.end(); ++it) {
SyncedNotification* notification = *it;
if (notification_id == notification->GetKey()) {
notification_data_.erase(it);
return;
}
}
}
void ChromeNotifierService::GetSyncedNotificationServices(
std::vector<message_center::Notifier*>* notifiers) {
std::vector<SyncedNotificationSendingServiceSettingsData>
sending_service_settings_data;
if (synced_notification_app_info_service_ == NULL)
return;
sending_service_settings_data =
synced_notification_app_info_service_->GetAllSendingServiceSettingsData();
for (size_t ii = 0; ii < sending_service_settings_data.size(); ++ii) {
bool app_enabled = false;
std::set<std::string>::iterator iter;
iter = find(enabled_sending_services_.begin(),
enabled_sending_services_.end(),
sending_service_settings_data[ii].notifier_id.id);
app_enabled = iter != enabled_sending_services_.end();
message_center::Notifier* app_info_notifier = new message_center::Notifier(
sending_service_settings_data[ii].notifier_id,
base::UTF8ToUTF16(
sending_service_settings_data[ii].settings_display_name),
app_enabled);
app_info_notifier->icon = sending_service_settings_data[ii].settings_icon;
notifiers->push_back(app_info_notifier);
}
}
void ChromeNotifierService::OnAddedAppIds(
std::vector<std::string> added_app_ids) {
std::vector<std::string>::const_iterator app_id_iter;
for (app_id_iter = added_app_ids.begin(); app_id_iter != added_app_ids.end();
++app_id_iter) {
std::set<std::string>::iterator sending_service_iter;
sending_service_iter = enabled_sending_services_.find(*app_id_iter);
if (sending_service_iter != enabled_sending_services_.end())
continue;
ScopedVector<SyncedNotification>::iterator notification_iter;
for (notification_iter = notification_data_.begin();
notification_iter != notification_data_.end();
++notification_iter) {
(*notification_iter)->ShowAllForAppId(profile_, *app_id_iter);
}
}
}
void ChromeNotifierService::OnRemovedAppIds(
std::vector<std::string> removed_app_ids) {
std::vector<std::string>::const_iterator app_id_iter;
for (app_id_iter = removed_app_ids.begin();
app_id_iter != removed_app_ids.end();
++app_id_iter) {
ScopedVector<SyncedNotification>::iterator notification_iter;
for (notification_iter = notification_data_.begin();
notification_iter != notification_data_.end();
++notification_iter) {
(*notification_iter)->HideAllForAppId(*app_id_iter);
}
}
}
void ChromeNotifierService::MarkNotificationAsRead(
const std::string& key) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
SyncedNotification* notification = FindNotificationById(key);
CHECK(notification != NULL);
notification->NotificationHasBeenRead();
syncer::SyncChangeList new_changes;
syncer::SyncData sync_data = CreateSyncDataFromNotification(*notification);
new_changes.push_back(
syncer::SyncChange(FROM_HERE,
syncer::SyncChange::ACTION_UPDATE,
sync_data));
sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes);
}
void ChromeNotifierService::Add(scoped_ptr<SyncedNotification> notification) {
SyncedNotification* notification_copy = notification.get();
notification_data_.push_back(notification.release());
std::string sending_service_id = GetSendingServiceId(notification_copy);
std::set<std::string>::iterator iter = find(enabled_sending_services_.begin(),
enabled_sending_services_.end(),
sending_service_id);
if (iter == enabled_sending_services_.end()) {
iter = find(initialized_sending_services_.begin(),
initialized_sending_services_.end(),
sending_service_id);
if (iter != initialized_sending_services_.end())
return;
}
UpdateInMessageCenter(notification_copy);
}
std::string ChromeNotifierService::GetSendingServiceId(
const SyncedNotification* synced_notification) {
std::string app_id = synced_notification->GetAppId();
DCHECK(synced_notification_app_info_service_ != NULL);
return synced_notification_app_info_service_->FindSendingServiceNameFromAppId(
app_id);
}
void ChromeNotifierService::AddForTest(
scoped_ptr<notifier::SyncedNotification> notification) {
notification_data_.push_back(notification.release());
}
void ChromeNotifierService::SetSyncedNotificationAppInfoServiceForTest(
SyncedNotificationAppInfoService* synced_notification_app_info_service) {
if (synced_notification_app_info_service_)
synced_notification_app_info_service_->set_chrome_notifier_service(NULL);
synced_notification_app_info_service_ = synced_notification_app_info_service;
synced_notification_app_info_service_->set_chrome_notifier_service(this);
}
void ChromeNotifierService::UpdateInMessageCenter(
SyncedNotification* notification) {
if (!notifier::ChromeNotifierServiceFactory::UseSyncedNotifications(
CommandLine::ForCurrentProcess()))
return;
notification->LogNotification();
if (notification->GetReadState() == SyncedNotification::kUnread) {
Display(notification);
} else {
notification_manager_->CancelById(notification->GetKey());
}
}
void ChromeNotifierService::Display(SyncedNotification* notification) {
if (synced_notification_first_run_) {
notification->set_toast_state(false);
}
if (avoid_bitmap_fetching_for_test_) {
notification->Show(profile_);
return;
}
notification->QueueBitmapFetchJobs(this, profile_);
notification->StartBitmapFetch();
}
void ChromeNotifierService::OnSyncedNotificationServiceEnabled(
const std::string& notifier_id, bool enabled) {
std::set<std::string>::iterator iter;
std::string notifier_id_copy(notifier_id);
iter = find(enabled_sending_services_.begin(),
enabled_sending_services_.end(),
notifier_id_copy);
base::ListValue synced_notification_services;
if (iter == enabled_sending_services_.end() && enabled) {
enabled_sending_services_.insert(notifier_id_copy);
DisplayUnreadNotificationsFromSource(notifier_id);
BuildServiceListValueInplace(enabled_sending_services_,
&synced_notification_services);
profile_->GetPrefs()->Set(prefs::kEnabledSyncedNotificationSendingServices,
synced_notification_services);
} else if (iter != enabled_sending_services_.end() && !enabled) {
enabled_sending_services_.erase(iter);
BuildServiceListValueInplace(enabled_sending_services_,
&synced_notification_services);
profile_->GetPrefs()->Set(prefs::kEnabledSyncedNotificationSendingServices,
synced_notification_services);
RemoveUnreadNotificationsFromSource(notifier_id_copy);
}
if (enabled) {
content::RecordAction(
UserMetricsAction("SyncedNotifications.SendingServiceEnabled"));
} else {
content::RecordAction(
UserMetricsAction("SyncedNotifications.SendingServiceDisabled"));
}
CollectPerServiceEnablingStatistics(notifier_id, enabled);
return;
}
void ChromeNotifierService::CollectPerServiceEnablingStatistics(
const std::string& notifier_id,
bool enabled) {
ChromeNotifierServiceActionType action =
CHROME_NOTIFIER_SERVICE_ACTION_UNKNOWN;
if (notifier_id == std::string(kFirstSyncedNotificationServiceId)) {
action = enabled
? CHROME_NOTIFIER_SERVICE_ACTION_FIRST_SERVICE_ENABLED
: CHROME_NOTIFIER_SERVICE_ACTION_FIRST_SERVICE_DISABLED;
}
UMA_HISTOGRAM_ENUMERATION("ChromeNotifierService.Actions",
action,
CHROME_NOTIFIER_SERVICE_ACTION_COUNT);
}
void ChromeNotifierService::BuildServiceListValueInplace(
std::set<std::string> services, base::ListValue* list_value) {
std::set<std::string>::iterator iter;
for (iter = services.begin();
iter != services.end();
++iter) {
base::StringValue* string_value(new base::StringValue(*iter));
list_value->Append(string_value);
}
}
void ChromeNotifierService::DisplayUnreadNotificationsFromSource(
const std::string& notifier_id) {
for (std::vector<SyncedNotification*>::const_iterator iter =
notification_data_.begin();
iter != notification_data_.end();
++iter) {
if (GetSendingServiceId(*iter) == notifier_id &&
(*iter)->GetReadState() == SyncedNotification::kUnread)
Display(*iter);
}
}
void ChromeNotifierService::RemoveUnreadNotificationsFromSource(
const std::string& notifier_id) {
for (std::vector<SyncedNotification*>::const_iterator iter =
notification_data_.begin();
iter != notification_data_.end();
++iter) {
if (GetSendingServiceId(*iter) == notifier_id &&
(*iter)->GetReadState() == SyncedNotification::kUnread) {
notification_manager_->CancelById((*iter)->GetKey());
}
}
}
void ChromeNotifierService::OnEnabledSendingServiceListPrefChanged(
std::set<std::string>* ids_field) {
ids_field->clear();
const std::vector<std::string> pref_list =
enabled_sending_services_prefs_.GetValue();
for (size_t i = 0; i < pref_list.size(); ++i) {
std::string element = pref_list[i];
if (!element.empty())
ids_field->insert(element);
else
LOG(WARNING) << i << "-th element is not a string "
<< prefs::kEnabledSyncedNotificationSendingServices;
}
}
void ChromeNotifierService::OnInitializedSendingServiceListPrefChanged(
std::set<std::string>* ids_field) {
ids_field->clear();
const std::vector<std::string> pref_list =
initialized_sending_services_prefs_.GetValue();
for (size_t i = 0; i < pref_list.size(); ++i) {
std::string element = pref_list[i];
if (!element.empty())
ids_field->insert(element);
else
LOG(WARNING) << i << "-th element is not a string for "
<< prefs::kInitializedSyncedNotificationSendingServices;
}
}
void ChromeNotifierService::OnSyncedNotificationFirstRunBooleanPrefChanged(
bool* new_value) {
synced_notification_first_run_ = *new_value;
}
void ChromeNotifierService::RegisterProfilePrefs(
user_prefs::PrefRegistrySyncable* registry) {
registry->RegisterListPref(
prefs::kEnabledSyncedNotificationSendingServices,
user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
registry->RegisterListPref(
prefs::kInitializedSyncedNotificationSendingServices,
user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
registry->RegisterBooleanPref(
prefs::kSyncedNotificationFirstRun, true,
user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
}
void ChromeNotifierService::InitializePrefs() {
enabled_sending_services_prefs_.Init(
prefs::kEnabledSyncedNotificationSendingServices,
profile_->GetPrefs(),
base::Bind(
&ChromeNotifierService::OnEnabledSendingServiceListPrefChanged,
base::Unretained(this),
base::Unretained(&enabled_sending_services_)));
initialized_sending_services_prefs_.Init(
prefs::kInitializedSyncedNotificationSendingServices,
profile_->GetPrefs(),
base::Bind(
&ChromeNotifierService::OnInitializedSendingServiceListPrefChanged,
base::Unretained(this),
base::Unretained(&initialized_sending_services_)));
synced_notification_first_run_prefs_.Init(
prefs::kSyncedNotificationFirstRun,
profile_->GetPrefs(),
base::Bind(
&ChromeNotifierService::
OnSyncedNotificationFirstRunBooleanPrefChanged,
base::Unretained(this),
base::Unretained(&synced_notification_first_run_)));
OnEnabledSendingServiceListPrefChanged(&enabled_sending_services_);
OnInitializedSendingServiceListPrefChanged(&initialized_sending_services_);
synced_notification_first_run_ =
profile_->GetPrefs()->GetBoolean(prefs::kSyncedNotificationFirstRun);
}
void ChromeNotifierService::ShowWelcomeToastIfNecessary(
const SyncedNotification* synced_notification,
NotificationUIManager* notification_ui_manager) {
const std::string& sending_service_id =
GetSendingServiceId(synced_notification);
std::set<std::string>::iterator iter;
iter = find(initialized_sending_services_.begin(),
initialized_sending_services_.end(),
sending_service_id);
if (iter != initialized_sending_services_.end())
return;
notifier::SyncedNotificationAppInfo* app_info =
FindAppInfoByAppId(synced_notification->GetAppId());
if (!app_info)
return;
if (app_info->settings_icon_url().is_empty()) {
gfx::Image notification_app_icon = synced_notification->GetAppIcon();
if (notification_app_icon.IsEmpty()) {
DVLOG(1) << "Unable to find the app icon for the welcome notification. "
<< "Service ID: " << sending_service_id;
}
}
message_center::NotifierId notifier_id(
message_center::NotifierId::SYNCED_NOTIFICATION_SERVICE,
sending_service_id);
Notification notification = CreateWelcomeNotificationForService(app_info);
notification_ui_manager->Add(notification, profile_);
enabled_sending_services_.insert(sending_service_id);
initialized_sending_services_.insert(sending_service_id);
base::ListValue enabled_sending_services;
base::ListValue initialized_sending_services;
BuildServiceListValueInplace(enabled_sending_services_,
&enabled_sending_services);
profile_->GetPrefs()->Set(prefs::kEnabledSyncedNotificationSendingServices,
enabled_sending_services);
BuildServiceListValueInplace(initialized_sending_services_,
&initialized_sending_services);
profile_->GetPrefs()->Set(
prefs::kInitializedSyncedNotificationSendingServices,
initialized_sending_services);
}
notifier::SyncedNotificationAppInfo* ChromeNotifierService::FindAppInfoByAppId(
const std::string& app_id) const {
if (NULL == synced_notification_app_info_service_)
return NULL;
return synced_notification_app_info_service_->
FindSyncedNotificationAppInfoByAppId(app_id);
}
const Notification ChromeNotifierService::CreateWelcomeNotificationForService(
SyncedNotificationAppInfo* app_info) {
std::string welcome_notification_id = base::GenerateGUID();
message_center::NotifierId notifier_id = app_info->GetNotifierId();
scoped_refptr<WelcomeDelegate> delegate(
new WelcomeDelegate(welcome_notification_id, profile_, notifier_id));
message_center::ButtonInfo button_info(
l10n_util::GetStringUTF16(IDS_NOTIFIER_WELCOME_BUTTON));
button_info.icon = ui::ResourceBundle::GetSharedInstance().GetImageNamed(
IDR_NOTIFIER_BLOCK_BUTTON);
message_center::RichNotificationData rich_notification_data;
rich_notification_data.buttons.push_back(button_info);
return Notification(
message_center::NOTIFICATION_TYPE_BASE_FORMAT,
GURL(kSyncedNotificationsWelcomeOrigin),
base::UTF8ToUTF16(app_info->settings_display_name()),
l10n_util::GetStringUTF16(IDS_NOTIFIER_WELCOME_BODY),
app_info->icon(),
blink::WebTextDirectionDefault,
notifier_id,
l10n_util::GetStringUTF16(IDS_NOTIFICATION_WELCOME_DISPLAY_SOURCE),
base::UTF8ToUTF16(welcome_notification_id),
rich_notification_data,
delegate.get());
}
}