1 // Copyright 2020 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.
4 
5 #include "chrome/browser/updates/announcement_notification/announcement_notification_delegate.h"
6 
7 #include <string>
8 
9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/first_run/first_run.h"
11 #include "chrome/browser/notifications/notification_display_service.h"
12 #include "chrome/grit/generated_resources.h"
13 #include "ui/base/l10n/l10n_util.h"
14 #include "ui/message_center/public/cpp/notification.h"
15 
AnnouncementNotificationDelegate(NotificationDisplayService * display_service)16 AnnouncementNotificationDelegate::AnnouncementNotificationDelegate(
17     NotificationDisplayService* display_service)
18     : display_service_(display_service) {
19   DCHECK(display_service_);
20 }
21 
22 AnnouncementNotificationDelegate::~AnnouncementNotificationDelegate() = default;
23 
ShowNotification()24 void AnnouncementNotificationDelegate::ShowNotification() {
25   auto rich_notification_data = message_center::RichNotificationData();
26   message_center::ButtonInfo button1(
27       l10n_util::GetStringUTF16(IDS_TOS_NOTIFICATION_ACK_BUTTON_TEXT));
28   message_center::ButtonInfo button2(
29       l10n_util::GetStringUTF16(IDS_TOS_NOTIFICATION_REVIEW_BUTTON_TEXT));
30   rich_notification_data.buttons.push_back(button1);
31   rich_notification_data.buttons.push_back(button2);
32 
33   message_center::Notification notification(
34       message_center::NOTIFICATION_TYPE_SIMPLE, kAnnouncementNotificationId,
35       l10n_util::GetStringUTF16(IDS_TOS_NOTIFICATION_TITLE),
36       l10n_util::GetStringUTF16(IDS_TOS_NOTIFICATION_BODY_TEXT), gfx::Image(),
37       base::string16(), GURL(),
38       message_center::NotifierId(message_center::NotifierType::SYSTEM_COMPONENT,
39                                  kAnnouncementNotificationId),
40       rich_notification_data, nullptr /*delegate*/);
41 
42   display_service_->Display(NotificationHandler::Type::ANNOUNCEMENT,
43                             notification, nullptr /*metadata*/);
44 }
45 
IsFirstRun()46 bool AnnouncementNotificationDelegate::IsFirstRun() {
47   return first_run::IsChromeFirstRun();
48 }
49