Commit 17166693 authored by Gabriel Charette's avatar Gabriel Charette Committed by Commit Bot

Migrate browser_shutdown.cc off the FILE thread.

R=thakis@chromium.org

Bug: 689520
Change-Id: I5ea04e1c89cf5694071aa1c7d0d6ff5caaca4f88
Reviewed-on: https://chromium-review.googlesource.com/580505Reviewed-by: default avatarNico Weber <thakis@chromium.org>
Commit-Queue: Gabriel Charette <gab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#488659}
parent d699aa1e
...@@ -17,7 +17,9 @@ ...@@ -17,7 +17,9 @@
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/task_scheduler/post_task.h"
#include "base/threading/thread.h" #include "base/threading/thread.h"
#include "base/threading/thread_restrictions.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/about_flags.h" #include "chrome/browser/about_flags.h"
...@@ -34,7 +36,6 @@ ...@@ -34,7 +36,6 @@
#include "components/prefs/pref_registry_simple.h" #include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/tracing/common/tracing_switches.h" #include "components/tracing/common/tracing_switches.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host.h"
#include "content/public/browser/tracing_controller.h" #include "content/public/browser/tracing_controller.h"
#include "printing/features/features.h" #include "printing/features/features.h"
...@@ -68,7 +69,6 @@ ...@@ -68,7 +69,6 @@
using base::Time; using base::Time;
using base::TimeDelta; using base::TimeDelta;
using content::BrowserThread;
namespace browser_shutdown { namespace browser_shutdown {
namespace { namespace {
...@@ -81,7 +81,13 @@ ShutdownType g_shutdown_type = NOT_VALID; ...@@ -81,7 +81,13 @@ ShutdownType g_shutdown_type = NOT_VALID;
int g_shutdown_num_processes; int g_shutdown_num_processes;
int g_shutdown_num_processes_slow; int g_shutdown_num_processes_slow;
const char kShutdownMsFile[] = "chrome_shutdown_ms.txt"; constexpr char kShutdownMsFile[] = "chrome_shutdown_ms.txt";
base::FilePath GetShutdownMsPath() {
base::FilePath shutdown_ms_file;
PathService::Get(chrome::DIR_USER_DATA, &shutdown_ms_file);
return shutdown_ms_file.AppendASCII(kShutdownMsFile);
}
const char* ToShutdownTypeString(ShutdownType type) { const char* ToShutdownTypeString(ShutdownType type) {
switch (type) { switch (type) {
...@@ -144,12 +150,6 @@ void OnShutdownStarting(ShutdownType type) { ...@@ -144,12 +150,6 @@ void OnShutdownStarting(ShutdownType type) {
} }
} }
base::FilePath GetShutdownMsPath() {
base::FilePath shutdown_ms_file;
PathService::Get(chrome::DIR_USER_DATA, &shutdown_ms_file);
return shutdown_ms_file.AppendASCII(kShutdownMsFile);
}
#if !defined(OS_ANDROID) #if !defined(OS_ANDROID)
bool ShutdownPreThreadsStop() { bool ShutdownPreThreadsStop() {
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
...@@ -273,6 +273,10 @@ void ShutdownPostThreadsStop(int shutdown_flags) { ...@@ -273,6 +273,10 @@ void ShutdownPostThreadsStop(int shutdown_flags) {
base::Int64ToString(shutdown_delta.InMilliseconds()); base::Int64ToString(shutdown_delta.InMilliseconds());
int len = static_cast<int>(shutdown_ms.length()) + 1; int len = static_cast<int>(shutdown_ms.length()) + 1;
base::FilePath shutdown_ms_file = GetShutdownMsPath(); base::FilePath shutdown_ms_file = GetShutdownMsPath();
// Note: ReadLastShutdownFile() is done as a BLOCK_SHUTDOWN task so there's
// an implicit sequencing between it and this write which happens after
// threads have been stopped (and thus TaskScheduler::Shutdown() is
// complete).
base::WriteFile(shutdown_ms_file, shutdown_ms.c_str(), len); base::WriteFile(shutdown_ms_file, shutdown_ms.c_str(), len);
} }
...@@ -285,7 +289,7 @@ void ShutdownPostThreadsStop(int shutdown_flags) { ...@@ -285,7 +289,7 @@ void ShutdownPostThreadsStop(int shutdown_flags) {
void ReadLastShutdownFile(ShutdownType type, void ReadLastShutdownFile(ShutdownType type,
int num_procs, int num_procs,
int num_procs_slow) { int num_procs_slow) {
DCHECK_CURRENTLY_ON(BrowserThread::FILE); base::ThreadRestrictions::AssertIOAllowed();
base::FilePath shutdown_ms_file = GetShutdownMsPath(); base::FilePath shutdown_ms_file = GetShutdownMsPath();
std::string shutdown_ms_str; std::string shutdown_ms_str;
...@@ -332,9 +336,10 @@ void ReadLastShutdownInfo() { ...@@ -332,9 +336,10 @@ void ReadLastShutdownInfo() {
UMA_HISTOGRAM_ENUMERATION("Shutdown.ShutdownType", type, kNumShutdownTypes); UMA_HISTOGRAM_ENUMERATION("Shutdown.ShutdownType", type, kNumShutdownTypes);
// Read and delete the file on the file thread. base::PostTaskWithTraits(
BrowserThread::PostTask( FROM_HERE,
BrowserThread::FILE, FROM_HERE, {base::MayBlock(), base::TaskPriority::BACKGROUND,
base::TaskShutdownBehavior::BLOCK_SHUTDOWN},
base::BindOnce(&ReadLastShutdownFile, type, num_procs, num_procs_slow)); base::BindOnce(&ReadLastShutdownFile, type, num_procs, num_procs_slow));
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment