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

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

Issue 1395093002: Fix system notifications incorrectly marked as type WEB_PAGE (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@timeout
Patch Set: 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"
11 #include "base/thread_task_runner_handle.h" 11 #include "base/thread_task_runner_handle.h"
12 #include "base/threading/thread_restrictions.h" 12 #include "base/threading/thread_restrictions.h"
13 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/notifications/notification.h" 14 #include "chrome/browser/notifications/notification.h"
15 #include "chrome/browser/notifications/notification_delegate.h" 15 #include "chrome/browser/notifications/notification_delegate.h"
16 #include "chrome/browser/notifications/notification_ui_manager.h" 16 #include "chrome/browser/notifications/notification_ui_manager.h"
17 #include "chrome/browser/profiles/profile_manager.h" 17 #include "chrome/browser/profiles/profile_manager.h"
18 #include "third_party/skia/include/core/SkBitmap.h" 18 #include "third_party/skia/include/core/SkBitmap.h"
19 #include "ui/gfx/image/image_skia.h" 19 #include "ui/gfx/image/image_skia.h"
20 #include "ui/message_center/notification_types.h"
21 #include "ui/message_center/notifier_settings.h"
20 22
21 namespace { 23 namespace {
22 24
23 void CloseBalloon(const std::string& id, ProfileID profile_id) { 25 void CloseBalloon(const std::string& id, ProfileID profile_id) {
24 // 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
25 // notification_ui_manager() will close the balloon in its destructor. 27 // notification_ui_manager() will close the balloon in its destructor.
26 if (!g_browser_process) 28 if (!g_browser_process)
27 return; 29 return;
28 30
29 g_browser_process->notification_ui_manager()->CancelById(id, profile_id); 31 g_browser_process->notification_ui_manager()->CancelById(id, profile_id);
30 } 32 }
31 33
32 // Prefix added to the notification ids. 34 // Prefix added to the notification ids.
35 const char kNotifierId[] = "status-icons.desktop-notification-balloon";
33 const char kNotificationPrefix[] = "desktop_notification_balloon."; 36 const char kNotificationPrefix[] = "desktop_notification_balloon.";
34 37
35 // Timeout for automatically dismissing the notification balloon. 38 // Timeout for automatically dismissing the notification balloon.
36 const size_t kTimeoutSeconds = 6; 39 const size_t kTimeoutSeconds = 6;
37 40
38 class DummyNotificationDelegate : public NotificationDelegate { 41 class DummyNotificationDelegate : public NotificationDelegate {
39 public: 42 public:
40 explicit DummyNotificationDelegate(const std::string& id, Profile* profile) 43 explicit DummyNotificationDelegate(const std::string& id, Profile* profile)
41 : id_(kNotificationPrefix + id), profile_(profile) {} 44 : id_(kNotificationPrefix + id), profile_(profile) {}
42 45
(...skipping 18 matching lines...) Expand all
61 64
62 DesktopNotificationBalloon::DesktopNotificationBalloon() : profile_(NULL) { 65 DesktopNotificationBalloon::DesktopNotificationBalloon() : profile_(NULL) {
63 } 66 }
64 67
65 DesktopNotificationBalloon::~DesktopNotificationBalloon() { 68 DesktopNotificationBalloon::~DesktopNotificationBalloon() {
66 if (!notification_id_.empty()) 69 if (!notification_id_.empty())
67 CloseBalloon(notification_id_, 70 CloseBalloon(notification_id_,
68 NotificationUIManager::GetProfileID(profile_)); 71 NotificationUIManager::GetProfileID(profile_));
69 } 72 }
70 73
71 void DesktopNotificationBalloon::DisplayBalloon( 74 void DesktopNotificationBalloon::DisplayBalloon(
Peter Beverloo 2015/10/09 10:47:30 Heh, this class only seems to be used for backgrou
72 const gfx::ImageSkia& icon, 75 const gfx::ImageSkia& icon,
73 const base::string16& title, 76 const base::string16& title,
74 const base::string16& contents) { 77 const base::string16& contents) {
75 // 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
76 // 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.
77 // IO access won't be required for normal uses. 80 // IO access won't be required for normal uses.
78 Profile* profile; 81 Profile* profile;
79 { 82 {
80 base::ThreadRestrictions::ScopedAllowIO allow_io; 83 base::ThreadRestrictions::ScopedAllowIO allow_io;
81 profile = ProfileManager::GetLastUsedProfile(); 84 profile = ProfileManager::GetLastUsedProfile();
82 } 85 }
83 86
84 NotificationDelegate* delegate = 87 DummyNotificationDelegate* delegate =
85 new DummyNotificationDelegate(base::IntToString(id_count_++), profile_); 88 new DummyNotificationDelegate(base::IntToString(id_count_++), profile_);
86 Notification notification(GURL(), title, contents, gfx::Image(icon), 89 Notification notification(message_center::NOTIFICATION_TYPE_SIMPLE, title,
87 base::string16(), std::string(), delegate); 90 contents, gfx::Image(icon),
91 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT,
92 kNotifierId),
Peter Beverloo 2015/10/09 10:47:30 This is not great. Theoretically the desktop notif
johnme 2015/10/09 11:21:02 Added TODO explaining this.
93 base::string16(), GURL(), std::string(),
94 message_center::RichNotificationData(), delegate);
88 95
89 g_browser_process->notification_ui_manager()->Add(notification, profile); 96 g_browser_process->notification_ui_manager()->Add(notification, profile);
90 97
91 notification_id_ = notification.delegate_id(); 98 notification_id_ = notification.delegate_id();
92 profile_ = profile; 99 profile_ = profile;
93 } 100 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698