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 @@
#include "base/metrics/histogram_macros.h"
#include "base/path_service.h"
#include "base/strings/string_number_conversions.h"
#include "base/task_scheduler/post_task.h"
#include "base/threading/thread.h"
#include "base/threading/thread_restrictions.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "chrome/browser/about_flags.h"
......@@ -34,7 +36,6 @@
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.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/tracing_controller.h"
#include "printing/features/features.h"
......@@ -68,7 +69,6 @@
using base::Time;
using base::TimeDelta;
using content::BrowserThread;
namespace browser_shutdown {
namespace {
......@@ -81,7 +81,13 @@ ShutdownType g_shutdown_type = NOT_VALID;
int g_shutdown_num_processes;
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) {
switch (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)
bool ShutdownPreThreadsStop() {
#if defined(OS_CHROMEOS)
......@@ -273,6 +273,10 @@ void ShutdownPostThreadsStop(int shutdown_flags) {
base::Int64ToString(shutdown_delta.InMilliseconds());
int len = static_cast<int>(shutdown_ms.length()) + 1;
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);
}
......@@ -285,7 +289,7 @@ void ShutdownPostThreadsStop(int shutdown_flags) {
void ReadLastShutdownFile(ShutdownType type,
int num_procs,
int num_procs_slow) {
DCHECK_CURRENTLY_ON(BrowserThread::FILE);
base::ThreadRestrictions::AssertIOAllowed();
base::FilePath shutdown_ms_file = GetShutdownMsPath();
std::string shutdown_ms_str;
......@@ -332,9 +336,10 @@ void ReadLastShutdownInfo() {
UMA_HISTOGRAM_ENUMERATION("Shutdown.ShutdownType", type, kNumShutdownTypes);
// Read and delete the file on the file thread.
BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE,
base::PostTaskWithTraits(
FROM_HERE,
{base::MayBlock(), base::TaskPriority::BACKGROUND,
base::TaskShutdownBehavior::BLOCK_SHUTDOWN},
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