1 // Copyright 2024 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/install_date_provider.h" 6 7 #include "base/logging.h" 8 #include "components/metrics/metrics_pref_names.h" 9 #include "components/prefs/pref_service.h" 10 11 namespace metrics { 12 13 namespace { 14 15 // The following two methods are copied from metrics_state_manager.cc, but are 16 // simple enough it's not really needed to reuse. ReadInstallDate(PrefService * local_state)17int64_t ReadInstallDate(PrefService* local_state) { 18 return local_state->GetInt64(prefs::kInstallDate); 19 } 20 21 // Round a timestamp measured in seconds since epoch to one with a granularity 22 // of an hour. This can be used before uploaded potentially sensitive 23 // timestamps. RoundSecondsToHour(int64_t time_in_seconds)24int64_t RoundSecondsToHour(int64_t time_in_seconds) { 25 return 3600 * (time_in_seconds / 3600); 26 } 27 28 } // namespace 29 ProvideSystemProfileMetrics(SystemProfileProto * system_profile_proto)30void InstallDateProvider::ProvideSystemProfileMetrics( 31 SystemProfileProto* system_profile_proto) { 32 system_profile_proto->set_install_date( 33 RoundSecondsToHour(ReadInstallDate(local_state_))); 34 } 35 36 } // namespace metrics 37