• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 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 #include "components/metrics/structured/neutrino_logging_util.h"
6 
7 #include "components/metrics/metrics_pref_names.h"
8 #include "components/metrics/structured/structured_events.h"
9 
10 namespace metrics {
11 namespace structured {
12 
NeutrinoDevicesLogWithLocalState(PrefService * local_state,NeutrinoDevicesLocation location)13 void NeutrinoDevicesLogWithLocalState(PrefService* local_state,
14                                       NeutrinoDevicesLocation location) {
15   auto code_point = events::v2::neutrino_devices::CodePoint();
16   if (local_state &&
17       local_state->HasPrefPath(metrics::prefs::kMetricsClientID)) {
18     const std::string client_id =
19         local_state->GetString(metrics::prefs::kMetricsClientID);
20     if (!client_id.empty())
21       code_point.SetClientId(client_id);
22   }
23   code_point.SetLocation(static_cast<int64_t>(location)).Record();
24 }
25 
NeutrinoDevicesLogEnrollmentWithLocalState(PrefService * local_state,bool is_managed,NeutrinoDevicesLocation location)26 void NeutrinoDevicesLogEnrollmentWithLocalState(
27     PrefService* local_state,
28     bool is_managed,
29     NeutrinoDevicesLocation location) {
30   auto enrollment = events::v2::neutrino_devices::Enrollment();
31   if (local_state &&
32       local_state->HasPrefPath(metrics::prefs::kMetricsClientID)) {
33     const std::string client_id =
34         local_state->GetString(metrics::prefs::kMetricsClientID);
35     if (!client_id.empty())
36       enrollment.SetClientId(client_id);
37   }
38   enrollment.SetIsManagedPolicy(is_managed)
39       .SetLocation(static_cast<int64_t>(location))
40       .Record();
41 }
42 
43 }  // namespace structured
44 }  // namespace metrics
45