blob: cac8ce1a607e51b2637ff2aa697ede347ec695ec [file] [log] [blame]
Tommy Nyquist30401622017-05-25 17:53:541// 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
Tommy Nyquistc1d6dea12017-07-26 20:37:235#include "components/feature_engagement/internal/never_availability_model.h"
Tommy Nyquist30401622017-05-25 17:53:546
Tommy Nyquist9c02705b2017-05-31 19:02:227#include <utility>
8
Sebastien Marchand53801a32019-01-25 16:26:119#include "base/bind.h"
Tommy Nyquist30401622017-05-25 17:53:5410#include "base/callback.h"
Tommy Nyquist9c02705b2017-05-31 19:02:2211#include "base/sequenced_task_runner.h"
12#include "base/single_thread_task_runner.h"
13#include "base/threading/thread_task_runner_handle.h"
Anton Bikineev1156b5f2021-05-15 22:35:3614#include "third_party/abseil-cpp/absl/types/optional.h"
Tommy Nyquist30401622017-05-25 17:53:5415
Tommy Nyquistc1d6dea12017-07-26 20:37:2316namespace feature_engagement {
Tommy Nyquist30401622017-05-25 17:53:5417
Tommy Nyquist9c02705b2017-05-31 19:02:2218NeverAvailabilityModel::NeverAvailabilityModel() : ready_(false) {}
Tommy Nyquist30401622017-05-25 17:53:5419
20NeverAvailabilityModel::~NeverAvailabilityModel() = default;
21
22void NeverAvailabilityModel::Initialize(OnInitializedCallback callback,
Tommy Nyquist9c02705b2017-05-31 19:02:2223 uint32_t current_day) {
24 base::ThreadTaskRunnerHandle::Get()->PostTask(
25 FROM_HERE,
26 base::BindOnce(&NeverAvailabilityModel::ForwardedOnInitializedCallback,
27 base::Unretained(this), std::move(callback)));
28}
Tommy Nyquist30401622017-05-25 17:53:5429
30bool NeverAvailabilityModel::IsReady() const {
Tommy Nyquist9c02705b2017-05-31 19:02:2231 return ready_;
Tommy Nyquist30401622017-05-25 17:53:5432}
33
Anton Bikineev1156b5f2021-05-15 22:35:3634absl::optional<uint32_t> NeverAvailabilityModel::GetAvailability(
Tommy Nyquist30401622017-05-25 17:53:5435 const base::Feature& feature) const {
Anton Bikineev1156b5f2021-05-15 22:35:3636 return absl::nullopt;
Tommy Nyquist30401622017-05-25 17:53:5437}
38
Tommy Nyquist9c02705b2017-05-31 19:02:2239void NeverAvailabilityModel::ForwardedOnInitializedCallback(
40 OnInitializedCallback callback) {
41 base::ThreadTaskRunnerHandle::Get()->PostTask(
42 FROM_HERE, base::BindOnce(std::move(callback), true));
43 ready_ = true;
44}
45
Tommy Nyquistc1d6dea12017-07-26 20:37:2346} // namespace feature_engagement