Use a valid /prefetch argument when launching a process.
The /prefetch:# argument that is currently added to the command line of
processes launched with content::StartSandboxedProcess is ignored by
Windows because # doesn't respect the [1, 8] constraint.
This CL ensures that a valid /prefetch:# argument is used for every
process launch (except when the feature is disabled by the PreRead
field trial).
BUG=577698
Review URL: https://codereview.chromium.org/1612663002
Cr-Commit-Position: refs/heads/master@{#373241}
diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn
index 2bea1a18..e22de2a 100644
--- a/chrome/browser/BUILD.gn
+++ b/chrome/browser/BUILD.gn
@@ -162,6 +162,10 @@
"//components/ssl_errors",
"//components/startup_metric_utils/browser:lib",
"//components/startup_metric_utils/browser:message_filter_lib",
+
+ # TODO(fdoray): Remove this once the PreRead field trial has expired.
+ # crbug.com/577698
+ "//components/startup_metric_utils/common",
"//components/strings",
"//components/suggestions",
"//components/sync_bookmarks",
diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc
index cef743b..005f950 100644
--- a/chrome/browser/browser_process_impl.cc
+++ b/chrome/browser/browser_process_impl.cc
@@ -111,6 +111,7 @@
#if defined(OS_WIN)
#include "base/win/windows_version.h"
+#include "components/startup_metric_utils/common/pre_read_field_trial_utils_win.h"
#include "ui/views/focus/view_storage.h"
#elif defined(OS_MACOSX)
#include "chrome/browser/chrome_browser_main_mac.h"
@@ -1268,6 +1269,11 @@
new_cl->AppendSwitch(kSwitchesToAddOnAutorestart[i]);
}
+#if defined(OS_WIN)
+ if (startup_metric_utils::GetPreReadOptions().use_prefetch_argument)
+ new_cl->AppendArg(switches::kPrefetchArgumentBrowserBackground);
+#endif // defined(OS_WIN)
+
DLOG(WARNING) << "Shutting down current instance of the browser.";
chrome::AttemptExit();
diff --git a/chrome/browser/chrome_browser_main.cc b/chrome/browser/chrome_browser_main.cc
index 81bbef48..0f156e6 100644
--- a/chrome/browser/chrome_browser_main.cc
+++ b/chrome/browser/chrome_browser_main.cc
@@ -583,7 +583,10 @@
registry_path,
base::Bind(&ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrial));
- // After startup is complete, update the pre-read group in the registry. The
+ // Initialize the PreRead options for the current process.
+ startup_metric_utils::InitializePreReadOptions(registry_path);
+
+ // After startup is complete, update the PreRead group in the registry. The
// group written in the registry will be used for the next startup.
BrowserThread::PostAfterStartupTask(
FROM_HERE, content::BrowserThread::GetBlockingPool(),
diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc
index 84fe4f0..194337d 100644
--- a/chrome/browser/chrome_content_browser_client.cc
+++ b/chrome/browser/chrome_content_browser_client.cc
@@ -168,6 +168,7 @@
#include "base/strings/string_tokenizer.h"
#include "base/win/windows_version.h"
#include "chrome/browser/chrome_browser_main_win.h"
+#include "components/startup_metric_utils/common/pre_read_field_trial_utils_win.h"
#include "sandbox/win/src/sandbox_policy.h"
#elif defined(OS_MACOSX)
#include "chrome/browser/chrome_browser_main_mac.h"
@@ -2693,6 +2694,10 @@
return false;
}
+
+bool ChromeContentBrowserClient::ShouldUseWindowsPrefetchArgument() const {
+ return startup_metric_utils::GetPreReadOptions().use_prefetch_argument;
+}
#endif // defined(OS_WIN)
void ChromeContentBrowserClient::RegisterFrameMojoShellServices(
diff --git a/chrome/browser/chrome_content_browser_client.h b/chrome/browser/chrome_content_browser_client.h
index 150c923..2a446549 100644
--- a/chrome/browser/chrome_content_browser_client.h
+++ b/chrome/browser/chrome_content_browser_client.h
@@ -281,6 +281,7 @@
int sandbox_type) const override;
bool IsWin32kLockdownEnabledForMimeType(
const std::string& mime_type) const override;
+ bool ShouldUseWindowsPrefetchArgument() const override;
#endif
void RegisterFrameMojoShellServices(
content::ServiceRegistry* registry,