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

Side by Side Diff: chrome/browser/status_icons/desktop_notification_balloon.cc

Issue 1387383004: Plumb NotifierId to status icon balloons (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@notif_cleanup
Patch Set: Rebase Created 5 years, 2 months 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/status_icons/desktop_notification_balloon.h" 5 #include "chrome/browser/status_icons/desktop_notification_balloon.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 15 matching lines...) Expand all
26 // The browser process may have gone away during shutting down, in this case 26 // The browser process may have gone away during shutting down, in this case
27 // notification_ui_manager() will close the balloon in its destructor. 27 // notification_ui_manager() will close the balloon in its destructor.
28 if (!g_browser_process) 28 if (!g_browser_process)
29 return; 29 return;
30 30
31 g_browser_process->notification_ui_manager()->CancelById(id, profile_id); 31 g_browser_process->notification_ui_manager()->CancelById(id, profile_id);
32 } 32 }
33 33
34 // Prefix added to the notification ids. 34 // Prefix added to the notification ids.
35 const char kNotificationPrefix[] = "desktop_notification_balloon."; 35 const char kNotificationPrefix[] = "desktop_notification_balloon.";
36 const char kNotifierId[] = "status-icons.desktop-notification-balloon";
37 36
38 // Timeout for automatically dismissing the notification balloon. 37 // Timeout for automatically dismissing the notification balloon.
39 const size_t kTimeoutSeconds = 6; 38 const size_t kTimeoutSeconds = 6;
40 39
41 class DummyNotificationDelegate : public NotificationDelegate { 40 class DummyNotificationDelegate : public NotificationDelegate {
42 public: 41 public:
43 explicit DummyNotificationDelegate(const std::string& id, Profile* profile) 42 explicit DummyNotificationDelegate(const std::string& id, Profile* profile)
44 : id_(kNotificationPrefix + id), profile_(profile) {} 43 : id_(kNotificationPrefix + id), profile_(profile) {}
45 44
46 void Display() override { 45 void Display() override {
(...skipping 20 matching lines...) Expand all
67 66
68 DesktopNotificationBalloon::~DesktopNotificationBalloon() { 67 DesktopNotificationBalloon::~DesktopNotificationBalloon() {
69 if (!notification_id_.empty()) 68 if (!notification_id_.empty())
70 CloseBalloon(notification_id_, 69 CloseBalloon(notification_id_,
71 NotificationUIManager::GetProfileID(profile_)); 70 NotificationUIManager::GetProfileID(profile_));
72 } 71 }
73 72
74 void DesktopNotificationBalloon::DisplayBalloon( 73 void DesktopNotificationBalloon::DisplayBalloon(
75 const gfx::ImageSkia& icon, 74 const gfx::ImageSkia& icon,
76 const base::string16& title, 75 const base::string16& title,
77 const base::string16& contents) { 76 const base::string16& contents,
77 const message_center::NotifierId& notifier_id) {
78 // Allowing IO access is required here to cover the corner case where 78 // Allowing IO access is required here to cover the corner case where
79 // there is no last used profile and the default one is loaded. 79 // there is no last used profile and the default one is loaded.
80 // IO access won't be required for normal uses. 80 // IO access won't be required for normal uses.
81 Profile* profile; 81 Profile* profile;
82 { 82 {
83 base::ThreadRestrictions::ScopedAllowIO allow_io; 83 base::ThreadRestrictions::ScopedAllowIO allow_io;
84 profile = ProfileManager::GetLastUsedProfile(); 84 profile = ProfileManager::GetLastUsedProfile();
85 } 85 }
86 86
87 NotificationDelegate* delegate = 87 NotificationDelegate* delegate =
88 new DummyNotificationDelegate(base::IntToString(id_count_++), profile_); 88 new DummyNotificationDelegate(base::IntToString(id_count_++), profile_);
89 // TODO(johnme): In theory the desktop notification balloon class can be used
90 // by lots of other features, which would not fall under a single system
91 // component id. So callers should pass in the notifier_id to be used here,
92 // see https://crbug.com/542232
93 Notification notification(message_center::NOTIFICATION_TYPE_SIMPLE, title, 89 Notification notification(message_center::NOTIFICATION_TYPE_SIMPLE, title,
94 contents, gfx::Image(icon), 90 contents, gfx::Image(icon), notifier_id, base::string16(), GURL(),
95 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT, 91 std::string(), message_center::RichNotificationData(), delegate);
96 kNotifierId),
97 base::string16(), GURL(), std::string(),
98 message_center::RichNotificationData(), delegate);
99 92
100 g_browser_process->notification_ui_manager()->Add(notification, profile); 93 g_browser_process->notification_ui_manager()->Add(notification, profile);
101 94
102 notification_id_ = notification.delegate_id(); 95 notification_id_ = notification.delegate_id();
103 profile_ = profile; 96 profile_ = profile;
104 } 97 }
OLDNEW
« no previous file with comments | « chrome/browser/status_icons/desktop_notification_balloon.h ('k') | chrome/browser/status_icons/status_icon.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698