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

ash / public / cpp / system / toast_data.cc [blame]

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

#include "ash/public/cpp/system/toast_data.h"

#include <utility>

#include "ash/strings/grit/ash_strings.h"
#include "base/time/time.h"
#include "ui/base/l10n/l10n_util.h"

namespace ash {

ToastData::ToastData(std::string id,
                     ToastCatalogName catalog_name,
                     const std::u16string& text,
                     base::TimeDelta duration,
                     bool visible_on_lock_screen,
                     bool has_dismiss_button)
    : id(std::move(id)),
      catalog_name(catalog_name),
      text(text),
      duration(std::max(duration, kMinimumDuration)),
      visible_on_lock_screen(visible_on_lock_screen),
      time_created(base::TimeTicks::Now()) {
  if (has_dismiss_button) {
    button_type = ButtonType::kTextButton;
    button_text = l10n_util::GetStringUTF16(IDS_ASH_TOAST_DISMISS_BUTTON);
  }
}

ToastData::ToastData(ToastData&& other) = default;
ToastData& ToastData::operator=(ToastData&& other) = default;

ToastData::~ToastData() {
  // The toast can get cancelled before it shows, so we only want to run
  // `expired_callback` if the toast actually did show.
  if (!time_start_showing.is_null() && expired_callback)
    std::move(expired_callback).Run();
}

}  // namespace ash