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

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: Fix typo 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.
33 const char kNotificationPrefix[] = "desktop_notification_balloon."; 35 const char kNotificationPrefix[] = "desktop_notification_balloon.";
36 const char kNotifierId[] = "status-icons.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
43 void Display() override { 46 void Display() override {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 NotificationDelegate* 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 // TODO(johnme): In theory the desktop notification balloon class can be used
87 base::string16(), std::string(), delegate); 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,
94 contents, gfx::Image(icon),
95 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT,
96 kNotifierId),
97 base::string16(), GURL(), std::string(),
98 message_center::RichNotificationData(), delegate);
88 99
89 g_browser_process->notification_ui_manager()->Add(notification, profile); 100 g_browser_process->notification_ui_manager()->Add(notification, profile);
90 101
91 notification_id_ = notification.delegate_id(); 102 notification_id_ = notification.delegate_id();
92 profile_ = profile; 103 profile_ = profile;
93 } 104 }
OLDNEW
« no previous file with comments | « chrome/browser/notifications/platform_notification_service_impl.cc ('k') | ui/message_center/message_center_style.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698