| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/message_loop/message_loop.h" | 5 #include "base/message_loop/message_loop.h" |
| 6 #include "chrome/browser/browser_process.h" | 6 #include "chrome/browser/browser_process.h" |
| 7 #include "chrome/browser/notifications/desktop_notification_service.h" | 7 #include "chrome/browser/notifications/desktop_notification_service.h" |
| 8 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 8 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
| 9 #include "chrome/browser/notifications/message_center_notification_manager.h" | 9 #include "chrome/browser/notifications/message_center_notification_manager.h" |
| 10 #include "chrome/browser/notifications/notification_ui_manager.h" | 10 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 11 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h" | 11 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h" |
| 12 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service_fac
tory.h" | 12 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service_fac
tory.h" |
| 13 #include "chrome/browser/notifications/sync_notifier/welcome_delegate.h" | 13 #include "chrome/browser/notifications/sync_notifier/welcome_delegate.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/ui/browser_navigator.h" |
| 15 #include "ui/message_center/message_center.h" | 16 #include "ui/message_center/message_center.h" |
| 16 #include "ui/message_center/message_center_util.h" | 17 #include "ui/message_center/message_center_util.h" |
| 18 #include "url/gurl.h" |
| 17 | 19 |
| 18 namespace notifier { | 20 namespace notifier { |
| 19 namespace { | 21 namespace { |
| 20 void UpdateMessageCenter() { | 22 void UpdateMessageCenter() { |
| 21 NotificationUIManager* notification_ui_manager = | 23 NotificationUIManager* notification_ui_manager = |
| 22 g_browser_process->notification_ui_manager(); | 24 g_browser_process->notification_ui_manager(); |
| 23 if (notification_ui_manager->DelegatesToMessageCenter()) { | 25 if (notification_ui_manager->DelegatesToMessageCenter()) { |
| 24 MessageCenterNotificationManager* message_center_notification_manager = | 26 MessageCenterNotificationManager* message_center_notification_manager = |
| 25 static_cast<MessageCenterNotificationManager*>(notification_ui_manager); | 27 static_cast<MessageCenterNotificationManager*>(notification_ui_manager); |
| 26 | 28 |
| 27 message_center_notification_manager->EnsureMessageCenterClosed(); | 29 message_center_notification_manager->EnsureMessageCenterClosed(); |
| 28 } | 30 } |
| 29 } | 31 } |
| 30 } // namespace | 32 } // namespace |
| 31 | 33 |
| 32 WelcomeDelegate::WelcomeDelegate(const std::string& notification_id, | 34 WelcomeDelegate::WelcomeDelegate(const std::string& notification_id, |
| 33 Profile* profile, | 35 Profile* profile, |
| 34 const message_center::NotifierId notifier_id) | 36 const message_center::NotifierId notifier_id, |
| 37 const GURL& on_click_link) |
| 35 : notification_id_(notification_id), | 38 : notification_id_(notification_id), |
| 36 profile_(profile), | 39 profile_(profile), |
| 37 notifier_id_(notifier_id) { | 40 notifier_id_(notifier_id), |
| 41 on_click_link_(on_click_link) { |
| 38 DCHECK_EQ(message_center::NotifierId::SYNCED_NOTIFICATION_SERVICE, | 42 DCHECK_EQ(message_center::NotifierId::SYNCED_NOTIFICATION_SERVICE, |
| 39 notifier_id.type); | 43 notifier_id.type); |
| 40 } | 44 } |
| 41 | 45 |
| 42 WelcomeDelegate::~WelcomeDelegate() {} | 46 WelcomeDelegate::~WelcomeDelegate() {} |
| 43 | 47 |
| 44 void WelcomeDelegate::Display() {} | 48 void WelcomeDelegate::Display() {} |
| 45 | 49 |
| 46 void WelcomeDelegate::Error() {} | 50 void WelcomeDelegate::Error() {} |
| 47 | 51 |
| 48 void WelcomeDelegate::Close(bool by_user) {} | 52 void WelcomeDelegate::Close(bool by_user) {} |
| 49 | 53 |
| 54 bool WelcomeDelegate::HasClickedListener() { |
| 55 return on_click_link_.is_valid(); |
| 56 } |
| 57 |
| 50 void WelcomeDelegate::Click() { | 58 void WelcomeDelegate::Click() { |
| 51 g_browser_process->notification_ui_manager()->CancelById(notification_id_); | 59 g_browser_process->notification_ui_manager()->CancelById(notification_id_); |
| 52 | 60 |
| 53 // TODO(dewittj): Notifications that remove themselves are currently poorly | 61 if (!on_click_link_.is_valid()) { |
| 54 // supported. We need to make it possible to completely remove a notification | 62 // TODO(dewittj): Notifications that remove themselves are currently poorly |
| 55 // while the center is open, and then this section can be removed. | 63 // supported. We need to make it possible to completely remove a |
| 56 UpdateMessageCenter(); | 64 // notification |
| 65 // while the center is open, and then this section can be removed. |
| 66 UpdateMessageCenter(); |
| 67 return; |
| 68 } |
| 69 |
| 70 chrome::NavigateParams params( |
| 71 profile_, on_click_link_, content::PAGE_TRANSITION_AUTO_BOOKMARK); |
| 72 |
| 73 params.disposition = SINGLETON_TAB; |
| 74 params.window_action = chrome::NavigateParams::SHOW_WINDOW; |
| 75 params.user_gesture = true; |
| 76 |
| 77 chrome::Navigate(¶ms); |
| 57 } | 78 } |
| 58 | 79 |
| 59 void WelcomeDelegate::ButtonClick(int button_index) { | 80 void WelcomeDelegate::ButtonClick(int button_index) { |
| 60 DCHECK_EQ(0, button_index); | 81 DCHECK_EQ(0, button_index); |
| 61 | 82 |
| 62 // We take a reference to ourselves to prevent destruction until the end of | 83 // We take a reference to ourselves to prevent destruction until the end of |
| 63 // this method. | 84 // this method. |
| 64 scoped_refptr<WelcomeDelegate> this_ptr(this); | 85 scoped_refptr<WelcomeDelegate> this_ptr(this); |
| 65 | 86 |
| 66 // WARNING: This line causes the |this| to be released. | 87 // WARNING: This line causes the |this| to be released. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 85 UpdateMessageCenter(); | 106 UpdateMessageCenter(); |
| 86 } | 107 } |
| 87 | 108 |
| 88 std::string WelcomeDelegate::id() const { return notification_id_; } | 109 std::string WelcomeDelegate::id() const { return notification_id_; } |
| 89 | 110 |
| 90 content::RenderViewHost* WelcomeDelegate::GetRenderViewHost() const { | 111 content::RenderViewHost* WelcomeDelegate::GetRenderViewHost() const { |
| 91 return NULL; | 112 return NULL; |
| 92 } | 113 } |
| 93 | 114 |
| 94 } // namespace notifier | 115 } // namespace notifier |
| OLD | NEW |