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

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: Renaming, nit fixes 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 constexpr char kManagedProvisionNotificationId[] = "arc_managed_provision";
31 constexpr char kManagedProvisionNotifierId[] = "arc_managed_provision";
32 constexpr 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::Delegate::Delegate() = default;
74
75 ArcProvisionNotificationService::Delegate::~Delegate() = default;
76
77 ArcProvisionNotificationService::ArcProvisionNotificationService(
78 ArcBridgeService* bridge_service)
79 : ArcProvisionNotificationService(bridge_service,
80 base::MakeUnique<DelegateImpl>()) {}
81
82 ArcProvisionNotificationService::ArcProvisionNotificationService(
83 ArcBridgeService* bridge_service,
84 std::unique_ptr<Delegate> delegate)
85 : ArcService(bridge_service), delegate_(std::move(delegate)) {
86 ArcSessionManager::Get()->AddObserver(this);
87 }
88
89 ArcProvisionNotificationService::~ArcProvisionNotificationService() {
90 // Make sure no notification is left being shown.
91 delegate_->RemoveManagedProvisionNotification();
92 ArcSessionManager::Get()->RemoveObserver(this);
93 }
94
95 void ArcProvisionNotificationService::OnArcPlayStoreEnabledChanged(
96 bool enabled) {
97 if (!enabled) {
98 // Make sure no notification is shown after ARC gets disabled.
99 delegate_->RemoveManagedProvisionNotification();
100 }
101 }
102
103 void ArcProvisionNotificationService::OnArcOptInManagementCheckStarted() {
104 // This observer is notified at an early phase of the OptIn flow, so start
105 // showing the notification if the OptIn flow happens silently (due to the
106 // managed prefs), or ensure that no notification is shown otherwise.
107 const Profile* const profile = ArcSessionManager::Get()->profile();
108 if (IsArcPlayStoreEnabledPreferenceManagedForProfile(profile) &&
109 AreArcAllOptInPreferencesManagedForProfile(profile)) {
110 delegate_->ShowManagedProvisionNotification();
111 } else {
112 delegate_->RemoveManagedProvisionNotification();
113 }
114 }
115
116 void ArcProvisionNotificationService::OnArcInitialStart() {
117 // The OptIn flow finished successfully, so remove the notification.
118 delegate_->RemoveManagedProvisionNotification();
119 }
120
121 void ArcProvisionNotificationService::OnArcSessionStopped(
122 ArcStopReason stop_reason) {
123 // One of the reasons of ARC being stopped is a failure of the opt-in flow.
124 // Therefore remove the notification if it is shown.
125 delegate_->RemoveManagedProvisionNotification();
126 }
127
128 void ArcProvisionNotificationService::OnArcShowingErrorRequested(
129 ArcSupportHost::Error error) {
130 // After the error is displayed, there is no reason to keep showing the
Luis Héctor Chávez 2017/03/24 17:39:16 The error might not be shown. Do you still want to
emaxx 2017/04/11 02:09:49 Done, rephrased the comment so that it doesn't tal
131 // notification, if one was shown.
132 delegate_->RemoveManagedProvisionNotification();
133 }
134
135 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698