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 startup_metric_utils::InitializePreReadOptions( |
68 bool trial_high_priority = false; | 68 BrowserDistribution::GetDistribution()->GetRegistryPath()); |
69 bool trial_only_if_cold = false; | 69 const startup_metric_utils::PreReadOptions pre_read_options = |
70 bool trial_prefetch_virtual_memory = false; | 70 startup_metric_utils::GetPreReadOptions(); |
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 | 71 |
76 // Pre-read the binary to warm the memory caches (avoids a lot of random IO). | 72 // Pre-read the binary to warm the memory caches (avoids a lot of random IO). |
77 if (!trial_no_pre_read) { | 73 if (!pre_read_options.no_pre_read) { |
78 base::ThreadPriority previous_priority = base::ThreadPriority::NORMAL; | 74 base::ThreadPriority previous_priority = base::ThreadPriority::NORMAL; |
79 if (trial_high_priority) { | 75 if (pre_read_options.high_priority) { |
80 previous_priority = base::PlatformThread::GetCurrentThreadPriority(); | 76 previous_priority = base::PlatformThread::GetCurrentThreadPriority(); |
81 base::PlatformThread::SetCurrentThreadPriority( | 77 base::PlatformThread::SetCurrentThreadPriority( |
82 base::ThreadPriority::DISPLAY); | 78 base::ThreadPriority::DISPLAY); |
83 } | 79 } |
84 | 80 |
85 if (trial_only_if_cold) { | 81 if (pre_read_options.only_if_cold) { |
86 base::MemoryMappedFile module_memory_map; | 82 base::MemoryMappedFile module_memory_map; |
87 const bool map_initialize_success = module_memory_map.Initialize(module); | 83 const bool map_initialize_success = module_memory_map.Initialize(module); |
88 DCHECK(map_initialize_success); | 84 DCHECK(map_initialize_success); |
89 if (!IsMemoryMappedFileWarm(module_memory_map)) { | 85 if (!IsMemoryMappedFileWarm(module_memory_map)) { |
90 if (trial_prefetch_virtual_memory) | 86 if (pre_read_options.prefetch_virtual_memory) |
91 PreReadMemoryMappedFile(module_memory_map, module); | 87 PreReadMemoryMappedFile(module_memory_map, module); |
92 else | 88 else |
93 PreReadFile(module); | 89 PreReadFile(module); |
94 } | 90 } |
95 } else if (trial_prefetch_virtual_memory) { | 91 } else if (pre_read_options.prefetch_virtual_memory) { |
96 base::MemoryMappedFile module_memory_map; | 92 base::MemoryMappedFile module_memory_map; |
97 const bool map_initialize_success = module_memory_map.Initialize(module); | 93 const bool map_initialize_success = module_memory_map.Initialize(module); |
98 DCHECK(map_initialize_success); | 94 DCHECK(map_initialize_success); |
99 PreReadMemoryMappedFile(module_memory_map, module); | 95 PreReadMemoryMappedFile(module_memory_map, module); |
100 } else { | 96 } else { |
101 PreReadFile(module); | 97 PreReadFile(module); |
102 } | 98 } |
103 | 99 |
104 if (trial_high_priority) | 100 if (pre_read_options.high_priority) |
105 base::PlatformThread::SetCurrentThreadPriority(previous_priority); | 101 base::PlatformThread::SetCurrentThreadPriority(previous_priority); |
106 } | 102 } |
107 | 103 |
108 return ::LoadLibraryExW(module.value().c_str(), nullptr, | 104 return ::LoadLibraryExW(module.value().c_str(), nullptr, |
109 LOAD_WITH_ALTERED_SEARCH_PATH); | 105 LOAD_WITH_ALTERED_SEARCH_PATH); |
110 } | 106 } |
111 | 107 |
112 void RecordDidRun(const base::FilePath& dll_path) { | 108 void RecordDidRun(const base::FilePath& dll_path) { |
113 bool system_level = !InstallUtil::IsPerUserInstall(dll_path); | 109 bool system_level = !InstallUtil::IsPerUserInstall(dll_path); |
114 GoogleUpdateSettings::UpdateDidRunState(true, system_level); | 110 GoogleUpdateSettings::UpdateDidRunState(true, system_level); |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 } | 386 } |
391 }; | 387 }; |
392 | 388 |
393 MainDllLoader* MakeMainDllLoader() { | 389 MainDllLoader* MakeMainDllLoader() { |
394 #if defined(GOOGLE_CHROME_BUILD) | 390 #if defined(GOOGLE_CHROME_BUILD) |
395 return new ChromeDllLoader(); | 391 return new ChromeDllLoader(); |
396 #else | 392 #else |
397 return new ChromiumDllLoader(); | 393 return new ChromiumDllLoader(); |
398 #endif | 394 #endif |
399 } | 395 } |
OLD | NEW |