File: campaigns_matcher.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (120 lines) | stat: -rw-r--r-- 4,975 bytes parent folder | download | duplicates (8)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROMEOS_ASH_COMPONENTS_GROWTH_CAMPAIGNS_MATCHER_H_
#define CHROMEOS_ASH_COMPONENTS_GROWTH_CAMPAIGNS_MATCHER_H_

#include <optional>
#include <string>

#include "base/strings/cstring_view.h"
#include "base/time/time.h"
#include "chromeos/ash/components/growth/campaigns_manager_client.h"
#include "chromeos/ash/components/growth/campaigns_model.h"
#include "url/gurl.h"

class PrefService;

namespace signin {
enum class Tribool;
}

namespace growth {

class CampaignsMatcher {
 public:
  CampaignsMatcher(CampaignsManagerClient* client, PrefService* local_state);
  CampaignsMatcher(const CampaignsMatcher&) = delete;
  CampaignsMatcher& operator=(const CampaignsMatcher&) = delete;
  ~CampaignsMatcher();

  // Prefs related targeting will only be enabled after this method is call
  // explicitly to set user prefs.
  void SetPrefs(PrefService* prefs);

  // Filter out campaigns that doesn't pass prematch and set the campaigns
  // for runtime matching.
  void FilterAndSetCampaigns(CampaignsPerSlot* campaigns);

  const std::string& opened_app_id() const { return opened_app_id_; }
  void SetOpenedApp(std::string app_id);
  void SetOobeCompleteTime(base::Time time);

  const Trigger& trigger() const { return trigger_; }
  void SetTrigger(const Trigger&& trigger);

  const GURL& active_url() const { return active_url_; }
  void SetActiveUrl(const GURL& url);

  // Set whether the current user is device owner.
  void SetIsUserOwner(bool is_user_owner);

  // Select the targeted campaign for the given `slot`. Returns nullptr if no
  // campaign found for the given `slot`.
  const Campaign* GetCampaignBySlot(Slot slot) const;

  void SetMantaCapabilityForTesting(signin::Tribool value);
  void SetBoardForTesting(std::optional<std::string> board);

 private:
  bool IsCampaignMatched(const Campaign* campaign, bool is_prematch) const;
  bool MatchDemoModeTier(const DemoModeTargeting& targeting) const;
  bool MatchDemoModeAppVersion(const DemoModeTargeting& targeting) const;
  bool MatchRetailers(const base::Value::List* retailers) const;
  bool MaybeMatchDemoModeTargeting(const DemoModeTargeting& targeting) const;
  bool MatchMilestone(const DeviceTargeting& targeting) const;
  bool MatchMilestoneVersion(const DeviceTargeting& targeting) const;
  bool MatchDeviceTargeting(const DeviceTargeting& targeting) const;
  bool MatchRegisteredTime(const std::unique_ptr<TimeWindowTargeting>&
                               registered_time_targeting) const;
  bool MatchExperimentTagTargeting(const base::Value::List* targeting) const;
  bool MatchOpenedApp(const std::vector<std::unique_ptr<AppTargeting>>&
                          apps_opened_targeting) const;
  bool MatchTriggerTargeting(
      const std::vector<std::unique_ptr<TriggerTargeting>>& triggers) const;
  bool MatchActiveUrlRegexes(
      const std::vector<std::string>& active_url_regrexes) const;
  bool MatchHotseatAppIcon(std::unique_ptr<AppTargeting> app) const;
  bool MatchSessionTargeting(const SessionTargeting& targeting) const;
  bool MatchRuntimeTargeting(const RuntimeTargeting& targeting,
                             int campaign_id,
                             std::optional<int> group_id) const;
  bool MatchBoard(const StringListTargeting* board_targeting) const;
  bool MatchChannel(const StringListTargeting* targeting) const;
  bool MatchDeviceAge(
      const std::unique_ptr<NumberRangeTargeting>& device_age_in_hours) const;
  bool MatchEvents(std::unique_ptr<EventsTargeting> config,
                   int campaign_id,
                   std::optional<int> group_id) const;
  bool ReachCap(base::cstring_view campaign_type,
                int id,
                base::cstring_view event_type,
                std::optional<int> cap) const;
  bool MatchMinorUser(std::optional<bool> minor_user_targeting) const;
  bool MatchOwner(std::optional<bool> is_owner) const;
  bool Matched(const Targeting* targeting,
               int campaign_id,
               std::optional<int> group_id,
               bool is_prematch) const;
  bool Matched(const Targetings* targetings,
               int campaign_id,
               std::optional<int> group_id,
               bool is_prematch) const;

  // Owned by CampaignsManager.
  raw_ptr<const CampaignsPerSlot> campaigns_ = nullptr;
  raw_ptr<CampaignsManagerClient> client_ = nullptr;
  raw_ptr<PrefService> local_state_ = nullptr;
  raw_ptr<PrefService> prefs_ = nullptr;
  std::string opened_app_id_;
  GURL active_url_;
  base::Time oobe_compelete_time_;
  bool is_user_owner_ = false;
  Trigger trigger_{TriggerType::kUnSpecified};
  std::optional<signin::Tribool> manta_capability_for_testing_ = std::nullopt;
  std::optional<std::string> board_for_testing_ = std::nullopt;
};

}  // namespace growth
#endif  // CHROMEOS_ASH_COMPONENTS_GROWTH_CAMPAIGNS_MATCHER_H_