Chromium Code Reviews| 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 <atlbase.h> | |
| 6 #include <atlcom.h> | |
| 5 #include <windows.h> | 7 #include <windows.h> |
| 6 #include <shlobj.h> | 8 #include <shlobj.h> |
| 7 | 9 |
| 8 #include <sstream> | 10 #include <sstream> |
| 9 | 11 |
| 10 #include "chrome/browser/first_run.h" | 12 #include "chrome/browser/first_run.h" |
| 11 | 13 |
| 12 #include "base/file_util.h" | 14 #include "base/file_util.h" |
| 13 #include "base/logging.h" | 15 #include "base/logging.h" |
| 14 #include "base/object_watcher.h" | 16 #include "base/object_watcher.h" |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 31 #include "chrome/common/pref_service.h" | 33 #include "chrome/common/pref_service.h" |
| 32 #include "chrome/installer/util/browser_distribution.h" | 34 #include "chrome/installer/util/browser_distribution.h" |
| 33 #include "chrome/installer/util/google_update_constants.h" | 35 #include "chrome/installer/util/google_update_constants.h" |
| 34 #include "chrome/installer/util/install_util.h" | 36 #include "chrome/installer/util/install_util.h" |
| 35 #include "chrome/installer/util/master_preferences.h" | 37 #include "chrome/installer/util/master_preferences.h" |
| 36 #include "chrome/installer/util/shell_util.h" | 38 #include "chrome/installer/util/shell_util.h" |
| 37 #include "chrome/installer/util/util_constants.h" | 39 #include "chrome/installer/util/util_constants.h" |
| 38 #include "chrome/views/accelerator_handler.h" | 40 #include "chrome/views/accelerator_handler.h" |
| 39 #include "chrome/views/window.h" | 41 #include "chrome/views/window.h" |
| 40 | 42 |
| 43 #include "google_update_idl.h" | |
| 44 | |
| 41 namespace { | 45 namespace { |
| 42 | 46 |
| 43 // The kSentinelFile file absence will tell us it is a first run. | 47 // The kSentinelFile file absence will tell us it is a first run. |
| 44 const wchar_t kSentinelFile[] = L"First Run"; | 48 const wchar_t kSentinelFile[] = L"First Run"; |
| 45 | 49 |
| 46 // Gives the full path to the sentinel file. The file might not exist. | 50 // Gives the full path to the sentinel file. The file might not exist. |
| 47 bool GetFirstRunSentinelFilePath(std::wstring* path) { | 51 bool GetFirstRunSentinelFilePath(std::wstring* path) { |
| 48 std::wstring first_run_sentinel; | 52 std::wstring first_run_sentinel; |
| 49 if (!PathService::Get(base::DIR_EXE, &first_run_sentinel)) | 53 if (!PathService::Get(base::DIR_EXE, &first_run_sentinel)) |
| 50 return false; | 54 return false; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 73 ProfileManager::GetDefaultProfileDir(user_data_dir); | 77 ProfileManager::GetDefaultProfileDir(user_data_dir); |
| 74 if (create_profile_dir) { | 78 if (create_profile_dir) { |
| 75 if (!file_util::PathExists(default_pref_dir)) { | 79 if (!file_util::PathExists(default_pref_dir)) { |
| 76 if (!file_util::CreateDirectory(default_pref_dir)) | 80 if (!file_util::CreateDirectory(default_pref_dir)) |
| 77 return std::wstring(); | 81 return std::wstring(); |
| 78 } | 82 } |
| 79 } | 83 } |
| 80 return ProfileManager::GetDefaultProfilePath(default_pref_dir); | 84 return ProfileManager::GetDefaultProfilePath(default_pref_dir); |
| 81 } | 85 } |
| 82 | 86 |
| 87 bool InvokeGoogleUpdateForRename() { | |
| 88 CComPtr<IProcessLauncher> ipl; | |
| 89 if (!FAILED(ipl.CoCreateInstance(__uuidof(ProcessLauncherClass)))) { | |
| 90 ULONG_PTR phandle = NULL; | |
| 91 DWORD id = GetCurrentProcessId(); | |
| 92 if (!FAILED(ipl->LaunchCmdElevated(google_update::kChromeGuid, | |
| 93 google_update::kRegRenameCmdField, | |
| 94 id, &phandle))) { | |
| 95 HANDLE handle = HANDLE(phandle); | |
| 96 ::GetExitCodeProcess(handle, exit_code); | |
| 97 ::CloseHandle(handle); | |
| 98 if (exit_code == installer_util::RENAME_SUCCESSFUL) | |
| 99 return true; | |
| 100 } | |
| 101 } | |
| 102 return false; | |
|
cpu_(ooo_6.6-7.5)
2008/11/20 02:43:38
So this rename does also the opv key work?
| |
| 103 } | |
| 104 | |
| 83 } // namespace | 105 } // namespace |
| 84 | 106 |
| 85 bool FirstRun::IsChromeFirstRun() { | 107 bool FirstRun::IsChromeFirstRun() { |
| 86 std::wstring first_run_sentinel; | 108 std::wstring first_run_sentinel; |
| 87 if (!GetFirstRunSentinelFilePath(&first_run_sentinel)) | 109 if (!GetFirstRunSentinelFilePath(&first_run_sentinel)) |
| 88 return false; | 110 return false; |
| 89 if (file_util::PathExists(first_run_sentinel)) | 111 if (file_util::PathExists(first_run_sentinel)) |
| 90 return false; | 112 return false; |
| 91 return true; | 113 return true; |
| 92 } | 114 } |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 213 return base::LaunchApp(command_line.command_line_string(), | 235 return base::LaunchApp(command_line.command_line_string(), |
| 214 false, false, NULL); | 236 false, false, NULL); |
| 215 } | 237 } |
| 216 | 238 |
| 217 bool Upgrade::SwapNewChromeExeIfPresent() { | 239 bool Upgrade::SwapNewChromeExeIfPresent() { |
| 218 std::wstring new_chrome_exe; | 240 std::wstring new_chrome_exe; |
| 219 if (!GetNewerChromeFile(&new_chrome_exe)) | 241 if (!GetNewerChromeFile(&new_chrome_exe)) |
| 220 return false; | 242 return false; |
| 221 if (!file_util::PathExists(new_chrome_exe)) | 243 if (!file_util::PathExists(new_chrome_exe)) |
| 222 return false; | 244 return false; |
| 223 std::wstring old_chrome_exe; | 245 std::wstring curr_chrome_exe; |
| 224 if (!PathService::Get(base::FILE_EXE, &old_chrome_exe)) | 246 if (!PathService::Get(base::FILE_EXE, &curr_chrome_exe)) |
| 225 return false; | 247 return false; |
| 248 | |
| 249 // First try to rename exe by launching rename command ourselves. | |
| 250 bool user_install = InstallUtil::IsPerUserInstall(curr_chrome_exe.c_str()); | |
| 251 HKEY reg_root = user_install ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; | |
| 252 BrowserDistribution *dist = BrowserDistribution::GetDistribution(); | |
| 226 RegKey key; | 253 RegKey key; |
| 227 HKEY reg_root = InstallUtil::IsPerUserInstall(old_chrome_exe.c_str()) ? | |
| 228 HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; | |
| 229 BrowserDistribution *dist = BrowserDistribution::GetDistribution(); | |
| 230 std::wstring rename_cmd; | 254 std::wstring rename_cmd; |
| 231 if (key.Open(reg_root, dist->GetVersionKey().c_str(), KEY_READ) && | 255 if (key.Open(reg_root, dist->GetVersionKey().c_str(), KEY_READ) && |
| 232 key.ReadValue(google_update::kRegRenameCmdField, &rename_cmd)) { | 256 key.ReadValue(google_update::kRegRenameCmdField, &rename_cmd)) { |
| 233 base::ProcessHandle handle; | 257 base::ProcessHandle handle; |
| 234 if (base::LaunchApp(rename_cmd, true, true, &handle)) { | 258 if (base::LaunchApp(rename_cmd, true, true, &handle)) { |
| 235 DWORD exit_code; | 259 DWORD exit_code; |
| 236 ::GetExitCodeProcess(handle, &exit_code); | 260 ::GetExitCodeProcess(handle, &exit_code); |
| 237 ::CloseHandle(handle); | 261 ::CloseHandle(handle); |
| 238 if (exit_code == installer_util::RENAME_SUCCESSFUL) | 262 if (exit_code == installer_util::RENAME_SUCCESSFUL) |
| 239 return true; | 263 return true; |
| 240 } | 264 } |
| 241 } | 265 } |
| 266 | |
| 267 // Rename didn't work so try to rename by calling Google Update | |
| 268 if (InvokeGoogleUpdateForRename(&exit_code)) | |
| 269 return true; | |
| 270 | |
| 271 // Rename still didn't work so just try to rename exe ourselves (for | |
| 272 // backward compatibility, can be deleted once the new process works). | |
| 242 std::wstring backup_exe; | 273 std::wstring backup_exe; |
| 243 if (!GetBackupChromeFile(&backup_exe)) | 274 if (!GetBackupChromeFile(&backup_exe)) |
| 244 return false; | 275 return false; |
| 245 if (::ReplaceFileW(old_chrome_exe.c_str(), new_chrome_exe.c_str(), | 276 if (::ReplaceFileW(curr_chrome_exe.c_str(), new_chrome_exe.c_str(), |
| 246 backup_exe.c_str(), REPLACEFILE_IGNORE_MERGE_ERRORS, | 277 backup_exe.c_str(), REPLACEFILE_IGNORE_MERGE_ERRORS, |
| 247 NULL, NULL)) { | 278 NULL, NULL)) { |
| 248 return true; | 279 return true; |
| 249 } | 280 } |
| 250 return false; | 281 return false; |
| 251 } | 282 } |
| 252 | 283 |
| 253 void OpenFirstRunDialog(Profile* profile) { | 284 void OpenFirstRunDialog(Profile* profile) { |
| 254 views::Window::CreateChromeWindow(NULL, gfx::Rect(), | 285 views::Window::CreateChromeWindow(NULL, gfx::Rect(), |
| 255 new FirstRunView(profile))->Show(); | 286 new FirstRunView(profile))->Show(); |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 493 bool FirstRun::SetShowWelcomePagePref() { | 524 bool FirstRun::SetShowWelcomePagePref() { |
| 494 PrefService* local_state = g_browser_process->local_state(); | 525 PrefService* local_state = g_browser_process->local_state(); |
| 495 if (!local_state) | 526 if (!local_state) |
| 496 return false; | 527 return false; |
| 497 if (!local_state->IsPrefRegistered(prefs::kShouldShowWelcomePage)) { | 528 if (!local_state->IsPrefRegistered(prefs::kShouldShowWelcomePage)) { |
| 498 local_state->RegisterBooleanPref(prefs::kShouldShowWelcomePage, false); | 529 local_state->RegisterBooleanPref(prefs::kShouldShowWelcomePage, false); |
| 499 local_state->SetBoolean(prefs::kShouldShowWelcomePage, true); | 530 local_state->SetBoolean(prefs::kShouldShowWelcomePage, true); |
| 500 } | 531 } |
| 501 return true; | 532 return true; |
| 502 } | 533 } |
| OLD | NEW |