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