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