Chromium Code Reviews| Index: chrome/browser/printing/cloud_print/privet_notifications.cc |
| diff --git a/chrome/browser/printing/cloud_print/privet_notifications.cc b/chrome/browser/printing/cloud_print/privet_notifications.cc |
| index d7eb4e9c691efe352c8e562449b71062b8a4a10e..784e8a3c782c6e4d3a0489488ad0f36bb8972ba2 100644 |
| --- a/chrome/browser/printing/cloud_print/privet_notifications.cc |
| +++ b/chrome/browser/printing/cloud_print/privet_notifications.cc |
| @@ -255,6 +255,7 @@ void PrivetNotificationService::PrivetNotify(int devices_active, |
| base::string16 product_name = |
| l10n_util::GetStringUTF16(IDS_LOCAL_DISCOVERY_SERVICE_NAME_PRINTER); |
| + Profile* profile = Profile::FromBrowserContext(profile_); |
|
dewittj
2016/10/25 20:08:30
if you are storing |profile_| as a Profile*, why i
Lei Zhang
2016/10/25 22:22:52
This is PrivetNotificationService, not PrivetNotif
dewittj
2016/10/25 23:35:56
Acknowledged.
|
| Notification notification( |
| message_center::NOTIFICATION_TYPE_SIMPLE, title, body, |
| ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
| @@ -262,10 +263,9 @@ void PrivetNotificationService::PrivetNotify(int devices_active, |
| message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT, |
| kPrivetNotificationID), |
| product_name, GURL(kPrivetNotificationOriginUrl), kPrivetNotificationID, |
| - rich_notification_data, new PrivetNotificationDelegate(profile_)); |
| + rich_notification_data, new PrivetNotificationDelegate(profile)); |
| auto* notification_ui_manager = g_browser_process->notification_ui_manager(); |
| - Profile* profile = Profile::FromBrowserContext(profile_); |
| bool updated = notification_ui_manager->Update(notification, profile); |
| if (!updated && added && |
| !local_discovery::LocalDiscoveryUIHandler::GetHasVisible()) { |
| @@ -349,9 +349,8 @@ void PrivetNotificationService::StartLister() { |
| new PrivetNotificationsListener(std::move(http_factory), this)); |
| } |
| -PrivetNotificationDelegate::PrivetNotificationDelegate( |
| - content::BrowserContext* profile) |
| - : profile_(profile) { |
| +PrivetNotificationDelegate::PrivetNotificationDelegate(Profile* profile) |
| + : profile_(profile) { |
| } |
| PrivetNotificationDelegate::~PrivetNotificationDelegate() { |
| @@ -362,6 +361,8 @@ std::string PrivetNotificationDelegate::id() const { |
| } |
| void PrivetNotificationDelegate::ButtonClick(int button_index) { |
| + CloseNotification(); |
|
dewittj
2016/10/25 20:08:30
Since I don't know the details of this particular
Lei Zhang
2016/10/25 22:22:52
Can you help me understand what the issue(s) are w
dewittj
2016/10/25 23:35:56
-warming up cache-
NotificationDelegate is refcou
|
| + |
| if (button_index == 0) { |
| ReportPrivetUmaEvent(PRIVET_NOTIFICATION_CLICKED); |
| OpenTab(GURL(kPrivetNotificationOriginUrl)); |
| @@ -374,17 +375,20 @@ void PrivetNotificationDelegate::ButtonClick(int button_index) { |
| } |
| void PrivetNotificationDelegate::OpenTab(const GURL& url) { |
| - Profile* profile = Profile::FromBrowserContext(profile_); |
| - chrome::NavigateParams params(profile, url, |
| + chrome::NavigateParams params(profile_, url, |
| ui::PAGE_TRANSITION_AUTO_TOPLEVEL); |
| params.disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB; |
| chrome::Navigate(¶ms); |
| } |
| void PrivetNotificationDelegate::DisableNotifications() { |
| - Profile* profile = Profile::FromBrowserContext(profile_); |
| - profile->GetPrefs()->SetBoolean(prefs::kLocalDiscoveryNotificationsEnabled, |
| - false); |
| + profile_->GetPrefs()->SetBoolean(prefs::kLocalDiscoveryNotificationsEnabled, |
| + false); |
| +} |
| + |
| +void PrivetNotificationDelegate::CloseNotification() { |
| + g_browser_process->notification_ui_manager()->CancelById( |
| + id(), NotificationUIManager::GetProfileID(profile_)); |
| } |
| } // namespace cloud_print |