| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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> | 5 #include <windows.h> |
| 6 #include <shlwapi.h> | 6 #include <shlwapi.h> |
| 7 | 7 |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "chrome/app/breakpad_win.h" | 9 #include "chrome/app/breakpad_win.h" |
| 10 #include "chrome/app/client_util.h" | 10 #include "chrome/app/client_util.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 bool EnvQueryStr(const wchar_t* key_name, std::wstring* value) { | 75 bool EnvQueryStr(const wchar_t* key_name, std::wstring* value) { |
| 76 wchar_t out[128]; | 76 wchar_t out[128]; |
| 77 DWORD count = sizeof(out)/sizeof(out[0]); | 77 DWORD count = sizeof(out)/sizeof(out[0]); |
| 78 DWORD rv = ::GetEnvironmentVariableW(key_name, out, count); | 78 DWORD rv = ::GetEnvironmentVariableW(key_name, out, count); |
| 79 if ((rv == 0) || (rv >= count)) | 79 if ((rv == 0) || (rv >= count)) |
| 80 return false; | 80 return false; |
| 81 *value = out; | 81 *value = out; |
| 82 return true; | 82 return true; |
| 83 } | 83 } |
| 84 | 84 |
| 85 bool IsRunningHeadless() { | |
| 86 return (0 != ::GetEnvironmentVariableW(L"CHROME_HEADLESS", NULL, 0)); | |
| 87 } | |
| 88 | |
| 89 // Expects that |dir| has a trailing backslash. |dir| is modified so it | 85 // Expects that |dir| has a trailing backslash. |dir| is modified so it |
| 90 // contains the full path that was tried. Caller must check for the return | 86 // contains the full path that was tried. Caller must check for the return |
| 91 // value not being null to dermine if this path contains a valid dll. | 87 // value not being null to dermine if this path contains a valid dll. |
| 92 HMODULE LoadChromeWithDirectory(std::wstring* dir) { | 88 HMODULE LoadChromeWithDirectory(std::wstring* dir) { |
| 93 ::SetCurrentDirectoryW(dir->c_str()); | 89 ::SetCurrentDirectoryW(dir->c_str()); |
| 94 const CommandLine& cmd_line = *CommandLine::ForCurrentProcess(); | 90 const CommandLine& cmd_line = *CommandLine::ForCurrentProcess(); |
| 95 #ifdef _WIN64 | 91 #ifdef _WIN64 |
| 96 if ((cmd_line.GetSwitchValueASCII(switches::kProcessType) == | 92 if ((cmd_line.GetSwitchValueASCII(switches::kProcessType) == |
| 97 switches::kNaClBrokerProcess) || | 93 switches::kNaClBrokerProcess) || |
| 98 (cmd_line.GetSwitchValueASCII(switches::kProcessType) == | 94 (cmd_line.GetSwitchValueASCII(switches::kProcessType) == |
| 99 switches::kNaClLoaderProcess)) { | 95 switches::kNaClLoaderProcess)) { |
| 100 // Load the 64-bit DLL when running in a 64-bit process. | 96 // Load the 64-bit DLL when running in a 64-bit process. |
| 101 dir->append(installer_util::kChromeNaCl64Dll); | 97 dir->append(installer_util::kChromeNaCl64Dll); |
| 102 } else { | 98 } else { |
| 103 // Only NaCl broker and loader can be launched as Win64 processes. | 99 // Only NaCl broker and loader can be launched as Win64 processes. |
| 104 NOTREACHED(); | 100 NOTREACHED(); |
| 105 return NULL; | 101 return NULL; |
| 106 } | 102 } |
| 107 #else | 103 #else |
| 108 dir->append(installer_util::kChromeDll); | 104 dir->append(installer_util::kChromeDll); |
| 109 #endif | 105 #endif |
| 110 | 106 |
| 111 #ifdef NDEBUG | 107 #ifdef NDEBUG |
| 112 // Experimental pre-reading optimization | 108 // Experimental pre-reading optimization |
| 113 // The idea is to pre read significant portion of chrome.dll in advance | 109 // The idea is to pre read significant portion of chrome.dll in advance |
| 114 // so that subsequent hard page faults are avoided. | 110 // so that subsequent hard page faults are avoided. |
| 115 if (!cmd_line.HasSwitch(switches::kProcessType) && | 111 if (!cmd_line.HasSwitch(switches::kProcessType)) { |
| 116 (IsRunningHeadless() || InstallUtil::IsChromeFrameProcess())) { | |
| 117 // The kernel brings in 8 pages for the code section at a time and 4 pages | 112 // The kernel brings in 8 pages for the code section at a time and 4 pages |
| 118 // for other sections. We can skip over these pages to avoid a soft page | 113 // for other sections. We can skip over these pages to avoid a soft page |
| 119 // fault which may not occur during code execution. However skipping 4K at | 114 // fault which may not occur during code execution. However skipping 4K at |
| 120 // a time still has better performance over 32K and 16K according to data. | 115 // a time still has better performance over 32K and 16K according to data. |
| 121 // TODO(ananta) | 116 // TODO(ananta) |
| 122 // Investigate this and tune. | 117 // Investigate this and tune. |
| 123 const size_t kStepSize = 4 * 1024; | 118 const size_t kStepSize = 4 * 1024; |
| 124 | 119 |
| 125 DWORD pre_read_size = 0; | 120 DWORD pre_read_size = 0; |
| 126 DWORD pre_read_step_size = kStepSize; | 121 DWORD pre_read_step_size = kStepSize; |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 } | 290 } |
| 296 }; | 291 }; |
| 297 | 292 |
| 298 MainDllLoader* MakeMainDllLoader() { | 293 MainDllLoader* MakeMainDllLoader() { |
| 299 #if defined(GOOGLE_CHROME_BUILD) | 294 #if defined(GOOGLE_CHROME_BUILD) |
| 300 return new ChromeDllLoader(); | 295 return new ChromeDllLoader(); |
| 301 #else | 296 #else |
| 302 return new ChromiumDllLoader(); | 297 return new ChromiumDllLoader(); |
| 303 #endif | 298 #endif |
| 304 } | 299 } |
| OLD | NEW |