[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
[email protected] | c9349d08 | 2008-08-22 21:16:47 | [diff] [blame] | 4 | |
[email protected] | 4512f3ac | 2009-11-04 03:39:22 | [diff] [blame] | 5 | #include <windows.h> |
| 6 | #include <shlwapi.h> |
[email protected] | c9349d08 | 2008-08-22 21:16:47 | [diff] [blame] | 7 | |
[email protected] | 5d91c9e | 2010-07-28 17:25:28 | [diff] [blame] | 8 | #include "base/command_line.h" |
[email protected] | 5858035 | 2010-10-26 04:07:50 | [diff] [blame] | 9 | #include "base/debug/trace_event.h" |
[email protected] | ae0f077 | 2010-08-13 04:54:10 | [diff] [blame] | 10 | #include "base/environment.h" |
[email protected] | 85286b5 | 2010-07-03 06:14:45 | [diff] [blame] | 11 | #include "base/file_util.h" |
[email protected] | ae0f077 | 2010-08-13 04:54:10 | [diff] [blame] | 12 | #include "base/logging.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 13 | #include "base/memory/scoped_ptr.h" |
[email protected] | 2544a7a | 2011-03-14 18:25:19 | [diff] [blame] | 14 | #include "base/win/registry.h" |
[email protected] | 36ee032 | 2010-12-23 21:27:12 | [diff] [blame] | 15 | #include "base/string_util.h" |
[email protected] | ae0f077 | 2010-08-13 04:54:10 | [diff] [blame] | 16 | #include "base/utf_string_conversions.h" |
[email protected] | 8576935 | 2010-11-16 14:24:30 | [diff] [blame] | 17 | #include "base/version.h" |
[email protected] | 4512f3ac | 2009-11-04 03:39:22 | [diff] [blame] | 18 | #include "chrome/app/breakpad_win.h" |
| 19 | #include "chrome/app/client_util.h" |
[email protected] | 03d21b8 | 2010-12-07 19:37:22 | [diff] [blame] | 20 | #include "chrome/common/chrome_constants.h" |
[email protected] | 103607e | 2010-02-01 18:57:09 | [diff] [blame] | 21 | #include "chrome/common/chrome_switches.h" |
[email protected] | 74d1eec | 2009-11-04 22:18:57 | [diff] [blame] | 22 | #include "chrome/installer/util/browser_distribution.h" |
[email protected] | 2544a7a | 2011-03-14 18:25:19 | [diff] [blame] | 23 | #include "chrome/installer/util/channel_info.h" |
[email protected] | 4512f3ac | 2009-11-04 03:39:22 | [diff] [blame] | 24 | #include "chrome/installer/util/install_util.h" |
[email protected] | 2414e84 | 2008-11-07 01:27:57 | [diff] [blame] | 25 | #include "chrome/installer/util/google_update_constants.h" |
[email protected] | fd59f82 | 2011-05-12 18:07:18 | [diff] [blame^] | 26 | #include "chrome/installer/util/google_update_settings.h" |
[email protected] | 28c1969 | 2008-11-07 23:40:38 | [diff] [blame] | 27 | #include "chrome/installer/util/util_constants.h" |
[email protected] | 4dd5793 | 2011-03-17 06:06:12 | [diff] [blame] | 28 | #include "content/common/result_codes.h" |
[email protected] | 28c1969 | 2008-11-07 23:40:38 | [diff] [blame] | 29 | |
| 30 | namespace { |
[email protected] | 4512f3ac | 2009-11-04 03:39:22 | [diff] [blame] | 31 | // The entry point signature of chrome.dll. |
| 32 | typedef int (*DLL_MAIN)(HINSTANCE, sandbox::SandboxInterfaceInfo*, wchar_t*); |
[email protected] | 28c1969 | 2008-11-07 23:40:38 | [diff] [blame] | 33 | |
[email protected] | 3cdacd4 | 2010-04-30 18:55:53 | [diff] [blame] | 34 | typedef void (*RelaunchChromeBrowserWithNewCommandLineIfNeededFunc)(); |
| 35 | |
[email protected] | 4512f3ac | 2009-11-04 03:39:22 | [diff] [blame] | 36 | // Gets chrome version according to the load path. |exe_path| must be the |
| 37 | // backslash terminated directory of the current chrome.exe. |
| 38 | bool GetVersion(const wchar_t* exe_path, const wchar_t* key_path, |
| 39 | std::wstring* version) { |
[email protected] | 48d4387 | 2008-11-04 23:38:32 | [diff] [blame] | 40 | HKEY reg_root = InstallUtil::IsPerUserInstall(exe_path) ? HKEY_CURRENT_USER : |
[email protected] | 28c1969 | 2008-11-07 23:40:38 | [diff] [blame] | 41 | HKEY_LOCAL_MACHINE; |
[email protected] | 2544a7a | 2011-03-14 18:25:19 | [diff] [blame] | 42 | bool success = false; |
[email protected] | 28c1969 | 2008-11-07 23:40:38 | [diff] [blame] | 43 | |
[email protected] | 2544a7a | 2011-03-14 18:25:19 | [diff] [blame] | 44 | base::win::RegKey key(reg_root, key_path, KEY_QUERY_VALUE); |
| 45 | if (key.Valid()) { |
| 46 | // If 'new_chrome.exe' is present it means chrome was auto-updated while |
| 47 | // running. We need to consult the opv value so we can load the old dll. |
| 48 | // TODO(cpu) : This is solving the same problem as the environment variable |
| 49 | // so one of them will eventually be deprecated. |
| 50 | std::wstring new_chrome_exe(exe_path); |
| 51 | new_chrome_exe.append(installer::kChromeNewExe); |
| 52 | if (::PathFileExistsW(new_chrome_exe.c_str()) && |
| 53 | key.ReadValue(google_update::kRegOldVersionField, |
| 54 | version) == ERROR_SUCCESS) { |
| 55 | success = true; |
| 56 | } else { |
| 57 | success = (key.ReadValue(google_update::kRegVersionField, |
| 58 | version) == ERROR_SUCCESS); |
| 59 | } |
[email protected] | 2414e84 | 2008-11-07 01:27:57 | [diff] [blame] | 60 | } |
| 61 | |
[email protected] | 2544a7a | 2011-03-14 18:25:19 | [diff] [blame] | 62 | return success; |
[email protected] | c9349d08 | 2008-08-22 21:16:47 | [diff] [blame] | 63 | } |
| 64 | |
[email protected] | 4512f3ac | 2009-11-04 03:39:22 | [diff] [blame] | 65 | // Gets the path of the current exe with a trailing backslash. |
[email protected] | 60400404 | 2009-10-21 23:10:26 | [diff] [blame] | 66 | std::wstring GetExecutablePath() { |
[email protected] | 4512f3ac | 2009-11-04 03:39:22 | [diff] [blame] | 67 | wchar_t path[MAX_PATH]; |
| 68 | ::GetModuleFileNameW(NULL, path, MAX_PATH); |
| 69 | if (!::PathRemoveFileSpecW(path)) |
| 70 | return std::wstring(); |
| 71 | std::wstring exe_path(path); |
| 72 | return exe_path.append(L"\\"); |
[email protected] | c9349d08 | 2008-08-22 21:16:47 | [diff] [blame] | 73 | } |
| 74 | |
[email protected] | bae4e38 | 2010-08-22 04:44:05 | [diff] [blame] | 75 | // Not generic, we only handle strings up to 128 chars. |
| 76 | bool EnvQueryStr(const wchar_t* key_name, std::wstring* value) { |
| 77 | wchar_t out[128]; |
| 78 | DWORD count = sizeof(out)/sizeof(out[0]); |
| 79 | DWORD rv = ::GetEnvironmentVariableW(key_name, out, count); |
| 80 | if ((rv == 0) || (rv >= count)) |
| 81 | return false; |
| 82 | *value = out; |
| 83 | return true; |
| 84 | } |
| 85 | |
[email protected] | 4512f3ac | 2009-11-04 03:39:22 | [diff] [blame] | 86 | // Expects that |dir| has a trailing backslash. |dir| is modified so it |
| 87 | // contains the full path that was tried. Caller must check for the return |
[email protected] | 8576935 | 2010-11-16 14:24:30 | [diff] [blame] | 88 | // value not being null to determine if this path contains a valid dll. |
[email protected] | 4512f3ac | 2009-11-04 03:39:22 | [diff] [blame] | 89 | HMODULE LoadChromeWithDirectory(std::wstring* dir) { |
| 90 | ::SetCurrentDirectoryW(dir->c_str()); |
[email protected] | 103607e | 2010-02-01 18:57:09 | [diff] [blame] | 91 | const CommandLine& cmd_line = *CommandLine::ForCurrentProcess(); |
[email protected] | 7b1bf81 | 2010-06-21 21:15:53 | [diff] [blame] | 92 | #ifdef _WIN64 |
[email protected] | 103607e | 2010-02-01 18:57:09 | [diff] [blame] | 93 | if ((cmd_line.GetSwitchValueASCII(switches::kProcessType) == |
| 94 | switches::kNaClBrokerProcess) || |
| 95 | (cmd_line.GetSwitchValueASCII(switches::kProcessType) == |
| 96 | switches::kNaClLoaderProcess)) { |
| 97 | // Load the 64-bit DLL when running in a 64-bit process. |
[email protected] | 74ca044 | 2010-12-15 14:44:50 | [diff] [blame] | 98 | dir->append(installer::kChromeNaCl64Dll); |
[email protected] | 103607e | 2010-02-01 18:57:09 | [diff] [blame] | 99 | } else { |
| 100 | // Only NaCl broker and loader can be launched as Win64 processes. |
| 101 | NOTREACHED(); |
| 102 | return NULL; |
| 103 | } |
| 104 | #else |
[email protected] | 74ca044 | 2010-12-15 14:44:50 | [diff] [blame] | 105 | dir->append(installer::kChromeDll); |
[email protected] | 103607e | 2010-02-01 18:57:09 | [diff] [blame] | 106 | #endif |
[email protected] | 00b7341 | 2010-06-21 21:01:36 | [diff] [blame] | 107 | |
[email protected] | 58ac024 | 2010-07-09 18:31:15 | [diff] [blame] | 108 | #ifdef NDEBUG |
[email protected] | 00b7341 | 2010-06-21 21:01:36 | [diff] [blame] | 109 | // Experimental pre-reading optimization |
| 110 | // The idea is to pre read significant portion of chrome.dll in advance |
| 111 | // so that subsequent hard page faults are avoided. |
[email protected] | bdf411b | 2010-07-13 22:21:59 | [diff] [blame] | 112 | if (!cmd_line.HasSwitch(switches::kProcessType)) { |
[email protected] | 85286b5 | 2010-07-03 06:14:45 | [diff] [blame] | 113 | // The kernel brings in 8 pages for the code section at a time and 4 pages |
| 114 | // for other sections. We can skip over these pages to avoid a soft page |
| 115 | // fault which may not occur during code execution. However skipping 4K at |
| 116 | // a time still has better performance over 32K and 16K according to data. |
| 117 | // TODO(ananta) |
| 118 | // Investigate this and tune. |
| 119 | const size_t kStepSize = 4 * 1024; |
| 120 | |
| 121 | DWORD pre_read_size = 0; |
| 122 | DWORD pre_read_step_size = kStepSize; |
| 123 | DWORD pre_read = 1; |
| 124 | |
[email protected] | 2544a7a | 2011-03-14 18:25:19 | [diff] [blame] | 125 | base::win::RegKey key(HKEY_CURRENT_USER, L"Software\\Google\\ChromeFrame", |
| 126 | KEY_QUERY_VALUE); |
| 127 | if (key.Valid()) { |
| 128 | key.ReadValueDW(L"PreReadSize", &pre_read_size); |
| 129 | key.ReadValueDW(L"PreReadStepSize", &pre_read_step_size); |
| 130 | key.ReadValueDW(L"PreRead", &pre_read); |
| 131 | key.Close(); |
[email protected] | 00b7341 | 2010-06-21 21:01:36 | [diff] [blame] | 132 | } |
[email protected] | 85286b5 | 2010-07-03 06:14:45 | [diff] [blame] | 133 | if (pre_read) { |
[email protected] | 366ae24 | 2011-05-10 02:23:58 | [diff] [blame] | 134 | TRACE_EVENT_BEGIN_ETW("PreReadImage", 0, ""); |
[email protected] | 85286b5 | 2010-07-03 06:14:45 | [diff] [blame] | 135 | file_util::PreReadImage(dir->c_str(), pre_read_size, pre_read_step_size); |
[email protected] | 366ae24 | 2011-05-10 02:23:58 | [diff] [blame] | 136 | TRACE_EVENT_END_ETW("PreReadImage", 0, ""); |
[email protected] | 00b7341 | 2010-06-21 21:01:36 | [diff] [blame] | 137 | } |
| 138 | } |
[email protected] | 58ac024 | 2010-07-09 18:31:15 | [diff] [blame] | 139 | #endif // NDEBUG |
[email protected] | 00b7341 | 2010-06-21 21:01:36 | [diff] [blame] | 140 | |
[email protected] | 4512f3ac | 2009-11-04 03:39:22 | [diff] [blame] | 141 | return ::LoadLibraryExW(dir->c_str(), NULL, |
| 142 | LOAD_WITH_ALTERED_SEARCH_PATH); |
| 143 | } |
| 144 | |
[email protected] | 2544a7a | 2011-03-14 18:25:19 | [diff] [blame] | 145 | void RecordDidRun(const std::wstring& dll_path) { |
[email protected] | 2544a7a | 2011-03-14 18:25:19 | [diff] [blame] | 146 | bool system_level = !InstallUtil::IsPerUserInstall(dll_path.c_str()); |
[email protected] | fd59f82 | 2011-05-12 18:07:18 | [diff] [blame^] | 147 | GoogleUpdateSettings::UpdateDidRunState(true, system_level); |
[email protected] | 4512f3ac | 2009-11-04 03:39:22 | [diff] [blame] | 148 | } |
| 149 | |
[email protected] | 2544a7a | 2011-03-14 18:25:19 | [diff] [blame] | 150 | void ClearDidRun(const std::wstring& dll_path) { |
[email protected] | 2544a7a | 2011-03-14 18:25:19 | [diff] [blame] | 151 | bool system_level = !InstallUtil::IsPerUserInstall(dll_path.c_str()); |
[email protected] | fd59f82 | 2011-05-12 18:07:18 | [diff] [blame^] | 152 | GoogleUpdateSettings::UpdateDidRunState(false, system_level); |
[email protected] | 2544a7a | 2011-03-14 18:25:19 | [diff] [blame] | 153 | } |
[email protected] | fd59f82 | 2011-05-12 18:07:18 | [diff] [blame^] | 154 | |
[email protected] | 42d7510c | 2009-12-19 01:48:30 | [diff] [blame] | 155 | } |
[email protected] | 4512f3ac | 2009-11-04 03:39:22 | [diff] [blame] | 156 | //============================================================================= |
| 157 | |
| 158 | MainDllLoader::MainDllLoader() : dll_(NULL) { |
| 159 | } |
| 160 | |
| 161 | MainDllLoader::~MainDllLoader() { |
| 162 | #ifdef PURIFY |
| 163 | // We should never unload the dll. There is only risk and no gain from |
| 164 | // doing so. The singleton dtors have been already run by AtExitManager. |
| 165 | ::FreeLibrary(dll_); |
| 166 | #endif |
| 167 | } |
| 168 | |
[email protected] | 8576935 | 2010-11-16 14:24:30 | [diff] [blame] | 169 | // Loading chrome is an interesting affair. First we try loading from the |
| 170 | // current directory to support run-what-you-compile and other development |
| 171 | // scenarios. |
| 172 | // If that fails then we look at the --chrome-version command line flag followed |
| 173 | // by the 'CHROME_VERSION' env variable to determine if we should stick with an |
| 174 | // older dll version even if a new one is available to support upgrade-in-place |
| 175 | // scenarios. |
| 176 | // If that fails then finally we look at the registry which should point us |
| 177 | // to the latest version. This is the expected path for the first chrome.exe |
| 178 | // browser instance in an installed build. |
| 179 | HMODULE MainDllLoader::Load(std::wstring* out_version, std::wstring* out_file) { |
[email protected] | 4512f3ac | 2009-11-04 03:39:22 | [diff] [blame] | 180 | std::wstring dir(GetExecutablePath()); |
[email protected] | 8576935 | 2010-11-16 14:24:30 | [diff] [blame] | 181 | *out_file = dir; |
| 182 | HMODULE dll = LoadChromeWithDirectory(out_file); |
[email protected] | 4512f3ac | 2009-11-04 03:39:22 | [diff] [blame] | 183 | if (dll) |
| 184 | return dll; |
| 185 | |
[email protected] | 36ee032 | 2010-12-23 21:27:12 | [diff] [blame] | 186 | std::wstring version_string; |
[email protected] | 8576935 | 2010-11-16 14:24:30 | [diff] [blame] | 187 | scoped_ptr<Version> version; |
| 188 | const CommandLine& cmd_line = *CommandLine::ForCurrentProcess(); |
| 189 | if (cmd_line.HasSwitch(switches::kChromeVersion)) { |
[email protected] | 36ee032 | 2010-12-23 21:27:12 | [diff] [blame] | 190 | version_string = cmd_line.GetSwitchValueNative(switches::kChromeVersion); |
| 191 | version.reset(Version::GetVersionFromString(WideToASCII(version_string))); |
[email protected] | 8576935 | 2010-11-16 14:24:30 | [diff] [blame] | 192 | |
| 193 | if (!version.get()) { |
| 194 | // If a bogus command line flag was given, then abort. |
| 195 | LOG(ERROR) << "Invalid version string received on command line: " |
[email protected] | 36ee032 | 2010-12-23 21:27:12 | [diff] [blame] | 196 | << version_string; |
[email protected] | 4512f3ac | 2009-11-04 03:39:22 | [diff] [blame] | 197 | return NULL; |
[email protected] | 8576935 | 2010-11-16 14:24:30 | [diff] [blame] | 198 | } |
[email protected] | 4512f3ac | 2009-11-04 03:39:22 | [diff] [blame] | 199 | } |
| 200 | |
[email protected] | 8576935 | 2010-11-16 14:24:30 | [diff] [blame] | 201 | if (!version.get()) { |
[email protected] | 03d21b8 | 2010-12-07 19:37:22 | [diff] [blame] | 202 | if (EnvQueryStr(ASCIIToWide(chrome::kChromeVersionEnvVar).c_str(), |
[email protected] | 36ee032 | 2010-12-23 21:27:12 | [diff] [blame] | 203 | &version_string)) { |
| 204 | version.reset(Version::GetVersionFromString(WideToASCII(version_string))); |
[email protected] | 8576935 | 2010-11-16 14:24:30 | [diff] [blame] | 205 | } |
| 206 | } |
| 207 | |
| 208 | if (!version.get()) { |
| 209 | std::wstring reg_path(GetRegistryPath()); |
| 210 | // Look into the registry to find the latest version. We don't validate |
| 211 | // this by building a Version object to avoid harming normal case startup |
| 212 | // time. |
[email protected] | 36ee032 | 2010-12-23 21:27:12 | [diff] [blame] | 213 | version_string.clear(); |
| 214 | GetVersion(dir.c_str(), reg_path.c_str(), &version_string); |
[email protected] | 8576935 | 2010-11-16 14:24:30 | [diff] [blame] | 215 | } |
| 216 | |
[email protected] | 36ee032 | 2010-12-23 21:27:12 | [diff] [blame] | 217 | if (version.get() || !version_string.empty()) { |
[email protected] | 8576935 | 2010-11-16 14:24:30 | [diff] [blame] | 218 | *out_file = dir; |
[email protected] | 36ee032 | 2010-12-23 21:27:12 | [diff] [blame] | 219 | *out_version = version_string; |
[email protected] | 8576935 | 2010-11-16 14:24:30 | [diff] [blame] | 220 | out_file->append(*out_version).append(L"\\"); |
[email protected] | 3e092a57 | 2011-05-02 20:47:08 | [diff] [blame] | 221 | dll = LoadChromeWithDirectory(out_file); |
| 222 | if (!dll) { |
| 223 | LOG(ERROR) << "Failed to load Chrome DLL from " << out_file; |
| 224 | } |
| 225 | return dll; |
[email protected] | 8576935 | 2010-11-16 14:24:30 | [diff] [blame] | 226 | } else { |
[email protected] | 3e092a57 | 2011-05-02 20:47:08 | [diff] [blame] | 227 | LOG(ERROR) << "Could not get Chrome DLL version."; |
[email protected] | 8576935 | 2010-11-16 14:24:30 | [diff] [blame] | 228 | return NULL; |
| 229 | } |
[email protected] | 4512f3ac | 2009-11-04 03:39:22 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | // Launching is a matter of loading the right dll, setting the CHROME_VERSION |
| 233 | // environment variable and just calling the entry point. Derived classes can |
| 234 | // add custom code in the OnBeforeLaunch callback. |
| 235 | int MainDllLoader::Launch(HINSTANCE instance, |
| 236 | sandbox::SandboxInterfaceInfo* sbox_info) { |
| 237 | std::wstring version; |
| 238 | std::wstring file; |
| 239 | dll_ = Load(&version, &file); |
| 240 | if (!dll_) |
| 241 | return ResultCodes::MISSING_DATA; |
| 242 | |
[email protected] | ae0f077 | 2010-08-13 04:54:10 | [diff] [blame] | 243 | scoped_ptr<base::Environment> env(base::Environment::Create()); |
[email protected] | 03d21b8 | 2010-12-07 19:37:22 | [diff] [blame] | 244 | env->SetVar(chrome::kChromeVersionEnvVar, WideToUTF8(version)); |
[email protected] | 4512f3ac | 2009-11-04 03:39:22 | [diff] [blame] | 245 | |
| 246 | InitCrashReporterWithDllPath(file); |
[email protected] | 2544a7a | 2011-03-14 18:25:19 | [diff] [blame] | 247 | OnBeforeLaunch(file); |
[email protected] | 4512f3ac | 2009-11-04 03:39:22 | [diff] [blame] | 248 | |
| 249 | DLL_MAIN entry_point = |
| 250 | reinterpret_cast<DLL_MAIN>(::GetProcAddress(dll_, "ChromeMain")); |
| 251 | if (!entry_point) |
| 252 | return ResultCodes::BAD_PROCESS_TYPE; |
| 253 | |
[email protected] | 42d7510c | 2009-12-19 01:48:30 | [diff] [blame] | 254 | int rc = entry_point(instance, sbox_info, ::GetCommandLineW()); |
[email protected] | 2544a7a | 2011-03-14 18:25:19 | [diff] [blame] | 255 | return OnBeforeExit(rc, file); |
[email protected] | 4512f3ac | 2009-11-04 03:39:22 | [diff] [blame] | 256 | } |
| 257 | |
[email protected] | 3cdacd4 | 2010-04-30 18:55:53 | [diff] [blame] | 258 | void MainDllLoader::RelaunchChromeBrowserWithNewCommandLineIfNeeded() { |
| 259 | RelaunchChromeBrowserWithNewCommandLineIfNeededFunc relaunch_function = |
| 260 | reinterpret_cast<RelaunchChromeBrowserWithNewCommandLineIfNeededFunc>( |
| 261 | ::GetProcAddress(dll_, |
| 262 | "RelaunchChromeBrowserWithNewCommandLineIfNeeded")); |
| 263 | if (!relaunch_function) { |
| 264 | LOG(ERROR) << "Could not find exported function " |
| 265 | << "RelaunchChromeBrowserWithNewCommandLineIfNeeded"; |
| 266 | } else { |
| 267 | relaunch_function(); |
| 268 | } |
| 269 | } |
| 270 | |
[email protected] | 4512f3ac | 2009-11-04 03:39:22 | [diff] [blame] | 271 | //============================================================================= |
| 272 | |
| 273 | class ChromeDllLoader : public MainDllLoader { |
| 274 | public: |
| 275 | virtual std::wstring GetRegistryPath() { |
| 276 | std::wstring key(google_update::kRegPathClients); |
[email protected] | 5f2cee8 | 2009-11-05 04:59:48 | [diff] [blame] | 277 | BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 278 | key.append(L"\\").append(dist->GetAppGuid()); |
[email protected] | 4512f3ac | 2009-11-04 03:39:22 | [diff] [blame] | 279 | return key; |
| 280 | } |
| 281 | |
[email protected] | 2544a7a | 2011-03-14 18:25:19 | [diff] [blame] | 282 | virtual void OnBeforeLaunch(const std::wstring& dll_path) { |
| 283 | RecordDidRun(dll_path); |
[email protected] | 4512f3ac | 2009-11-04 03:39:22 | [diff] [blame] | 284 | } |
[email protected] | 42d7510c | 2009-12-19 01:48:30 | [diff] [blame] | 285 | |
[email protected] | 2544a7a | 2011-03-14 18:25:19 | [diff] [blame] | 286 | virtual int OnBeforeExit(int return_code, const std::wstring& dll_path) { |
[email protected] | 42d7510c | 2009-12-19 01:48:30 | [diff] [blame] | 287 | // NORMAL_EXIT_CANCEL is used for experiments when the user cancels |
| 288 | // so we need to reset the did_run signal so omaha does not count |
| 289 | // this run as active usage. |
| 290 | if (ResultCodes::NORMAL_EXIT_CANCEL == return_code) { |
[email protected] | 2544a7a | 2011-03-14 18:25:19 | [diff] [blame] | 291 | ClearDidRun(dll_path); |
[email protected] | 42d7510c | 2009-12-19 01:48:30 | [diff] [blame] | 292 | } |
| 293 | return return_code; |
| 294 | } |
[email protected] | 4512f3ac | 2009-11-04 03:39:22 | [diff] [blame] | 295 | }; |
| 296 | |
| 297 | //============================================================================= |
| 298 | |
| 299 | class ChromiumDllLoader : public MainDllLoader { |
| 300 | public: |
| 301 | virtual std::wstring GetRegistryPath() { |
[email protected] | 74d1eec | 2009-11-04 22:18:57 | [diff] [blame] | 302 | BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 303 | return dist->GetVersionKey(); |
[email protected] | 4512f3ac | 2009-11-04 03:39:22 | [diff] [blame] | 304 | } |
| 305 | }; |
| 306 | |
| 307 | MainDllLoader* MakeMainDllLoader() { |
| 308 | #if defined(GOOGLE_CHROME_BUILD) |
| 309 | return new ChromeDllLoader(); |
| 310 | #else |
| 311 | return new ChromiumDllLoader(); |
| 312 | #endif |
| 313 | } |