| 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 "chrome/app/breakpad_win.h" | 9 #include "chrome/app/breakpad_win.h" |
| 9 #include "chrome/app/client_util.h" | 10 #include "chrome/app/client_util.h" |
| 10 #include "chrome/common/chrome_switches.h" | 11 #include "chrome/common/chrome_switches.h" |
| 11 #include "chrome/common/result_codes.h" | 12 #include "chrome/common/result_codes.h" |
| 12 #include "chrome/installer/util/browser_distribution.h" | 13 #include "chrome/installer/util/browser_distribution.h" |
| 13 #include "chrome/installer/util/install_util.h" | 14 #include "chrome/installer/util/install_util.h" |
| 14 #include "chrome/installer/util/google_update_constants.h" | 15 #include "chrome/installer/util/google_update_constants.h" |
| 15 #include "chrome/installer/util/util_constants.h" | 16 #include "chrome/installer/util/util_constants.h" |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 NOTREACHED(); | 104 NOTREACHED(); |
| 104 return NULL; | 105 return NULL; |
| 105 } | 106 } |
| 106 #else | 107 #else |
| 107 dir->append(installer_util::kChromeDll); | 108 dir->append(installer_util::kChromeDll); |
| 108 #endif | 109 #endif |
| 109 | 110 |
| 110 // Experimental pre-reading optimization | 111 // Experimental pre-reading optimization |
| 111 // The idea is to pre read significant portion of chrome.dll in advance | 112 // The idea is to pre read significant portion of chrome.dll in advance |
| 112 // so that subsequent hard page faults are avoided. | 113 // so that subsequent hard page faults are avoided. |
| 113 DWORD pre_read_size_mb = 0; | |
| 114 if (!cmd_line.HasSwitch(switches::kProcessType) && | 114 if (!cmd_line.HasSwitch(switches::kProcessType) && |
| 115 (IsRunningHeadless() || InstallUtil::IsChromeFrameProcess())) { | 115 (IsRunningHeadless() || InstallUtil::IsChromeFrameProcess())) { |
| 116 // The kernel brings in 8 pages for the code section at a time and 4 pages |
| 117 // for other sections. We can skip over these pages to avoid a soft page |
| 118 // fault which may not occur during code execution. However skipping 4K at |
| 119 // a time still has better performance over 32K and 16K according to data. |
| 120 // TODO(ananta) |
| 121 // Investigate this and tune. |
| 122 const size_t kStepSize = 4 * 1024; |
| 123 |
| 124 DWORD pre_read_size = 0; |
| 125 DWORD pre_read_step_size = kStepSize; |
| 126 DWORD pre_read = 1; |
| 127 |
| 116 HKEY key = NULL; | 128 HKEY key = NULL; |
| 117 if (::RegOpenKeyEx(HKEY_CURRENT_USER, L"Software\\Google\\ChromeFrame", | 129 if (::RegOpenKeyEx(HKEY_CURRENT_USER, L"Software\\Google\\ChromeFrame", |
| 118 0, KEY_QUERY_VALUE, &key) == ERROR_SUCCESS) { | 130 0, KEY_QUERY_VALUE, &key) == ERROR_SUCCESS) { |
| 119 DWORD unused = sizeof(pre_read_size_mb); | 131 DWORD unused = sizeof(pre_read_size); |
| 120 if (::RegQueryValueEx(key, L"PreRead", NULL, NULL, | 132 RegQueryValueEx(key, L"PreReadSize", NULL, NULL, |
| 121 reinterpret_cast<LPBYTE>(&pre_read_size_mb), | 133 reinterpret_cast<LPBYTE>(&pre_read_size), &unused); |
| 122 &unused) != ERROR_SUCCESS) { | 134 RegQueryValueEx(key, L"PreReadStepSize", NULL, NULL, |
| 123 pre_read_size_mb = 16; // Default | 135 reinterpret_cast<LPBYTE>(&pre_read_step_size), &unused); |
| 124 } | 136 unused = sizeof(pre_read); |
| 137 RegQueryValueEx(key, L"PreRead", NULL, NULL, |
| 138 reinterpret_cast<LPBYTE>(&pre_read), &unused); |
| 125 RegCloseKey(key); | 139 RegCloseKey(key); |
| 126 key = NULL; | 140 key = NULL; |
| 127 } else { | 141 } |
| 128 pre_read_size_mb = 16; // Read in first 16 MB by default. | 142 if (pre_read) { |
| 143 file_util::PreReadImage(dir->c_str(), pre_read_size, pre_read_step_size); |
| 129 } | 144 } |
| 130 } | 145 } |
| 131 | 146 |
| 132 if (pre_read_size_mb) { | |
| 133 HANDLE chrome_dll = CreateFile(dir->c_str(), | |
| 134 GENERIC_READ, | |
| 135 FILE_SHARE_READ | FILE_SHARE_WRITE, | |
| 136 NULL, | |
| 137 OPEN_EXISTING, | |
| 138 FILE_FLAG_SEQUENTIAL_SCAN, | |
| 139 NULL); | |
| 140 if (chrome_dll == INVALID_HANDLE_VALUE) { | |
| 141 DWORD error = GetLastError(); | |
| 142 DLOG(ERROR) << __FUNCTION__ << " CreateFile( " | |
| 143 << dir->c_str() << " ) failed. Error: " << error; | |
| 144 } else { | |
| 145 const size_t kChunkSize = 1024 * 1024; // 1 MB | |
| 146 void* buffer = VirtualAlloc(NULL, kChunkSize, MEM_COMMIT, PAGE_READWRITE); | |
| 147 if (buffer) { | |
| 148 size_t read_size = pre_read_size_mb * kChunkSize; | |
| 149 DWORD read = 0; | |
| 150 while (::ReadFile(chrome_dll, buffer, kChunkSize, &read, NULL)) { | |
| 151 // nothing to do here... | |
| 152 read_size -= std::min(size_t(read), read_size); | |
| 153 if (!read || !read_size) | |
| 154 break; | |
| 155 } | |
| 156 | |
| 157 VirtualFree(buffer, 0, MEM_RELEASE); | |
| 158 } | |
| 159 | |
| 160 CloseHandle(chrome_dll); | |
| 161 } | |
| 162 } | |
| 163 | |
| 164 return ::LoadLibraryExW(dir->c_str(), NULL, | 147 return ::LoadLibraryExW(dir->c_str(), NULL, |
| 165 LOAD_WITH_ALTERED_SEARCH_PATH); | 148 LOAD_WITH_ALTERED_SEARCH_PATH); |
| 166 } | 149 } |
| 167 | 150 |
| 168 // Set did_run "dr" in omaha's client state for this product. | 151 // Set did_run "dr" in omaha's client state for this product. |
| 169 bool SetDidRunState(const wchar_t* guid, const wchar_t* value) { | 152 bool SetDidRunState(const wchar_t* guid, const wchar_t* value) { |
| 170 std::wstring key_path(google_update::kRegPathClientState); | 153 std::wstring key_path(google_update::kRegPathClientState); |
| 171 key_path.append(L"\\").append(guid); | 154 key_path.append(L"\\").append(guid); |
| 172 HKEY reg_key; | 155 HKEY reg_key; |
| 173 if (::RegCreateKeyExW(HKEY_CURRENT_USER, key_path.c_str(), 0, NULL, | 156 if (::RegCreateKeyExW(HKEY_CURRENT_USER, key_path.c_str(), 0, NULL, |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 } | 294 } |
| 312 }; | 295 }; |
| 313 | 296 |
| 314 MainDllLoader* MakeMainDllLoader() { | 297 MainDllLoader* MakeMainDllLoader() { |
| 315 #if defined(GOOGLE_CHROME_BUILD) | 298 #if defined(GOOGLE_CHROME_BUILD) |
| 316 return new ChromeDllLoader(); | 299 return new ChromeDllLoader(); |
| 317 #else | 300 #else |
| 318 return new ChromiumDllLoader(); | 301 return new ChromiumDllLoader(); |
| 319 #endif | 302 #endif |
| 320 } | 303 } |
| OLD | NEW |