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

Side by Side Diff: chrome/browser/printing/cloud_print/privet_notifications.cc

Issue 2446043002: Close privet printer notifications when clicked. (Closed)
Patch Set: Created 4 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/printing/cloud_print/privet_notifications.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/printing/cloud_print/privet_notifications.h" 5 #include "chrome/browser/printing/cloud_print/privet_notifications.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 message_center::ButtonInfo(l10n_util::GetStringUTF16( 248 message_center::ButtonInfo(l10n_util::GetStringUTF16(
249 IDS_LOCAL_DISCOVERY_NOTIFICATIONS_DISABLE_BUTTON_LABEL))); 249 IDS_LOCAL_DISCOVERY_NOTIFICATIONS_DISABLE_BUTTON_LABEL)));
250 250
251 base::string16 title = l10n_util::GetPluralStringFUTF16( 251 base::string16 title = l10n_util::GetPluralStringFUTF16(
252 IDS_LOCAL_DISCOVERY_NOTIFICATION_TITLE_PRINTER, devices_active); 252 IDS_LOCAL_DISCOVERY_NOTIFICATION_TITLE_PRINTER, devices_active);
253 base::string16 body = l10n_util::GetPluralStringFUTF16( 253 base::string16 body = l10n_util::GetPluralStringFUTF16(
254 IDS_LOCAL_DISCOVERY_NOTIFICATION_CONTENTS_PRINTER, devices_active); 254 IDS_LOCAL_DISCOVERY_NOTIFICATION_CONTENTS_PRINTER, devices_active);
255 base::string16 product_name = 255 base::string16 product_name =
256 l10n_util::GetStringUTF16(IDS_LOCAL_DISCOVERY_SERVICE_NAME_PRINTER); 256 l10n_util::GetStringUTF16(IDS_LOCAL_DISCOVERY_SERVICE_NAME_PRINTER);
257 257
258 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.
258 Notification notification( 259 Notification notification(
259 message_center::NOTIFICATION_TYPE_SIMPLE, title, body, 260 message_center::NOTIFICATION_TYPE_SIMPLE, title, body,
260 ui::ResourceBundle::GetSharedInstance().GetImageNamed( 261 ui::ResourceBundle::GetSharedInstance().GetImageNamed(
261 IDR_LOCAL_DISCOVERY_CLOUDPRINT_ICON), 262 IDR_LOCAL_DISCOVERY_CLOUDPRINT_ICON),
262 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT, 263 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT,
263 kPrivetNotificationID), 264 kPrivetNotificationID),
264 product_name, GURL(kPrivetNotificationOriginUrl), kPrivetNotificationID, 265 product_name, GURL(kPrivetNotificationOriginUrl), kPrivetNotificationID,
265 rich_notification_data, new PrivetNotificationDelegate(profile_)); 266 rich_notification_data, new PrivetNotificationDelegate(profile));
266 267
267 auto* notification_ui_manager = g_browser_process->notification_ui_manager(); 268 auto* notification_ui_manager = g_browser_process->notification_ui_manager();
268 Profile* profile = Profile::FromBrowserContext(profile_);
269 bool updated = notification_ui_manager->Update(notification, profile); 269 bool updated = notification_ui_manager->Update(notification, profile);
270 if (!updated && added && 270 if (!updated && added &&
271 !local_discovery::LocalDiscoveryUIHandler::GetHasVisible()) { 271 !local_discovery::LocalDiscoveryUIHandler::GetHasVisible()) {
272 ReportPrivetUmaEvent(PRIVET_NOTIFICATION_SHOWN); 272 ReportPrivetUmaEvent(PRIVET_NOTIFICATION_SHOWN);
273 notification_ui_manager->Add(notification, profile); 273 notification_ui_manager->Add(notification, profile);
274 } 274 }
275 } 275 }
276 276
277 void PrivetNotificationService::PrivetRemoveNotification() { 277 void PrivetNotificationService::PrivetRemoveNotification() {
278 ReportPrivetUmaEvent(PRIVET_NOTIFICATION_CANCELED); 278 ReportPrivetUmaEvent(PRIVET_NOTIFICATION_CANCELED);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 342
343 std::unique_ptr<PrivetHTTPAsynchronousFactory> http_factory( 343 std::unique_ptr<PrivetHTTPAsynchronousFactory> http_factory(
344 PrivetHTTPAsynchronousFactory::CreateInstance( 344 PrivetHTTPAsynchronousFactory::CreateInstance(
345 content::BrowserContext::GetDefaultStoragePartition(profile_)-> 345 content::BrowserContext::GetDefaultStoragePartition(profile_)->
346 GetURLRequestContext())); 346 GetURLRequestContext()));
347 347
348 privet_notifications_listener_.reset( 348 privet_notifications_listener_.reset(
349 new PrivetNotificationsListener(std::move(http_factory), this)); 349 new PrivetNotificationsListener(std::move(http_factory), this));
350 } 350 }
351 351
352 PrivetNotificationDelegate::PrivetNotificationDelegate( 352 PrivetNotificationDelegate::PrivetNotificationDelegate(Profile* profile)
353 content::BrowserContext* profile) 353 : profile_(profile) {
354 : profile_(profile) {
355 } 354 }
356 355
357 PrivetNotificationDelegate::~PrivetNotificationDelegate() { 356 PrivetNotificationDelegate::~PrivetNotificationDelegate() {
358 } 357 }
359 358
360 std::string PrivetNotificationDelegate::id() const { 359 std::string PrivetNotificationDelegate::id() const {
361 return kPrivetNotificationID; 360 return kPrivetNotificationID;
362 } 361 }
363 362
364 void PrivetNotificationDelegate::ButtonClick(int button_index) { 363 void PrivetNotificationDelegate::ButtonClick(int button_index) {
364 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
365
365 if (button_index == 0) { 366 if (button_index == 0) {
366 ReportPrivetUmaEvent(PRIVET_NOTIFICATION_CLICKED); 367 ReportPrivetUmaEvent(PRIVET_NOTIFICATION_CLICKED);
367 OpenTab(GURL(kPrivetNotificationOriginUrl)); 368 OpenTab(GURL(kPrivetNotificationOriginUrl));
368 return; 369 return;
369 } 370 }
370 371
371 DCHECK_EQ(1, button_index); 372 DCHECK_EQ(1, button_index);
372 ReportPrivetUmaEvent(PRIVET_DISABLE_NOTIFICATIONS_CLICKED); 373 ReportPrivetUmaEvent(PRIVET_DISABLE_NOTIFICATIONS_CLICKED);
373 DisableNotifications(); 374 DisableNotifications();
374 } 375 }
375 376
376 void PrivetNotificationDelegate::OpenTab(const GURL& url) { 377 void PrivetNotificationDelegate::OpenTab(const GURL& url) {
377 Profile* profile = Profile::FromBrowserContext(profile_); 378 chrome::NavigateParams params(profile_, url,
378 chrome::NavigateParams params(profile, url,
379 ui::PAGE_TRANSITION_AUTO_TOPLEVEL); 379 ui::PAGE_TRANSITION_AUTO_TOPLEVEL);
380 params.disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB; 380 params.disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB;
381 chrome::Navigate(&params); 381 chrome::Navigate(&params);
382 } 382 }
383 383
384 void PrivetNotificationDelegate::DisableNotifications() { 384 void PrivetNotificationDelegate::DisableNotifications() {
385 Profile* profile = Profile::FromBrowserContext(profile_); 385 profile_->GetPrefs()->SetBoolean(prefs::kLocalDiscoveryNotificationsEnabled,
386 profile->GetPrefs()->SetBoolean(prefs::kLocalDiscoveryNotificationsEnabled, 386 false);
387 false); 387 }
388
389 void PrivetNotificationDelegate::CloseNotification() {
390 g_browser_process->notification_ui_manager()->CancelById(
391 id(), NotificationUIManager::GetProfileID(profile_));
388 } 392 }
389 393
390 } // namespace cloud_print 394 } // namespace cloud_print
OLDNEW
« no previous file with comments | « chrome/browser/printing/cloud_print/privet_notifications.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698