File: evaluate_seed.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (104 lines) | stat: -rw-r--r-- 4,363 bytes parent folder | download | duplicates (6)
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
// 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 COMPONENTS_VARIATIONS_CROS_EVALUATE_SEED_EVALUATE_SEED_H_
#define COMPONENTS_VARIATIONS_CROS_EVALUATE_SEED_EVALUATE_SEED_H_

#include <stdio.h>

#include <memory>
#include <optional>
#include <string>

#include "base/command_line.h"
#include "base/functional/callback.h"
#include "chromeos/ash/components/dbus/featured/featured.pb.h"
#include "components/variations/client_filterable_state.h"
#include "components/variations/cros_evaluate_seed/cros_variations_field_trial_creator.h"
#include "components/variations/service/variations_field_trial_creator_base.h"
#include "components/variations/service/variations_service_client.h"

namespace variations::cros_early_boot::evaluate_seed {
inline constexpr char kSafeSeedSwitch[] = "use-safe-seed";
inline constexpr char kEnterpriseEnrolledSwitch[] = "enterprise-enrolled";
inline constexpr char kLocalStatePathSwitch[] = "local-state-path";

class CrosVariationsServiceClient : public VariationsServiceClient {
 public:
  CrosVariationsServiceClient() = default;

  CrosVariationsServiceClient(const CrosVariationsServiceClient&) = delete;
  CrosVariationsServiceClient& operator=(const CrosVariationsServiceClient&) =
      delete;

  base::Version GetVersionForSimulation() override;

  scoped_refptr<network::SharedURLLoaderFactory> GetURLLoaderFactory() override;

  network_time::NetworkTimeTracker* GetNetworkTimeTracker() override;

  bool OverridesRestrictParameter(std::string* parameter) override;

  base::FilePath GetVariationsSeedFileDir() override;

  bool IsEnterprise() override;

  // Multi-profile early-boot experiments are not supported.
  void RemoveGoogleGroupsFromPrefsForDeletedProfiles(
      PrefService* local_state) override {}

 private:
  version_info::Channel GetChannel() override;
};

struct SafeSeed {
  bool use_safe_seed = false;  // use the data in |seed_data| or ignore it?
  featured::SeedDetails seed_data;
};

// Read the safe seed data from |stream|, if and only if the command-line
// indicates that we should use the safe seed.
// Returns nullopt if reading the safe seed failed, but we wanted one.
// Otherwise, returns a SafeSeed struct, with the |use_safe_seed| field
// indicating whether to use the associated data in |seed_data|.
std::optional<SafeSeed> GetSafeSeedData(FILE* stream);

// Return a CrOSVariationsFieldTrialCreator for either the safe seed or the
// local-state-based seed, depending on whether |safe_seed_details| has a safe
// seed specified. |entropy_provider| is used to provide entropy when setting up
// the seed file field trial.
std::unique_ptr<CrOSVariationsFieldTrialCreator> GetFieldTrialCreator(
    PrefService* local_state,
    CrosVariationsServiceClient* client,
    const std::optional<featured::SeedDetails>& safe_seed_details,
    const variations::EntropyProviders* entropy_providers);

typedef base::OnceCallback<std::unique_ptr<CrOSVariationsFieldTrialCreator>(
    PrefService* local_state,
    CrosVariationsServiceClient* client,
    const std::optional<featured::SeedDetails>& safe_seed_details,
    const variations::EntropyProviders* entropy_providers)>
    GetCrOSVariationsFieldTrialCreator;

// Evaluate the seed state, writing serialized computed output to stdout.
// In most cases, this will read seed state from the local state file as
// specified in kLocalStatePathSwitch, defaulting to a common fallback,
// kDefaultLocalStatePath.
// If kSafeSeedSwitch is specified, read SeedDetails from |in_stream| for safe
// seed and associated data.
// Writes a serialized ComputedState proto to |out_stream|.
// Uses |GetFieldTrialCreator| to get a CrOSVariationsFieldTrialCreator.
// Return values are standard for main methods (EXIT_SUCCESS / EXIT_FAILURE).
int EvaluateSeedMain(FILE* in_stream, FILE* out_stream);

// |get_creator| is a callback that will be invoked instead of
// |GetFieldTrialCreator| to get a CrOSVariationsFieldTrialCreator. Otherwise,
// the same as EvaluateSeedMain.
int EvaluateSeedMain(FILE* in_stream,
                     FILE* out_stream,
                     GetCrOSVariationsFieldTrialCreator get_creator);

}  // namespace variations::cros_early_boot::evaluate_seed

#endif  // COMPONENTS_VARIATIONS_CROS_EVALUATE_SEED_EVALUATE_SEED_H_