blob: 4ef736fc6c176d98eaa588a9da58a5f6313890e7 [file] [log] [blame]
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_DETACHABLE_BASE_DETACHABLE_BASE_NOTIFICATION_CONTROLLER_H_
#define ASH_DETACHABLE_BASE_DETACHABLE_BASE_NOTIFICATION_CONTROLLER_H_
#include "ash/ash_export.h"
#include "ash/detachable_base/detachable_base_observer.h"
#include "ash/session/session_observer.h"
#include "base/scoped_observer.h"
namespace ash {
class DetachableBaseHandler;
// Observes DetachableBaseHandler to detect changes to detachable base state,
// and shows relevant notifications as needed:
// * when the attached base is different from the last one used by the active
// user, it shows a notification warning the user the base has changed, and
// that the newly attached base might be malicious (untrusted base might be
// tracking the user's key strokes).
// * when the attached base could not be authenticated, it warns the user that
// the base may not be trusted.
class ASH_EXPORT DetachableBaseNotificationController
: public DetachableBaseObserver,
public SessionObserver {
public:
static const char kBaseChangedNotificationId[];
explicit DetachableBaseNotificationController(
DetachableBaseHandler* detachable_base_handler);
~DetachableBaseNotificationController() override;
// DetachableBaseObserver:
void OnDetachableBasePairingStatusChanged(
DetachableBasePairingStatus pairing_status) override;
// SessionObserver:
void OnActiveUserSessionChanged(const AccountId& account_id) override;
void OnSessionStateChanged(session_manager::SessionState state) override;
private:
// Called when the session state or detachable base pairing state change.
// Determines whether the current state requires showing a notification to the
// user, and show kBaseChangedNotificationId if that is the case.
void ShowPairingNotificationIfNeeded();
// Removes kBaseChangedNotificationId notification if it was previously shown
// within the current session.
void RemovePairingNotification();
DetachableBaseHandler* detachable_base_handler_;
ScopedObserver<DetachableBaseHandler, DetachableBaseObserver>
detachable_base_observer_;
ScopedSessionObserver session_observer_;
DISALLOW_COPY_AND_ASSIGN(DetachableBaseNotificationController);
};
} // namespace ash
#endif // ASH_DETACHABLE_BASE_DETACHABLE_BASE_NOTIFICATION_CONTROLLER_H_