OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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_migration_guide_notification.h" | 5 #include "chrome/browser/chromeos/arc/arc_migration_guide_notification.h" |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "chrome/app/vector_icons/vector_icons.h" | 9 #include "chrome/app/vector_icons/vector_icons.h" |
10 #include "chrome/browser/chromeos/arc/arc_util.h" | 10 #include "chrome/browser/chromeos/arc/arc_util.h" |
11 #include "chrome/browser/lifetime/application_lifetime.h" | 11 #include "chrome/browser/lifetime/application_lifetime.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" | 13 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" |
| 14 #include "chrome/common/pref_names.h" |
14 #include "chrome/grit/generated_resources.h" | 15 #include "chrome/grit/generated_resources.h" |
15 #include "components/signin/core/account_id/account_id.h" | 16 #include "components/signin/core/account_id/account_id.h" |
| 17 #include "components/user_manager/known_user.h" |
16 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
17 #include "ui/gfx/color_palette.h" | 19 #include "ui/gfx/color_palette.h" |
18 #include "ui/gfx/paint_vector_icon.h" | 20 #include "ui/gfx/paint_vector_icon.h" |
19 #include "ui/message_center/message_center.h" | 21 #include "ui/message_center/message_center.h" |
20 #include "ui/message_center/notification.h" | 22 #include "ui/message_center/notification.h" |
21 #include "ui/message_center/notification_delegate.h" | 23 #include "ui/message_center/notification_delegate.h" |
22 | 24 |
23 namespace arc { | 25 namespace arc { |
24 | 26 |
25 namespace { | 27 namespace { |
26 | 28 |
27 constexpr char kNotifierId[] = "arc_fs_migration"; | 29 constexpr char kNotifierId[] = "arc_fs_migration"; |
28 constexpr char kNotificationId[] = "arc_fs_migration/migrate"; | 30 constexpr char kSuggestNotificationId[] = "arc_fs_migration/suggest"; |
| 31 constexpr char kSuccessNotificationId[] = "arc_fs_migration/success"; |
29 | 32 |
30 class ArcMigrationGuideNotificationDelegate | 33 class ArcMigrationGuideNotificationDelegate |
31 : public message_center::NotificationDelegate { | 34 : public message_center::NotificationDelegate { |
32 public: | 35 public: |
33 ArcMigrationGuideNotificationDelegate() = default; | 36 ArcMigrationGuideNotificationDelegate() = default; |
34 | 37 |
35 // message_center::NotificationDelegate | 38 // message_center::NotificationDelegate |
36 void ButtonClick(int button_index) override { chrome::AttemptUserExit(); } | 39 void ButtonClick(int button_index) override { chrome::AttemptUserExit(); } |
37 | 40 |
38 private: | 41 private: |
39 ~ArcMigrationGuideNotificationDelegate() override = default; | 42 ~ArcMigrationGuideNotificationDelegate() override = default; |
40 | 43 |
41 DISALLOW_COPY_AND_ASSIGN(ArcMigrationGuideNotificationDelegate); | 44 DISALLOW_COPY_AND_ASSIGN(ArcMigrationGuideNotificationDelegate); |
42 }; | 45 }; |
43 | 46 |
44 } // namespace | 47 } // namespace |
45 | 48 |
46 // static | 49 // static |
47 void ShowArcMigrationGuideNotification(Profile* profile) { | 50 void ShowArcMigrationGuideNotification(Profile* profile) { |
48 // Always remove the notification to make sure the notification appears | 51 // Always remove the notification to make sure the notification appears |
49 // as a popup in any situation. | 52 // as a popup in any situation. |
50 message_center::MessageCenter::Get()->RemoveNotification(kNotificationId, | 53 message_center::MessageCenter::Get()->RemoveNotification( |
51 false /* by_user */); | 54 kSuggestNotificationId, false /* by_user */); |
52 | 55 |
53 message_center::NotifierId notifier_id( | 56 message_center::NotifierId notifier_id( |
54 message_center::NotifierId::SYSTEM_COMPONENT, kNotifierId); | 57 message_center::NotifierId::SYSTEM_COMPONENT, kNotifierId); |
55 notifier_id.profile_id = | 58 notifier_id.profile_id = |
56 multi_user_util::GetAccountIdFromProfile(profile).GetUserEmail(); | 59 multi_user_util::GetAccountIdFromProfile(profile).GetUserEmail(); |
57 | 60 |
58 message_center::RichNotificationData data; | 61 message_center::RichNotificationData data; |
59 data.buttons.push_back(message_center::ButtonInfo(l10n_util::GetStringUTF16( | 62 data.buttons.push_back(message_center::ButtonInfo(l10n_util::GetStringUTF16( |
60 IDS_ARC_MIGRATE_ENCRYPTION_NOTIFICATION_RESTART_BUTTON))); | 63 IDS_ARC_MIGRATE_ENCRYPTION_NOTIFICATION_RESTART_BUTTON))); |
61 message_center::MessageCenter::Get()->AddNotification( | 64 message_center::MessageCenter::Get()->AddNotification( |
62 base::MakeUnique<message_center::Notification>( | 65 base::MakeUnique<message_center::Notification>( |
63 message_center::NOTIFICATION_TYPE_SIMPLE, kNotificationId, | 66 message_center::NOTIFICATION_TYPE_SIMPLE, kSuggestNotificationId, |
64 l10n_util::GetStringUTF16( | 67 l10n_util::GetStringUTF16( |
65 IDS_ARC_MIGRATE_ENCRYPTION_NOTIFICATION_TITLE), | 68 IDS_ARC_MIGRATE_ENCRYPTION_NOTIFICATION_TITLE), |
66 // TODO(kinaba): crbug/710289 Change message for low-battery case. | 69 // TODO(kinaba): crbug/710289 Change message for low-battery case. |
67 l10n_util::GetStringUTF16( | 70 l10n_util::GetStringUTF16( |
68 IDS_ARC_MIGRATE_ENCRYPTION_NOTIFICATION_MESSAGE), | 71 IDS_ARC_MIGRATE_ENCRYPTION_NOTIFICATION_MESSAGE), |
69 gfx::Image(gfx::CreateVectorIcon( | 72 gfx::Image(gfx::CreateVectorIcon( |
70 kArcMigrateEncryptionNotificationIcon, gfx::kPlaceholderColor)), | 73 kArcMigrateEncryptionNotificationIcon, gfx::kPlaceholderColor)), |
71 base::string16(), GURL(), notifier_id, data, | 74 base::string16(), GURL(), notifier_id, data, |
72 new ArcMigrationGuideNotificationDelegate())); | 75 new ArcMigrationGuideNotificationDelegate())); |
73 } | 76 } |
74 | 77 |
| 78 void ShowArcMigrationSuccessNotificationIfNeeded(Profile* profile) { |
| 79 const AccountId account_id = |
| 80 multi_user_util::GetAccountIdFromProfile(profile); |
| 81 |
| 82 int pref_value = kFileSystemIncompatible; |
| 83 user_manager::known_user::GetIntegerPref( |
| 84 account_id, prefs::kArcCompatibleFilesystemChosen, &pref_value); |
| 85 |
| 86 // Show notification only when the pref value indicates the file system is |
| 87 // compatible, but not yet notified. |
| 88 if (pref_value != kFileSystemCompatible) |
| 89 return; |
| 90 |
| 91 // If this is a newly created profile, the filesystem was compatible from |
| 92 // the beginning, not because of migration. Skip showing the notification. |
| 93 if (!profile->IsNewProfile()) { |
| 94 message_center::NotifierId notifier_id( |
| 95 message_center::NotifierId::SYSTEM_COMPONENT, kNotifierId); |
| 96 notifier_id.profile_id = account_id.GetUserEmail(); |
| 97 |
| 98 message_center::MessageCenter::Get()->AddNotification( |
| 99 base::MakeUnique<message_center::Notification>( |
| 100 message_center::NOTIFICATION_TYPE_SIMPLE, kSuccessNotificationId, |
| 101 base::string16(), // title |
| 102 l10n_util::GetStringUTF16( |
| 103 IDS_ARC_MIGRATE_ENCRYPTION_SUCCESS_MESSAGE), |
| 104 gfx::Image(gfx::CreateVectorIcon( |
| 105 kArcMigrateEncryptionNotificationIcon, gfx::kPlaceholderColor)), |
| 106 base::string16(), GURL(), notifier_id, |
| 107 message_center::RichNotificationData(), |
| 108 new message_center::NotificationDelegate())); |
| 109 } |
| 110 |
| 111 // Mark as notified. |
| 112 user_manager::known_user::SetIntegerPref( |
| 113 account_id, prefs::kArcCompatibleFilesystemChosen, |
| 114 arc::kFileSystemCompatibleAndNotified); |
| 115 } |
| 116 |
75 } // namespace arc | 117 } // namespace arc |
OLD | NEW |