Commit f01f4835 authored by Bettina Dea's avatar Bettina Dea Committed by Commit Bot

Use a static variable to store creation time of first run.

Calling GetFileInfo() is a blocking call and because the desktop feature
tracker needs the first run creation time, it was performing file I/O on
the UI thread causing jank. This change moves getting the creation time to
sentinel creation and caches that result in a static variable.

Bug: 785189
Change-Id: Ia4b4e5783bf3e6d06c9812661d7930384cbf9b21
Reviewed-on: https://chromium-review.googlesource.com/773445Reviewed-by: default avatarCarlos Pizano <cpu@chromium.org>
Reviewed-by: default avatarRobert Liao <robliao@chromium.org>
Reviewed-by: default avatarWez <wez@chromium.org>
Commit-Queue: Bettina Dea <bdea@chromium.org>
Cr-Commit-Position: refs/heads/master@{#517914}
parent 105ce465
...@@ -423,6 +423,19 @@ void ProcessDefaultBrowserPolicy(bool make_chrome_default_for_user) { ...@@ -423,6 +423,19 @@ void ProcessDefaultBrowserPolicy(bool make_chrome_default_for_user) {
} }
} }
// Reads the creation time of the first run sentinel file. If the first run
// sentinel file does not exist, it will return base::Time().
base::Time ReadFirstRunSentinelCreationTime() {
base::Time first_run_sentinel_creation_time = base::Time();
base::FilePath first_run_sentinel;
if (first_run::internal::GetFirstRunSentinelFilePath(&first_run_sentinel)) {
base::File::Info info;
if (base::GetFileInfo(first_run_sentinel, &info))
first_run_sentinel_creation_time = info.creation_time;
}
return first_run_sentinel_creation_time;
}
} // namespace } // namespace
namespace first_run { namespace first_run {
...@@ -555,17 +568,15 @@ bool IsMetricsReportingOptIn() { ...@@ -555,17 +568,15 @@ bool IsMetricsReportingOptIn() {
void CreateSentinelIfNeeded() { void CreateSentinelIfNeeded() {
if (IsChromeFirstRun()) if (IsChromeFirstRun())
internal::CreateSentinel(); internal::CreateSentinel();
// Causes the first run sentinel creation time to be read and cached, while
// I/O is still allowed.
ignore_result(GetFirstRunSentinelCreationTime());
} }
base::Time GetFirstRunSentinelCreationTime() { base::Time GetFirstRunSentinelCreationTime() {
base::FilePath first_run_sentinel; static const base::Time cached_time = ReadFirstRunSentinelCreationTime();
base::Time first_run_sentinel_creation_time = base::Time(); return cached_time;
if (first_run::internal::GetFirstRunSentinelFilePath(&first_run_sentinel)) {
base::File::Info info;
if (base::GetFileInfo(first_run_sentinel, &info))
first_run_sentinel_creation_time = info.creation_time;
}
return first_run_sentinel_creation_time;
} }
bool SetShowFirstRunBubblePref(FirstRunBubbleOptions show_bubble_option) { bool SetShowFirstRunBubblePref(FirstRunBubbleOptions show_bubble_option) {
......
...@@ -115,8 +115,8 @@ bool IsMetricsReportingOptIn(); ...@@ -115,8 +115,8 @@ bool IsMetricsReportingOptIn();
// (http://crbug.com/264694). // (http://crbug.com/264694).
void CreateSentinelIfNeeded(); void CreateSentinelIfNeeded();
// Returns the creation time of the first run sentinel file. If the first run // Returns the first run sentinel creation time. This only requires I/O
// sentinel file does not exist, it will return base::Time(). // permission on the sequence it is first called on.
base::Time GetFirstRunSentinelCreationTime(); base::Time GetFirstRunSentinelCreationTime();
// Sets the kShowFirstRunBubbleOption local state pref so that the browser // Sets the kShowFirstRunBubbleOption local state pref so that the browser
......
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