Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(116)

Side by Side Diff: chrome/browser/chromeos/arc/notification/arc_provision_notification_service.cc

Issue 2745533005: Show notification during ARC managed provision (Closed)
Patch Set: Add tests, clean up Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/arc/notification/arc_provision_notification_se rvice.h"
6
7 #include "ash/common/system/chromeos/devicetype_utils.h"
8 #include "base/memory/ptr_util.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/chromeos/arc/arc_util.h"
11 #include "chrome/grit/generated_resources.h"
12 #include "chrome/grit/theme_resources.h"
13 #include "components/signin/core/account_id/account_id.h"
14 #include "components/user_manager/user.h"
15 #include "components/user_manager/user_manager.h"
16 #include "ui/base/l10n/l10n_util.h"
17 #include "ui/base/resource/resource_bundle.h"
18 #include "ui/chromeos/resources/grit/ui_chromeos_resources.h"
19 #include "ui/gfx/image/image.h"
20 #include "ui/message_center/message_center.h"
21 #include "ui/message_center/notification.h"
22 #include "ui/message_center/notification_types.h"
23 #include "ui/message_center/notifier_settings.h"
24 #include "url/gurl.h"
25
26 namespace arc {
27
28 namespace {
29
30 const char kManagedProvisionNotificationId[] = "arc_managed_provision";
Luis Héctor Chávez 2017/03/13 15:50:41 nit: constexpr
emaxx 2017/03/16 18:32:12 Done.
31 const char kManagedProvisionNotifierId[] = "arc_managed_provision";
32 const char kManagedProvisionDisplaySource[] = "arc_managed_provision";
33
34 class DelegateImpl : public ArcProvisionNotificationService::Delegate {
35 public:
36 void ShowManagedProvisionNotification() override;
37 void RemoveManagedProvisionNotification() override;
38 };
39
40 void DelegateImpl::ShowManagedProvisionNotification() {
41 message_center::NotifierId notifier_id(
42 message_center::NotifierId::SYSTEM_COMPONENT,
43 kManagedProvisionNotifierId);
44 const AccountId& account_id =
45 user_manager::UserManager::Get()->GetPrimaryUser()->GetAccountId();
46 notifier_id.profile_id = account_id.GetUserEmail();
47 message_center::RichNotificationData optional_fields;
48 optional_fields.clickable = false;
49 optional_fields.never_timeout = true;
50
51 message_center::MessageCenter::Get()->AddNotification(
52 base::MakeUnique<message_center::Notification>(
53 message_center::NOTIFICATION_TYPE_SIMPLE,
54 kManagedProvisionNotificationId,
55 l10n_util::GetStringUTF16(
56 IDS_ARC_MANAGED_PROVISION_NOTIFICATION_TITLE),
57 l10n_util::GetStringFUTF16(
58 IDS_ARC_MANAGED_PROVISION_NOTIFICATION_MESSAGE,
59 ash::GetChromeOSDeviceName()),
60 gfx::Image(ui::ResourceBundle::GetSharedInstance().GetImageNamed(
61 IDR_ARC_PLAY_STORE_NOTIFICATION)),
62 base::UTF8ToUTF16(kManagedProvisionDisplaySource), GURL(),
63 notifier_id, optional_fields, nullptr));
64 }
65
66 void DelegateImpl::RemoveManagedProvisionNotification() {
67 message_center::MessageCenter::Get()->RemoveNotification(
68 kManagedProvisionNotificationId, false);
69 }
70
71 } // namespace
72
73 ArcProvisionNotificationService::ArcProvisionNotificationService(
74 ArcBridgeService* bridge_service)
75 : ArcProvisionNotificationService(bridge_service,
76 base::MakeUnique<DelegateImpl>()) {}
77
78 ArcProvisionNotificationService::ArcProvisionNotificationService(
79 ArcBridgeService* bridge_service,
80 std::unique_ptr<Delegate> delegate)
81 : ArcService(bridge_service), delegate_(std::move(delegate)) {
82 ArcSessionManager::Get()->AddObserver(this);
83 }
84
85 ArcProvisionNotificationService::~ArcProvisionNotificationService() {
86 // Make sure no notification is left being shown.
87 delegate_->RemoveManagedProvisionNotification();
88 ArcSessionManager::Get()->RemoveObserver(this);
89 }
90
91 void ArcProvisionNotificationService::OnArcPlayStoreEnabledChanged(
92 bool enabled) {
93 if (!enabled) {
94 // Make sure no notification is shown after ARC gets disabled.
95 delegate_->RemoveManagedProvisionNotification();
96 }
97 }
98
99 void ArcProvisionNotificationService::OnArcStartOptInAndroidManagementCheck() {
100 // This observer is notified at an early phase of the OptIn flow, so start
101 // showing the notification if the OptIn flow happens silently (due to the
102 // managed prefs), or ensure that no notification is shown otherwise.
103 const Profile* const profile = ArcSessionManager::Get()->profile();
104 if (IsArcPlayStoreEnabledPreferenceManagedForProfile(profile) &&
105 AreArcAllOptInPreferencesManagedForProfile(profile)) {
106 delegate_->ShowManagedProvisionNotification();
107 } else {
108 delegate_->RemoveManagedProvisionNotification();
109 }
110 }
111
112 void ArcProvisionNotificationService::OnArcInitialStart() {
113 // The OptIn flow finished successfully, so remove the notification.
114 delegate_->RemoveManagedProvisionNotification();
115 }
116
117 void ArcProvisionNotificationService::OnArcSessionStopped(
118 ArcStopReason stop_reason) {
119 // One of the reasons of ARC being stopped is a failure of the opt-in flow.
120 // Therefore remove the notification if it is shown.
121 delegate_->RemoveManagedProvisionNotification();
122 }
123
124 void ArcProvisionNotificationService::OnArcSupportHostErrorShown(
125 ArcSupportHost::Error error) {
126 // After the error is displayed, there is no reason to keep showing the
127 // notification, if one was shown.
128 delegate_->RemoveManagedProvisionNotification();
129 }
130
131 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698