OLD | NEW |
---|---|
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/notifications/message_center_notification_manager.h" | 5 #include "chrome/browser/notifications/message_center_notification_manager.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/command_line.h" | |
10 #include "base/logging.h" | 11 #include "base/logging.h" |
11 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
12 #include "build/build_config.h" | 13 #include "build/build_config.h" |
13 #include "chrome/browser/notifications/extension_welcome_notification.h" | 14 #include "chrome/browser/notifications/extension_welcome_notification.h" |
14 #include "chrome/browser/notifications/extension_welcome_notification_factory.h" | 15 #include "chrome/browser/notifications/extension_welcome_notification_factory.h" |
15 #include "chrome/browser/notifications/fullscreen_notification_blocker.h" | 16 #include "chrome/browser/notifications/fullscreen_notification_blocker.h" |
16 #include "chrome/browser/notifications/message_center_settings_controller.h" | 17 #include "chrome/browser/notifications/message_center_settings_controller.h" |
17 #include "chrome/browser/notifications/notification.h" | 18 #include "chrome/browser/notifications/notification.h" |
18 #include "chrome/browser/notifications/profile_notification.h" | 19 #include "chrome/browser/notifications/profile_notification.h" |
19 #include "chrome/browser/notifications/screen_lock_notification_blocker.h" | 20 #include "chrome/browser/notifications/screen_lock_notification_blocker.h" |
20 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
22 #include "chrome/common/chrome_switches.h" | |
21 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
22 #include "content/public/common/url_constants.h" | 24 #include "content/public/common/url_constants.h" |
23 #include "extensions/browser/extension_registry.h" | 25 #include "extensions/browser/extension_registry.h" |
24 #include "extensions/common/extension_set.h" | 26 #include "extensions/common/extension_set.h" |
25 #include "extensions/common/permissions/permissions_data.h" | 27 #include "extensions/common/permissions/permissions_data.h" |
26 #include "ui/gfx/image/image_skia.h" | 28 #include "ui/gfx/image/image_skia.h" |
27 #include "ui/message_center/message_center_style.h" | 29 #include "ui/message_center/message_center_style.h" |
28 #include "ui/message_center/message_center_tray.h" | 30 #include "ui/message_center/message_center_tray.h" |
29 #include "ui/message_center/message_center_types.h" | 31 #include "ui/message_center/message_center_types.h" |
30 #include "ui/message_center/notifier_settings.h" | 32 #include "ui/message_center/notifier_settings.h" |
31 | 33 |
32 #if defined(OS_CHROMEOS) | 34 #if defined(OS_CHROMEOS) |
33 #include "chrome/browser/notifications/login_state_notification_blocker_chromeos .h" | 35 #include "chrome/browser/notifications/login_state_notification_blocker_chromeos .h" |
34 #endif | 36 #endif |
35 | 37 |
36 #if defined(USE_ASH) | 38 #if defined(USE_ASH) |
37 #include "ash/common/system/web_notification/web_notification_tray.h" | 39 #include "ash/common/system/web_notification/web_notification_tray.h" |
38 #include "ash/shell.h" | 40 #include "ash/shell.h" |
39 #endif | 41 #endif |
40 | 42 |
43 #if defined(USE_GLIB) && defined(USE_GIO) | |
44 #include "chrome/browser/notifications/dbus_notification_manager.h" | |
45 #endif | |
46 | |
41 using message_center::NotifierId; | 47 using message_center::NotifierId; |
42 | 48 |
43 MessageCenterNotificationManager::MessageCenterNotificationManager( | 49 MessageCenterNotificationManager::MessageCenterNotificationManager( |
44 message_center::MessageCenter* message_center, | 50 message_center::MessageCenter* message_center, |
45 std::unique_ptr<message_center::NotifierSettingsProvider> settings_provider) | 51 std::unique_ptr<message_center::NotifierSettingsProvider> settings_provider) |
46 : message_center_(message_center), | 52 : message_center_(message_center), |
47 settings_provider_(std::move(settings_provider)), | 53 settings_provider_(std::move(settings_provider)), |
48 system_observer_(this), | 54 system_observer_(this), |
49 stats_collector_(message_center) { | 55 stats_collector_(message_center) { |
50 message_center_->AddObserver(this); | 56 message_center_->AddObserver(this); |
51 message_center_->SetNotifierSettingsProvider(settings_provider_.get()); | 57 message_center_->SetNotifierSettingsProvider(settings_provider_.get()); |
52 | 58 |
53 #if defined(OS_CHROMEOS) | 59 #if defined(OS_CHROMEOS) |
54 blockers_.push_back( | 60 blockers_.push_back( |
55 base::MakeUnique<LoginStateNotificationBlockerChromeOS>(message_center)); | 61 base::MakeUnique<LoginStateNotificationBlockerChromeOS>(message_center)); |
56 #else | 62 #else |
57 blockers_.push_back( | 63 blockers_.push_back( |
58 base::MakeUnique<ScreenLockNotificationBlocker>(message_center)); | 64 base::MakeUnique<ScreenLockNotificationBlocker>(message_center)); |
59 #endif | 65 #endif |
60 blockers_.push_back( | 66 blockers_.push_back( |
61 base::MakeUnique<FullscreenNotificationBlocker>(message_center)); | 67 base::MakeUnique<FullscreenNotificationBlocker>(message_center)); |
62 | 68 |
63 #if defined(OS_WIN) || defined(OS_MACOSX) \ | 69 #if defined(OS_WIN) || defined(OS_MACOSX) \ |
64 || (defined(OS_LINUX) && !defined(OS_CHROMEOS)) | 70 || (defined(OS_LINUX) && !defined(OS_CHROMEOS)) |
71 #if defined(USE_GLIB) && defined(USE_GIO) | |
72 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
73 switches::kUseSystemNotifications)) { | |
74 dbus_notification_manager_.reset( | |
75 DbusNotificationManager::CreateDbusNotificationManager(message_center)); | |
Peter Beverloo
2017/04/03 23:39:29
Instead of putting this in MessageCenterNotificati
Tom (Use chromium acct)
2017/04/04 02:43:17
Done.
| |
76 } | |
77 if (dbus_notification_manager_) | |
78 return; // Do not create a message center tray if using the dbus impl. | |
79 #endif | |
65 // On Windows, Linux and Mac, the notification manager owns the tray icon and | 80 // On Windows, Linux and Mac, the notification manager owns the tray icon and |
66 // views.Other platforms have global ownership and Create will return NULL. | 81 // views. Other platforms have global ownership and Create will return NULL. |
67 tray_.reset(message_center::CreateMessageCenterTray()); | 82 tray_.reset(message_center::CreateMessageCenterTray()); |
68 #endif | 83 #endif |
69 } | 84 } |
70 | 85 |
71 MessageCenterNotificationManager::~MessageCenterNotificationManager() { | 86 MessageCenterNotificationManager::~MessageCenterNotificationManager() { |
72 message_center_->SetNotifierSettingsProvider(nullptr); | 87 message_center_->SetNotifierSettingsProvider(nullptr); |
73 message_center_->RemoveObserver(this); | 88 message_center_->RemoveObserver(this); |
74 | 89 |
75 profile_notifications_.clear(); | 90 profile_notifications_.clear(); |
76 } | 91 } |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
335 } | 350 } |
336 | 351 |
337 ProfileNotification* MessageCenterNotificationManager::FindProfileNotification( | 352 ProfileNotification* MessageCenterNotificationManager::FindProfileNotification( |
338 const std::string& id) const { | 353 const std::string& id) const { |
339 auto iter = profile_notifications_.find(id); | 354 auto iter = profile_notifications_.find(id); |
340 if (iter == profile_notifications_.end()) | 355 if (iter == profile_notifications_.end()) |
341 return nullptr; | 356 return nullptr; |
342 | 357 |
343 return (*iter).second.get(); | 358 return (*iter).second.get(); |
344 } | 359 } |
OLD | NEW |