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

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: Addressed Peter's review comments 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";
Peter Beverloo 2015/10/09 12:55:23 micro nit: alphabetise.
johnme 2015/10/09 14:20:41 Done.
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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // TODO(johnme): In theory the desktop notification balloon class can be
Peter Beverloo 2015/10/09 12:55:23 Please place this comment above the call, not in t
johnme 2015/10/09 14:20:41 Done (I linked directly to https://codereview.chro
92 // used by lots of other features, which would not fall under a single
93 // system component id. So callers should pass in the id to be used here.
94 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT,
95 kNotifierId),
96 base::string16(), GURL(), std::string(),
97 message_center::RichNotificationData(), delegate);
88 98
89 g_browser_process->notification_ui_manager()->Add(notification, profile); 99 g_browser_process->notification_ui_manager()->Add(notification, profile);
90 100
91 notification_id_ = notification.delegate_id(); 101 notification_id_ = notification.delegate_id();
92 profile_ = profile; 102 profile_ = profile;
93 } 103 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698