Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8482)

Unified Diff: chrome/common/prefetch_argument_win.cc

Issue 1595633002: Use valid /prefetch arguments for process launches on Windows. - do not submit (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move
Patch Set: address simple comments from gab Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/common/prefetch_argument_win.h ('k') | chrome/common/service_process_util.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/prefetch_argument_win.cc
diff --git a/chrome/common/prefetch_argument_win.cc b/chrome/common/prefetch_argument_win.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b6afdf54a5a569595a4e67caf865e08c5f2e94d8
--- /dev/null
+++ b/chrome/common/prefetch_argument_win.cc
@@ -0,0 +1,62 @@
+// Copyright (c) 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/common/prefetch_argument_win.h"
+
+#include <string>
+
+#include "base/command_line.h"
+#include "base/logging.h"
+#include "base/strings/stringprintf.h"
+#include "chrome/common/chrome_switches.h"
+#include "chrome/installer/util/browser_distribution.h"
+#include "components/startup_metric_utils/common/pre_read_field_trial_utils_win.h"
+#include "content/public/common/content_switches.h"
+
+namespace chrome {
+
+void AddWindowsPrefetchArgument(base::CommandLine* command_line) {
+ DCHECK(command_line);
+
+ int pre_read_options = startup_metric_utils::GetPreReadOptions(
+ BrowserDistribution::GetDistribution()->GetRegistryPath());
+ if (pre_read_options & startup_metric_utils::NO_PREFETCH_ARGUMENT)
+ return;
+
+ const std::string process_type =
+ command_line->GetSwitchValueASCII(switches::kProcessType);
+
+ // There can be 9 prefetch profiles per executable: a profile for launches
+ // without a /prefetch argument and a profile per /prefetch:# argument, where
+ // # is [1, 8].
+ int prefetch_id;
+
+ if (process_type.empty()) {
+ // No prefetch argument when the browser process is launched in foreground.
+ if (!command_line->HasSwitch(switches::kNoStartupWindow))
+ return;
+ prefetch_id = 1;
+ } else if (process_type == switches::kRendererProcess) {
+ prefetch_id = 2;
+ } else if (process_type == switches::kGpuProcess) {
+ prefetch_id = 3;
+ } else if (process_type == switches::kPpapiPluginProcess) {
+ prefetch_id = 4;
+ } else {
+ // Default prefetch argument, shared by all other process types. It is
+ // likely that the prefetcher will never prefetch anything for these process
+ // types as it won't be able to observe consistent file reads across
+ // launches, but a least by using a custom profile they won't interfere with
+ // the default profile used by the browser process.
+ prefetch_id = 8;
+ }
+
+ DCHECK_GE(prefetch_id, 0);
+ DCHECK_LE(prefetch_id, 8);
+
+ if (prefetch_id != 0)
+ command_line->AppendArg(base::StringPrintf("/prefetch:%d", prefetch_id));
+}
+
+} // namespace chrome
« no previous file with comments | « chrome/common/prefetch_argument_win.h ('k') | chrome/common/service_process_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698