Patricia Alfonso | 3b296e9f | 2023-09-14 15:18:14 | [diff] [blame] | 1 | // Copyright 2023 The Chromium Authors |
| 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 CHROME_BROWSER_TPCD_EXPERIMENT_EXPERIMENT_MANAGER_H_ |
| 6 | #define CHROME_BROWSER_TPCD_EXPERIMENT_EXPERIMENT_MANAGER_H_ |
| 7 | |
Nan Lin | 03748b4 | 2023-09-22 19:21:03 | [diff] [blame] | 8 | #include "base/no_destructor.h" |
Anton Maliev | 6ddb3c4 | 2023-09-26 21:08:30 | [diff] [blame] | 9 | #include "third_party/abseil-cpp/absl/types/optional.h" |
Nan Lin | 03748b4 | 2023-09-22 19:21:03 | [diff] [blame] | 10 | |
Patricia Alfonso | 3b296e9f | 2023-09-14 15:18:14 | [diff] [blame] | 11 | namespace tpcd::experiment { |
| 12 | |
| 13 | class ExperimentManager { |
| 14 | public: |
Nan Lin | 03748b4 | 2023-09-22 19:21:03 | [diff] [blame] | 15 | static ExperimentManager* GetInstance(); |
Patricia Alfonso | 3b296e9f | 2023-09-14 15:18:14 | [diff] [blame] | 16 | |
| 17 | // Called by EligibilityService to tell the manager whether a profile is |
| 18 | // eligible. Mode B also needs to know whether the profile has been onboarded |
| 19 | // to the 3PCD UX, but Mode A does not. |
| 20 | void SetClientEligibility(bool is_eligible, bool is_onboarded = false); |
| 21 | |
Anton Maliev | 6ddb3c4 | 2023-09-26 21:08:30 | [diff] [blame] | 22 | // Returns the final decision for client eligiblity, if completed. |
| 23 | // absl::nullopt will be returned if the final decision has not been made yet. |
| 24 | absl::optional<bool> IsClientEligible() const; |
| 25 | |
Nan Lin | 03748b4 | 2023-09-22 19:21:03 | [diff] [blame] | 26 | protected: |
| 27 | ExperimentManager(); |
| 28 | ~ExperimentManager() = default; |
| 29 | |
Patricia Alfonso | 3b296e9f | 2023-09-14 15:18:14 | [diff] [blame] | 30 | private: |
Nan Lin | 03748b4 | 2023-09-22 19:21:03 | [diff] [blame] | 31 | friend base::NoDestructor<ExperimentManager>; |
| 32 | |
Patricia Alfonso | 3b296e9f | 2023-09-14 15:18:14 | [diff] [blame] | 33 | // Mode B experiment will need to register the client for the synthetic trial |
| 34 | // IFF the client is eligible and onboarded (TCPDExperimentState == |
| 35 | // kOnboardedEligible). Register the client for the correct arm of the |
| 36 | // synthetic trial based on Finch feature params. |
| 37 | void RegisterSyntheticTrial(); |
| 38 | |
| 39 | // If a previously registered client becomes ineligible, unregister it from |
| 40 | // the synthetic trial by registering it to a "invalidated" experiment arm. |
| 41 | void UnregisterSyntheticTrial(); |
| 42 | |
| 43 | // Check the client is eligible for 3PCD Experiments. Returns false when: the |
| 44 | // client is <30 days old or Android users with a PWA installed. |
| 45 | bool isClientEligible(); |
| 46 | }; |
| 47 | |
| 48 | } // namespace tpcd::experiment |
| 49 | |
| 50 | #endif // CHROME_BROWSER_TPCD_EXPERIMENT_EXPERIMENT_MANAGER_H_ |