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
3 // found in the LICENSE file.
5 #include "base/message_loop/message_loop.h"
6 #include "chrome/browser/browser_process.h"
7 #include "chrome/browser/notifications/desktop_notification_service.h"
8 #include "chrome/browser/notifications/desktop_notification_service_factory.h"
9 #include "chrome/browser/notifications/message_center_notification_manager.h"
10 #include "chrome/browser/notifications/notification_ui_manager.h"
11 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h"
12 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service_factory.h"
13 #include "chrome/browser/notifications/sync_notifier/welcome_delegate.h"
14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/browser_navigator.h"
16 #include "ui/message_center/message_center.h"
21 void UpdateMessageCenter() {
22 NotificationUIManager* notification_ui_manager =
23 g_browser_process->notification_ui_manager();
24 MessageCenterNotificationManager* message_center_notification_manager =
25 static_cast<MessageCenterNotificationManager*>(notification_ui_manager);
27 message_center_notification_manager->EnsureMessageCenterClosed();
31 WelcomeDelegate::WelcomeDelegate(const std::string& notification_id,
33 const message_center::NotifierId notifier_id,
34 const GURL& on_click_link)
35 : notification_id_(notification_id),
37 notifier_id_(notifier_id),
38 on_click_link_(on_click_link) {
39 DCHECK_EQ(message_center::NotifierId::SYNCED_NOTIFICATION_SERVICE,
43 WelcomeDelegate::~WelcomeDelegate() {}
45 void WelcomeDelegate::Display() {}
47 void WelcomeDelegate::Error() {}
49 void WelcomeDelegate::Close(bool by_user) {}
51 bool WelcomeDelegate::HasClickedListener() {
52 return on_click_link_.is_valid();
55 void WelcomeDelegate::Click() {
56 g_browser_process->notification_ui_manager()->CancelById(notification_id_);
58 if (!on_click_link_.is_valid()) {
59 // TODO(dewittj): Notifications that remove themselves are currently poorly
60 // supported. We need to make it possible to completely remove a
62 // while the center is open, and then this section can be removed.
63 UpdateMessageCenter();
67 chrome::NavigateParams params(
68 profile_, on_click_link_, content::PAGE_TRANSITION_AUTO_BOOKMARK);
70 params.disposition = SINGLETON_TAB;
71 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
72 params.user_gesture = true;
74 chrome::Navigate(¶ms);
77 void WelcomeDelegate::ButtonClick(int button_index) {
78 DCHECK_EQ(0, button_index);
80 // We take a reference to ourselves to prevent destruction until the end of
82 scoped_refptr<WelcomeDelegate> this_ptr(this);
84 // WARNING: This line causes the |this| to be released.
85 g_browser_process->notification_ui_manager()->CancelById(notification_id_);
87 DesktopNotificationService* notification_service =
88 DesktopNotificationServiceFactory::GetForProfile(profile_);
89 if (notification_service)
90 notification_service->SetNotifierEnabled(notifier_id_, false);
92 ChromeNotifierService* notifier_service =
93 ChromeNotifierServiceFactory::GetForProfile(profile_,
94 Profile::EXPLICIT_ACCESS);
95 if (notifier_service) {
96 notifier_service->OnSyncedNotificationServiceEnabled(notifier_id_.id,
100 // TODO(dewittj): Notifications that remove themselves are currently poorly
101 // supported. We need to make it possible to completely remove a notification
102 // while the center is open, and then this section can be removed.
103 UpdateMessageCenter();
106 std::string WelcomeDelegate::id() const { return notification_id_; }
108 content::WebContents* WelcomeDelegate::GetWebContents() const {
112 } // namespace notifier