summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-25 06:54:11 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-25 06:54:11 +0000
commit61e9572d1eeadfd4eb8326515fa73e3826de3111 (patch)
treec08d7c6889007449cc16df7e20c4b274767cdc7f /chrome/browser
parentfcd58d1762447670f2acfbcd7d377cbfd16b7541 (diff)
downloadchromium_src-61e9572d1eeadfd4eb8326515fa73e3826de3111.zip
chromium_src-61e9572d1eeadfd4eb8326515fa73e3826de3111.tar.gz
chromium_src-61e9572d1eeadfd4eb8326515fa73e3826de3111.tar.bz2
Move last shutdown file access off the UI thread and onto the file thread.
Review URL: http://codereview.chromium.org/437049 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33056 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/browser_main.cc15
-rw-r--r--chrome/browser/browser_shutdown.cc73
2 files changed, 52 insertions, 36 deletions
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc
index faaca82..aff0551 100644
--- a/chrome/browser/browser_main.cc
+++ b/chrome/browser/browser_main.cc
@@ -624,6 +624,13 @@ int BrowserMain(const MainFunctionParams& parameters) {
base::Time::Now().ToTimeT());
}
+ // Create the child threads. We need to do this since ChromeThread::PostTask
+ // silently deletes a posted task if the target message loop isn't created.
+ browser_process->db_thread();
+ browser_process->file_thread();
+ browser_process->process_launcher_thread();
+ browser_process->io_thread();
+
#if defined(OS_WIN)
// Record last shutdown time into a histogram.
browser_shutdown::ReadLastShutdownInfo();
@@ -650,14 +657,6 @@ int BrowserMain(const MainFunctionParams& parameters) {
}
}
- // Create the child threads. We need to do this since ChromeThread::PostTask
- // silently deletes a posted task if the target message loop isn't created.
- // Note: must be done before FirstRun code is started.
- browser_process->db_thread();
- browser_process->file_thread();
- browser_process->process_launcher_thread();
- browser_process->io_thread();
-
// Importing other browser settings is done in a browser-like process
// that exits when this task has finished.
#if defined(OS_WIN)
diff --git a/chrome/browser/browser_shutdown.cc b/chrome/browser/browser_shutdown.cc
index 0b6d680..474410f 100644
--- a/chrome/browser/browser_shutdown.cc
+++ b/chrome/browser/browser_shutdown.cc
@@ -168,7 +168,13 @@ void Shutdown() {
}
#if defined(OS_WIN)
-void ReadLastShutdownInfo() {
+
+void ReadLastShutdownFile(
+ ShutdownType type,
+ int num_procs,
+ int num_procs_slow) {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE));
+
FilePath shutdown_ms_file = GetShutdownMsPath();
std::string shutdown_ms_str;
int64 shutdown_ms = 0;
@@ -176,6 +182,39 @@ void ReadLastShutdownInfo() {
shutdown_ms = StringToInt64(shutdown_ms_str);
file_util::Delete(shutdown_ms_file, false);
+ if (type == NOT_VALID || shutdown_ms == 0 || num_procs == 0)
+ return;
+
+ const char *time_fmt = "Shutdown.%s.time";
+ const char *time_per_fmt = "Shutdown.%s.time_per_process";
+ std::string time;
+ std::string time_per;
+ if (type == WINDOW_CLOSE) {
+ time = StringPrintf(time_fmt, "window_close");
+ time_per = StringPrintf(time_per_fmt, "window_close");
+ } else if (type == BROWSER_EXIT) {
+ time = StringPrintf(time_fmt, "browser_exit");
+ time_per = StringPrintf(time_per_fmt, "browser_exit");
+ } else if (type == END_SESSION) {
+ time = StringPrintf(time_fmt, "end_session");
+ time_per = StringPrintf(time_per_fmt, "end_session");
+ } else {
+ NOTREACHED();
+ }
+
+ if (time.empty())
+ return;
+
+ // TODO(erikkay): change these to UMA histograms after a bit more testing.
+ UMA_HISTOGRAM_TIMES(time.c_str(),
+ TimeDelta::FromMilliseconds(shutdown_ms));
+ UMA_HISTOGRAM_TIMES(time_per.c_str(),
+ TimeDelta::FromMilliseconds(shutdown_ms / num_procs));
+ UMA_HISTOGRAM_COUNTS_100("Shutdown.renderers.total", num_procs);
+ UMA_HISTOGRAM_COUNTS_100("Shutdown.renderers.slow", num_procs_slow);
+}
+
+void ReadLastShutdownInfo() {
PrefService* prefs = g_browser_process->local_state();
ShutdownType type =
static_cast<ShutdownType>(prefs->GetInteger(prefs::kShutdownType));
@@ -186,33 +225,11 @@ void ReadLastShutdownInfo() {
prefs->SetInteger(prefs::kShutdownNumProcesses, 0);
prefs->SetInteger(prefs::kShutdownNumProcessesSlow, 0);
- if (type > NOT_VALID && shutdown_ms > 0 && num_procs > 0) {
- const char *time_fmt = "Shutdown.%s.time";
- const char *time_per_fmt = "Shutdown.%s.time_per_process";
- std::string time;
- std::string time_per;
- if (type == WINDOW_CLOSE) {
- time = StringPrintf(time_fmt, "window_close");
- time_per = StringPrintf(time_per_fmt, "window_close");
- } else if (type == BROWSER_EXIT) {
- time = StringPrintf(time_fmt, "browser_exit");
- time_per = StringPrintf(time_per_fmt, "browser_exit");
- } else if (type == END_SESSION) {
- time = StringPrintf(time_fmt, "end_session");
- time_per = StringPrintf(time_per_fmt, "end_session");
- } else {
- NOTREACHED();
- }
- if (time.length()) {
- // TODO(erikkay): change these to UMA histograms after a bit more testing.
- UMA_HISTOGRAM_TIMES(time.c_str(),
- TimeDelta::FromMilliseconds(shutdown_ms));
- UMA_HISTOGRAM_TIMES(time_per.c_str(),
- TimeDelta::FromMilliseconds(shutdown_ms / num_procs));
- UMA_HISTOGRAM_COUNTS_100("Shutdown.renderers.total", num_procs);
- UMA_HISTOGRAM_COUNTS_100("Shutdown.renderers.slow", num_procs_slow);
- }
- }
+ // Read and delete the file on the file thread.
+ ChromeThread::PostTask(
+ ChromeThread::FILE, FROM_HERE,
+ NewRunnableFunction(
+ &ReadLastShutdownFile, type, num_procs, num_procs_slow));
}
#endif