| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 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/chromeos/arc/arc_auth_notification.h" |
| 6 |
| 7 #include "ash/common/system/chromeos/devicetype_utils.h" |
| 8 #include "base/macros.h" |
| 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/chromeos/arc/arc_optin_uma.h" |
| 11 #include "chrome/browser/chromeos/arc/arc_session_manager.h" |
| 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" |
| 14 #include "chrome/grit/generated_resources.h" |
| 15 #include "chrome/grit/theme_resources.h" |
| 16 #include "components/signin/core/account_id/account_id.h" |
| 17 #include "ui/base/l10n/l10n_util.h" |
| 18 #include "ui/base/resource/resource_bundle.h" |
| 19 #include "ui/message_center/message_center.h" |
| 20 #include "ui/message_center/message_center_observer.h" |
| 21 #include "ui/message_center/notification.h" |
| 22 #include "ui/message_center/notification_delegate.h" |
| 23 #include "url/gurl.h" |
| 24 |
| 25 namespace { |
| 26 |
| 27 // Ids of the notification shown on first run. |
| 28 const char kNotifierId[] = "arc_auth"; |
| 29 const char kDisplaySource[] = "arc_auth_source"; |
| 30 const char kFirstRunNotificationId[] = "arc_auth/first_run"; |
| 31 |
| 32 class ArcAuthNotificationDelegate |
| 33 : public message_center::NotificationDelegate, |
| 34 public message_center::MessageCenterObserver { |
| 35 public: |
| 36 ArcAuthNotificationDelegate() {} |
| 37 |
| 38 // message_center::MessageCenterObserver |
| 39 void OnNotificationUpdated(const std::string& notification_id) override { |
| 40 if (notification_id != kFirstRunNotificationId) |
| 41 return; |
| 42 |
| 43 StopObserving(); |
| 44 message_center::Notification* notification = |
| 45 message_center::MessageCenter::Get()->FindVisibleNotificationById( |
| 46 notification_id); |
| 47 if (!notification) { |
| 48 NOTREACHED(); |
| 49 return; |
| 50 } |
| 51 |
| 52 if (!notification->IsRead()) |
| 53 UpdateOptInActionUMA(arc::OptInActionType::NOTIFICATION_TIMED_OUT); |
| 54 } |
| 55 |
| 56 // message_center::NotificationDelegate |
| 57 void Display() override { StartObserving(); } |
| 58 |
| 59 void ButtonClick(int button_index) override { |
| 60 StopObserving(); |
| 61 if (button_index == 0) { |
| 62 UpdateOptInActionUMA(arc::OptInActionType::NOTIFICATION_ACCEPTED); |
| 63 arc::ArcSessionManager::Get()->EnableArc(); |
| 64 } else { |
| 65 UpdateOptInActionUMA(arc::OptInActionType::NOTIFICATION_DECLINED); |
| 66 arc::ArcSessionManager::Get()->DisableArc(); |
| 67 } |
| 68 } |
| 69 |
| 70 void Close(bool by_user) override { StopObserving(); } |
| 71 |
| 72 private: |
| 73 ~ArcAuthNotificationDelegate() override { StopObserving(); } |
| 74 |
| 75 void StartObserving() { |
| 76 message_center::MessageCenter::Get()->AddObserver(this); |
| 77 } |
| 78 |
| 79 void StopObserving() { |
| 80 message_center::MessageCenter::Get()->RemoveObserver(this); |
| 81 } |
| 82 |
| 83 DISALLOW_COPY_AND_ASSIGN(ArcAuthNotificationDelegate); |
| 84 }; |
| 85 |
| 86 } // namespace |
| 87 |
| 88 namespace arc { |
| 89 |
| 90 // static |
| 91 void ArcAuthNotification::Show(Profile* profile) { |
| 92 message_center::NotifierId notifier_id( |
| 93 message_center::NotifierId::SYSTEM_COMPONENT, kNotifierId); |
| 94 notifier_id.profile_id = |
| 95 multi_user_util::GetAccountIdFromProfile(profile).GetUserEmail(); |
| 96 |
| 97 message_center::RichNotificationData data; |
| 98 data.buttons.push_back(message_center::ButtonInfo( |
| 99 l10n_util::GetStringUTF16(IDS_ARC_OPEN_PLAY_STORE_NOTIFICATION_BUTTON))); |
| 100 data.buttons.push_back(message_center::ButtonInfo( |
| 101 l10n_util::GetStringUTF16(IDS_ARC_CANCEL_NOTIFICATION_BUTTON))); |
| 102 ui::ResourceBundle& resource_bundle = ui::ResourceBundle::GetSharedInstance(); |
| 103 std::unique_ptr<message_center::Notification> notification( |
| 104 new message_center::Notification( |
| 105 message_center::NOTIFICATION_TYPE_SIMPLE, kFirstRunNotificationId, |
| 106 l10n_util::GetStringUTF16(IDS_ARC_NOTIFICATION_TITLE), |
| 107 l10n_util::GetStringFUTF16(IDS_ARC_NOTIFICATION_MESSAGE, |
| 108 ash::GetChromeOSDeviceName()), |
| 109 resource_bundle.GetImageNamed(IDR_ARC_PLAY_STORE_NOTIFICATION), |
| 110 base::UTF8ToUTF16(kDisplaySource), GURL(), notifier_id, data, |
| 111 new ArcAuthNotificationDelegate())); |
| 112 message_center::MessageCenter::Get()->AddNotification( |
| 113 std::move(notification)); |
| 114 } |
| 115 |
| 116 // static |
| 117 void ArcAuthNotification::Hide() { |
| 118 message_center::MessageCenter::Get()->RemoveNotification( |
| 119 kFirstRunNotificationId, false); |
| 120 } |
| 121 |
| 122 } // namespace arc |
| OLD | NEW |