1 // 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 
5 #ifndef COMPONENTS_FEATURE_ENGAGEMENT_INTERNAL_AVAILABILITY_MODEL_H_
6 #define COMPONENTS_FEATURE_ENGAGEMENT_INTERNAL_AVAILABILITY_MODEL_H_
7 
8 #include <stdint.h>
9 
10 #include "base/callback_forward.h"
11 #include "base/macros.h"
12 #include "base/optional.h"
13 
14 namespace base {
15 struct Feature;
16 }  // namespace base
17 
18 namespace feature_engagement {
19 
20 // An AvailabilityModel tracks when each feature was made available to an
21 // end user.
22 class AvailabilityModel {
23  public:
24   // Invoked when the availability data has finished loading, and whether the
25   // load was a success. In the case of a failure, it is invalid to ever call
26   // GetAvailability(...).
27   using OnInitializedCallback = base::OnceCallback<void(bool success)>;
28 
29   virtual ~AvailabilityModel() = default;
30 
31   // Starts initialization of the AvailabilityModel.
32   virtual void Initialize(OnInitializedCallback callback,
33                           uint32_t current_day) = 0;
34 
35   // Returns whether the model is ready, i.e. whether it has been successfully
36   // initialized.
37   virtual bool IsReady() const = 0;
38 
39   // Returns the day number since epoch (1970-01-01) in the local timezone for
40   // when the particular |feature| was made available.
41   // See TimeProvider::GetCurrentDay().
42   virtual base::Optional<uint32_t> GetAvailability(
43       const base::Feature& feature) const = 0;
44 
45  protected:
46   AvailabilityModel() = default;
47 
48  private:
49   DISALLOW_COPY_AND_ASSIGN(AvailabilityModel);
50 };
51 
52 }  // namespace feature_engagement
53 
54 #endif  // COMPONENTS_FEATURE_ENGAGEMENT_INTERNAL_AVAILABILITY_MODEL_H_
55