Commit 3224cfec authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

Make ArcAuthNotification use NotificationDisplayService.

Also stop observing the MessageCenter, which is in another process (in
--mash).

The UMA is a little wonky, even before this change, because manually
closing the notification is not explicitly logged. It will need to be
reworked in the new style of notifications because if closing doesn't
count as "decline" then nothing does. For now this more or less
maintains existing behavior.

Bug: 783018
Change-Id: I69278c0653d8548ccd1fe6a66015b7cf08a0d08c
Reviewed-on: https://chromium-review.googlesource.com/777739Reviewed-by: default avatarTetsui Ohkubo <tetsui@chromium.org>
Reviewed-by: default avatarYusuke Sato <yusukes@chromium.org>
Commit-Queue: Evan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#517883}
parent 7f395224
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "chrome/app/vector_icons/vector_icons.h" #include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/chromeos/arc/arc_optin_uma.h" #include "chrome/browser/chromeos/arc/arc_optin_uma.h"
#include "chrome/browser/chromeos/arc/arc_util.h" #include "chrome/browser/chromeos/arc/arc_util.h"
#include "chrome/browser/notifications/notification_display_service.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/ash/multi_user/multi_user_util.h" #include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
...@@ -23,8 +24,6 @@ ...@@ -23,8 +24,6 @@
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
#include "ui/chromeos/devicetype_utils.h" #include "ui/chromeos/devicetype_utils.h"
#include "ui/message_center/message_center.h"
#include "ui/message_center/message_center_observer.h"
#include "ui/message_center/notification.h" #include "ui/message_center/notification.h"
#include "ui/message_center/notification_delegate.h" #include "ui/message_center/notification_delegate.h"
#include "ui/message_center/public/cpp/message_center_switches.h" #include "ui/message_center/public/cpp/message_center_switches.h"
...@@ -39,74 +38,45 @@ const char kNotifierId[] = "arc_auth"; ...@@ -39,74 +38,45 @@ const char kNotifierId[] = "arc_auth";
const char kFirstRunNotificationId[] = "arc_auth/first_run"; const char kFirstRunNotificationId[] = "arc_auth/first_run";
class ArcAuthNotificationDelegate class ArcAuthNotificationDelegate
: public message_center::NotificationDelegate, : public message_center::NotificationDelegate {
public message_center::MessageCenterObserver {
public: public:
explicit ArcAuthNotificationDelegate(Profile* profile) : profile_(profile) {} explicit ArcAuthNotificationDelegate(Profile* profile) : profile_(profile) {}
// message_center::MessageCenterObserver
void OnNotificationUpdated(const std::string& notification_id) override {
if (notification_id != kFirstRunNotificationId)
return;
StopObserving();
message_center::Notification* notification =
message_center::MessageCenter::Get()->FindVisibleNotificationById(
notification_id);
if (!notification) {
NOTREACHED();
return;
}
if (!notification->IsRead())
UpdateOptInActionUMA(arc::OptInActionType::NOTIFICATION_TIMED_OUT);
}
// message_center::NotificationDelegate // message_center::NotificationDelegate
void Display() override { StartObserving(); }
// TODO(tetsui): Remove this method when IsNewStyleNotificationEnabled() flag // TODO(tetsui): Remove this method when IsNewStyleNotificationEnabled() flag
// is removed. // is removed.
void ButtonClick(int button_index) override { void ButtonClick(int button_index) override {
StopObserving();
if (button_index == 0) { if (button_index == 0) {
UpdateOptInActionUMA(arc::OptInActionType::NOTIFICATION_ACCEPTED); LogUma(arc::OptInActionType::NOTIFICATION_ACCEPTED);
arc::SetArcPlayStoreEnabledForProfile(profile_, true); arc::SetArcPlayStoreEnabledForProfile(profile_, true);
} else { } else {
UpdateOptInActionUMA(arc::OptInActionType::NOTIFICATION_DECLINED); LogUma(arc::OptInActionType::NOTIFICATION_DECLINED);
arc::SetArcPlayStoreEnabledForProfile(profile_, false); arc::SetArcPlayStoreEnabledForProfile(profile_, false);
} }
} }
void Click() override { void Click() override {
StopObserving(); LogUma(arc::OptInActionType::NOTIFICATION_ACCEPTED);
UpdateOptInActionUMA(arc::OptInActionType::NOTIFICATION_ACCEPTED);
arc::SetArcPlayStoreEnabledForProfile(profile_, true); arc::SetArcPlayStoreEnabledForProfile(profile_, true);
} }
void Close(bool by_user) override { StopObserving(); } void Close(bool by_user) override {
LogUma(arc::OptInActionType::NOTIFICATION_TIMED_OUT);
}
private: private:
~ArcAuthNotificationDelegate() override { StopObserving(); } ~ArcAuthNotificationDelegate() override {}
void StartObserving() {
if (observing_message_center_)
return;
message_center::MessageCenter::Get()->AddObserver(this);
observing_message_center_ = true;
}
void StopObserving() { void LogUma(arc::OptInActionType action) {
if (!observing_message_center_) if (!uma_logged_)
return; UpdateOptInActionUMA(action);
message_center::MessageCenter::Get()->RemoveObserver(this); uma_logged_ = true;
observing_message_center_ = false;
} }
// Unowned pointer.
Profile* const profile_; Profile* const profile_;
// To prevent double observing.
bool observing_message_center_ = false; // Whether a UMA action has been logged.
bool uma_logged_ = false;
DISALLOW_COPY_AND_ASSIGN(ArcAuthNotificationDelegate); DISALLOW_COPY_AND_ASSIGN(ArcAuthNotificationDelegate);
}; };
...@@ -181,15 +151,13 @@ void ArcAuthNotification::Show() { ...@@ -181,15 +151,13 @@ void ArcAuthNotification::Show() {
l10n_util::GetStringUTF16(IDS_ARC_NOTIFICATION_DISPLAY_SOURCE), GURL(), l10n_util::GetStringUTF16(IDS_ARC_NOTIFICATION_DISPLAY_SOURCE), GURL(),
notifier_id, data, new ArcAuthNotificationDelegate(profile_)); notifier_id, data, new ArcAuthNotificationDelegate(profile_));
} }
message_center::MessageCenter::Get()->AddNotification( NotificationDisplayService::GetForProfile(profile_)->Display(
std::move(notification)); NotificationCommon::TRANSIENT, *notification);
} }
void ArcAuthNotification::Hide() { void ArcAuthNotification::Hide() {
message_center::MessageCenter* message_center = NotificationDisplayService::GetForProfile(profile_)->Close(
message_center::MessageCenter::Get(); NotificationCommon::TRANSIENT, kFirstRunNotificationId);
if (message_center)
message_center->RemoveNotification(kFirstRunNotificationId, false);
session_manager::SessionManager* session_manager = session_manager::SessionManager* session_manager =
session_manager::SessionManager::Get(); session_manager::SessionManager::Get();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment