xref: /aosp_15_r20/external/cronet/components/metrics/metrics_shutdown.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1*6777b538SAndroid Build Coastguard Worker // Copyright 2023 The Chromium Authors
2*6777b538SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*6777b538SAndroid Build Coastguard Worker // found in the LICENSE file.
4*6777b538SAndroid Build Coastguard Worker 
5*6777b538SAndroid Build Coastguard Worker #include "components/metrics/metrics_shutdown.h"
6*6777b538SAndroid Build Coastguard Worker 
7*6777b538SAndroid Build Coastguard Worker #include "base/metrics/persistent_histogram_allocator.h"
8*6777b538SAndroid Build Coastguard Worker #include "components/metrics/clean_exit_beacon.h"
9*6777b538SAndroid Build Coastguard Worker #include "components/prefs/pref_service.h"
10*6777b538SAndroid Build Coastguard Worker 
11*6777b538SAndroid Build Coastguard Worker namespace metrics {
12*6777b538SAndroid Build Coastguard Worker 
Shutdown(PrefService * local_state)13*6777b538SAndroid Build Coastguard Worker void Shutdown(PrefService* local_state) {
14*6777b538SAndroid Build Coastguard Worker   CleanExitBeacon::EnsureCleanShutdown(local_state);
15*6777b538SAndroid Build Coastguard Worker   auto* allocator = base::GlobalHistogramAllocator::Get();
16*6777b538SAndroid Build Coastguard Worker   if (allocator) {
17*6777b538SAndroid Build Coastguard Worker     // Write to the persistent histogram allocator that we've exited cleanly.
18*6777b538SAndroid Build Coastguard Worker     // This is not perfect as the browser may crash after this call (or the
19*6777b538SAndroid Build Coastguard Worker     // device may lose power, which may leave the underlying pages in an
20*6777b538SAndroid Build Coastguard Worker     // inconsistent state), but this is "good" enough for debugging sake.
21*6777b538SAndroid Build Coastguard Worker     allocator->memory_allocator()->SetMemoryState(
22*6777b538SAndroid Build Coastguard Worker         base::PersistentMemoryAllocator::MemoryState::MEMORY_COMPLETED);
23*6777b538SAndroid Build Coastguard Worker   }
24*6777b538SAndroid Build Coastguard Worker }
25*6777b538SAndroid Build Coastguard Worker 
26*6777b538SAndroid Build Coastguard Worker }  // namespace metrics
27