1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53

ash / system / power / adaptive_charging_notification_controller.h [blame]

// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_SYSTEM_POWER_ADAPTIVE_CHARGING_NOTIFICATION_CONTROLLER_H_
#define ASH_SYSTEM_POWER_ADAPTIVE_CHARGING_NOTIFICATION_CONTROLLER_H_

#include <optional>
#include <string>

#include "ash/ash_export.h"
#include "base/memory/weak_ptr.h"
#include "base/time/time.h"
#include "ui/message_center/public/cpp/notification_delegate.h"

namespace ash {

class ASH_EXPORT AdaptiveChargingNotificationController
    : public message_center::NotificationObserver {
 public:
  AdaptiveChargingNotificationController();
  AdaptiveChargingNotificationController(
      const AdaptiveChargingNotificationController&) = delete;
  AdaptiveChargingNotificationController& operator=(
      const AdaptiveChargingNotificationController&) = delete;
  virtual ~AdaptiveChargingNotificationController();

  // Show the adaptive charging notification. There are two possible
  // scenarios:
  // 1. When the battery is kept at 80% indefinitely (i.e. no value of
  // |time_to_full| is provided), the notification is a
  // normal notification.
  // 2. When the battery is temporary kept at 80% (i.e. |time_to_full| has
  // a value), the estimated time to full will be shown.
  void ShowAdaptiveChargingNotification(
      std::optional<base::TimeDelta> time_to_full = std::nullopt);

  void CloseAdaptiveChargingNotification(bool by_user = false);

  bool ShouldShowNotification();

  // message_center::NotificationObserver:
  void Click(const std::optional<int>& button_index,
             const std::optional<std::u16string>& reply) override;

 private:
  base::WeakPtrFactory<AdaptiveChargingNotificationController>
      weak_ptr_factory_{this};
};

}  // namespace ash

#endif  // ASH_SYSTEM_POWER_ADAPTIVE_CHARGING_NOTIFICATION_CONTROLLER_H_