| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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/chromeos/arc/arc_auth_notification.h" | 5 #include "chrome/browser/chromeos/arc/arc_auth_notification.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
| 22 #include "ui/base/resource/resource_bundle.h" | 22 #include "ui/base/resource/resource_bundle.h" |
| 23 #include "ui/message_center/message_center.h" | 23 #include "ui/message_center/message_center.h" |
| 24 #include "ui/message_center/message_center_observer.h" | 24 #include "ui/message_center/message_center_observer.h" |
| 25 #include "ui/message_center/notification.h" | 25 #include "ui/message_center/notification.h" |
| 26 #include "ui/message_center/notification_delegate.h" | 26 #include "ui/message_center/notification_delegate.h" |
| 27 #include "url/gurl.h" | 27 #include "url/gurl.h" |
| 28 | 28 |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 bool g_disabled = false; |
| 32 |
| 31 // Ids of the notification shown on first run. | 33 // Ids of the notification shown on first run. |
| 32 const char kNotifierId[] = "arc_auth"; | 34 const char kNotifierId[] = "arc_auth"; |
| 33 const char kDisplaySource[] = "arc_auth_source"; | 35 const char kDisplaySource[] = "arc_auth_source"; |
| 34 const char kFirstRunNotificationId[] = "arc_auth/first_run"; | 36 const char kFirstRunNotificationId[] = "arc_auth/first_run"; |
| 35 | 37 |
| 36 class ArcAuthNotificationDelegate | 38 class ArcAuthNotificationDelegate |
| 37 : public message_center::NotificationDelegate, | 39 : public message_center::NotificationDelegate, |
| 38 public message_center::MessageCenterObserver { | 40 public message_center::MessageCenterObserver { |
| 39 public: | 41 public: |
| 40 explicit ArcAuthNotificationDelegate(Profile* profile) : profile_(profile) {} | 42 explicit ArcAuthNotificationDelegate(Profile* profile) : profile_(profile) {} |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 | 90 |
| 89 DISALLOW_COPY_AND_ASSIGN(ArcAuthNotificationDelegate); | 91 DISALLOW_COPY_AND_ASSIGN(ArcAuthNotificationDelegate); |
| 90 }; | 92 }; |
| 91 | 93 |
| 92 } // namespace | 94 } // namespace |
| 93 | 95 |
| 94 namespace arc { | 96 namespace arc { |
| 95 | 97 |
| 96 // static | 98 // static |
| 97 void ArcAuthNotification::Show(Profile* profile) { | 99 void ArcAuthNotification::Show(Profile* profile) { |
| 100 if (g_disabled) |
| 101 return; |
| 102 |
| 98 message_center::NotifierId notifier_id( | 103 message_center::NotifierId notifier_id( |
| 99 message_center::NotifierId::SYSTEM_COMPONENT, kNotifierId); | 104 message_center::NotifierId::SYSTEM_COMPONENT, kNotifierId); |
| 100 notifier_id.profile_id = | 105 notifier_id.profile_id = |
| 101 multi_user_util::GetAccountIdFromProfile(profile).GetUserEmail(); | 106 multi_user_util::GetAccountIdFromProfile(profile).GetUserEmail(); |
| 102 | 107 |
| 103 message_center::RichNotificationData data; | 108 message_center::RichNotificationData data; |
| 104 data.buttons.push_back(message_center::ButtonInfo( | 109 data.buttons.push_back(message_center::ButtonInfo( |
| 105 l10n_util::GetStringUTF16(IDS_ARC_OPEN_PLAY_STORE_NOTIFICATION_BUTTON))); | 110 l10n_util::GetStringUTF16(IDS_ARC_OPEN_PLAY_STORE_NOTIFICATION_BUTTON))); |
| 106 data.buttons.push_back(message_center::ButtonInfo( | 111 data.buttons.push_back(message_center::ButtonInfo( |
| 107 l10n_util::GetStringUTF16(IDS_ARC_CANCEL_NOTIFICATION_BUTTON))); | 112 l10n_util::GetStringUTF16(IDS_ARC_CANCEL_NOTIFICATION_BUTTON))); |
| 108 ui::ResourceBundle& resource_bundle = ui::ResourceBundle::GetSharedInstance(); | 113 ui::ResourceBundle& resource_bundle = ui::ResourceBundle::GetSharedInstance(); |
| 109 std::unique_ptr<message_center::Notification> notification( | 114 std::unique_ptr<message_center::Notification> notification( |
| 110 new message_center::Notification( | 115 new message_center::Notification( |
| 111 message_center::NOTIFICATION_TYPE_SIMPLE, kFirstRunNotificationId, | 116 message_center::NOTIFICATION_TYPE_SIMPLE, kFirstRunNotificationId, |
| 112 l10n_util::GetStringUTF16(IDS_ARC_NOTIFICATION_TITLE), | 117 l10n_util::GetStringUTF16(IDS_ARC_NOTIFICATION_TITLE), |
| 113 l10n_util::GetStringFUTF16(IDS_ARC_NOTIFICATION_MESSAGE, | 118 l10n_util::GetStringFUTF16(IDS_ARC_NOTIFICATION_MESSAGE, |
| 114 ash::GetChromeOSDeviceName()), | 119 ash::GetChromeOSDeviceName()), |
| 115 resource_bundle.GetImageNamed(IDR_ARC_PLAY_STORE_NOTIFICATION), | 120 resource_bundle.GetImageNamed(IDR_ARC_PLAY_STORE_NOTIFICATION), |
| 116 base::UTF8ToUTF16(kDisplaySource), GURL(), notifier_id, data, | 121 base::UTF8ToUTF16(kDisplaySource), GURL(), notifier_id, data, |
| 117 new ArcAuthNotificationDelegate(profile))); | 122 new ArcAuthNotificationDelegate(profile))); |
| 118 message_center::MessageCenter::Get()->AddNotification( | 123 message_center::MessageCenter::Get()->AddNotification( |
| 119 std::move(notification)); | 124 std::move(notification)); |
| 120 } | 125 } |
| 121 | 126 |
| 122 // static | 127 // static |
| 123 void ArcAuthNotification::Hide() { | 128 void ArcAuthNotification::Hide() { |
| 129 if (g_disabled) |
| 130 return; |
| 131 |
| 124 message_center::MessageCenter::Get()->RemoveNotification( | 132 message_center::MessageCenter::Get()->RemoveNotification( |
| 125 kFirstRunNotificationId, false); | 133 kFirstRunNotificationId, false); |
| 126 } | 134 } |
| 127 | 135 |
| 136 // static |
| 137 void ArcAuthNotification::DisableForTesting() { |
| 138 g_disabled = true; |
| 139 } |
| 140 |
| 128 } // namespace arc | 141 } // namespace arc |
| OLD | NEW |