OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <windows.h> // NOLINT | 5 #include <windows.h> // NOLINT |
6 #include <shlwapi.h> // NOLINT | 6 #include <shlwapi.h> // NOLINT |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <userenv.h> // NOLINT | 8 #include <userenv.h> // NOLINT |
9 | 9 |
10 #include "chrome/app/main_dll_loader_win.h" | 10 #include "chrome/app/main_dll_loader_win.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 typedef int (*DLL_MAIN)(HINSTANCE, sandbox::SandboxInterfaceInfo*); | 57 typedef int (*DLL_MAIN)(HINSTANCE, sandbox::SandboxInterfaceInfo*); |
58 | 58 |
59 typedef void (*RelaunchChromeBrowserWithNewCommandLineIfNeededFunc)(); | 59 typedef void (*RelaunchChromeBrowserWithNewCommandLineIfNeededFunc)(); |
60 | 60 |
61 // Loads |module| after setting the CWD to |module|'s directory. Returns a | 61 // Loads |module| after setting the CWD to |module|'s directory. Returns a |
62 // reference to the loaded module on success, or null on error. | 62 // reference to the loaded module on success, or null on error. |
63 HMODULE LoadModuleWithDirectory(const base::FilePath& module) { | 63 HMODULE LoadModuleWithDirectory(const base::FilePath& module) { |
64 ::SetCurrentDirectoryW(module.DirName().value().c_str()); | 64 ::SetCurrentDirectoryW(module.DirName().value().c_str()); |
65 | 65 |
66 // Get pre-read options from the PreRead field trial. | 66 // Get pre-read options from the PreRead field trial. |
67 bool trial_no_pre_read = false; | 67 int pre_read_options = startup_metric_utils::GetPreReadOptions( |
68 bool trial_high_priority = false; | 68 BrowserDistribution::GetDistribution()->GetRegistryPath()); |
69 bool trial_only_if_cold = false; | |
70 bool trial_prefetch_virtual_memory = false; | |
71 startup_metric_utils::GetPreReadOptions( | |
72 BrowserDistribution::GetDistribution()->GetRegistryPath(), | |
73 &trial_no_pre_read, &trial_high_priority, &trial_only_if_cold, | |
74 &trial_prefetch_virtual_memory); | |
75 | 69 |
76 // Pre-read the binary to warm the memory caches (avoids a lot of random IO). | 70 // Pre-read the binary to warm the memory caches (avoids a lot of random IO). |
77 if (!trial_no_pre_read) { | 71 if (!(pre_read_options & startup_metric_utils::NO_PRE_READ)) { |
78 base::ThreadPriority previous_priority = base::ThreadPriority::NORMAL; | 72 base::ThreadPriority previous_priority = base::ThreadPriority::NORMAL; |
79 if (trial_high_priority) { | 73 if (pre_read_options & startup_metric_utils::HIGH_PRIORITY) { |
80 previous_priority = base::PlatformThread::GetCurrentThreadPriority(); | 74 previous_priority = base::PlatformThread::GetCurrentThreadPriority(); |
81 base::PlatformThread::SetCurrentThreadPriority( | 75 base::PlatformThread::SetCurrentThreadPriority( |
82 base::ThreadPriority::DISPLAY); | 76 base::ThreadPriority::DISPLAY); |
83 } | 77 } |
84 | 78 |
85 if (trial_only_if_cold) { | 79 if (pre_read_options & startup_metric_utils::ONLY_IF_COLD) { |
86 base::MemoryMappedFile module_memory_map; | 80 base::MemoryMappedFile module_memory_map; |
87 const bool map_initialize_success = module_memory_map.Initialize(module); | 81 const bool map_initialize_success = module_memory_map.Initialize(module); |
88 DCHECK(map_initialize_success); | 82 DCHECK(map_initialize_success); |
89 if (!IsMemoryMappedFileWarm(module_memory_map)) { | 83 if (!IsMemoryMappedFileWarm(module_memory_map)) { |
90 if (trial_prefetch_virtual_memory) | 84 if (pre_read_options & startup_metric_utils::PREFETCH_VIRTUAL_MEMORY) |
91 PreReadMemoryMappedFile(module_memory_map, module); | 85 PreReadMemoryMappedFile(module_memory_map, module); |
92 else | 86 else |
93 PreReadFile(module); | 87 PreReadFile(module); |
94 } | 88 } |
95 } else if (trial_prefetch_virtual_memory) { | 89 } else if (pre_read_options & |
| 90 startup_metric_utils::PREFETCH_VIRTUAL_MEMORY) { |
96 base::MemoryMappedFile module_memory_map; | 91 base::MemoryMappedFile module_memory_map; |
97 const bool map_initialize_success = module_memory_map.Initialize(module); | 92 const bool map_initialize_success = module_memory_map.Initialize(module); |
98 DCHECK(map_initialize_success); | 93 DCHECK(map_initialize_success); |
99 PreReadMemoryMappedFile(module_memory_map, module); | 94 PreReadMemoryMappedFile(module_memory_map, module); |
100 } else { | 95 } else { |
101 PreReadFile(module); | 96 PreReadFile(module); |
102 } | 97 } |
103 | 98 |
104 if (trial_high_priority) | 99 if (pre_read_options & startup_metric_utils::HIGH_PRIORITY) |
105 base::PlatformThread::SetCurrentThreadPriority(previous_priority); | 100 base::PlatformThread::SetCurrentThreadPriority(previous_priority); |
106 } | 101 } |
107 | 102 |
108 return ::LoadLibraryExW(module.value().c_str(), nullptr, | 103 return ::LoadLibraryExW(module.value().c_str(), nullptr, |
109 LOAD_WITH_ALTERED_SEARCH_PATH); | 104 LOAD_WITH_ALTERED_SEARCH_PATH); |
110 } | 105 } |
111 | 106 |
112 void RecordDidRun(const base::FilePath& dll_path) { | 107 void RecordDidRun(const base::FilePath& dll_path) { |
113 bool system_level = !InstallUtil::IsPerUserInstall(dll_path); | 108 bool system_level = !InstallUtil::IsPerUserInstall(dll_path); |
114 GoogleUpdateSettings::UpdateDidRunState(true, system_level); | 109 GoogleUpdateSettings::UpdateDidRunState(true, system_level); |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 } | 385 } |
391 }; | 386 }; |
392 | 387 |
393 MainDllLoader* MakeMainDllLoader() { | 388 MainDllLoader* MakeMainDllLoader() { |
394 #if defined(GOOGLE_CHROME_BUILD) | 389 #if defined(GOOGLE_CHROME_BUILD) |
395 return new ChromeDllLoader(); | 390 return new ChromeDllLoader(); |
396 #else | 391 #else |
397 return new ChromiumDllLoader(); | 392 return new ChromiumDllLoader(); |
398 #endif | 393 #endif |
399 } | 394 } |
OLD | NEW |