1 // Copyright 2023 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/metrics_shutdown.h" 6 7 #include "base/metrics/persistent_histogram_allocator.h" 8 #include "components/metrics/clean_exit_beacon.h" 9 #include "components/prefs/pref_service.h" 10 11 namespace metrics { 12 Shutdown(PrefService * local_state)13void Shutdown(PrefService* local_state) { 14 CleanExitBeacon::EnsureCleanShutdown(local_state); 15 auto* allocator = base::GlobalHistogramAllocator::Get(); 16 if (allocator) { 17 // Write to the persistent histogram allocator that we've exited cleanly. 18 // This is not perfect as the browser may crash after this call (or the 19 // device may lose power, which may leave the underlying pages in an 20 // inconsistent state), but this is "good" enough for debugging sake. 21 allocator->memory_allocator()->SetMemoryState( 22 base::PersistentMemoryAllocator::MemoryState::MEMORY_COMPLETED); 23 } 24 } 25 26 } // namespace metrics 27