Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4269)

Unified Diff: chrome/browser/first_run/upgrade_win.cc

Issue 6840003: first-run: Refactor Upgrade class into a common upgrade_util API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: upgrade_utils -> upgrade_util Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/first_run/upgrade_util_win.cc ('k') | chrome/browser/process_singleton.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/first_run/upgrade_win.cc
diff --git a/chrome/browser/first_run/upgrade_win.cc b/chrome/browser/first_run/upgrade_win.cc
deleted file mode 100644
index 42f3b747d1ba0b87d05ea258c446c2eab0e7791c..0000000000000000000000000000000000000000
--- a/chrome/browser/first_run/upgrade_win.cc
+++ /dev/null
@@ -1,157 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/first_run/upgrade.h"
-
-#include <algorithm>
-#include <string>
-
-#include "base/base_paths.h"
-#include "base/command_line.h"
-#include "base/environment.h"
-#include "base/file_path.h"
-#include "base/file_util.h"
-#include "base/logging.h"
-#include "base/path_service.h"
-#include "base/process_util.h"
-#include "base/win/registry.h"
-#include "base/win/scoped_comptr.h"
-#include "chrome/browser/first_run/try_chrome_dialog_view.h"
-#include "chrome/browser/process_singleton.h"
-#include "chrome/common/chrome_constants.h"
-#include "chrome/installer/util/browser_distribution.h"
-#include "chrome/installer/util/google_update_constants.h"
-#include "chrome/installer/util/install_util.h"
-#include "chrome/installer/util/shell_util.h"
-#include "chrome/installer/util/util_constants.h"
-#include "google_update_idl.h"
-
-namespace {
-
-bool GetNewerChromeFile(FilePath* path) {
- if (!PathService::Get(base::DIR_EXE, path))
- return false;
- *path = path->Append(installer::kChromeNewExe);
- return true;
-}
-
-bool InvokeGoogleUpdateForRename() {
- base::win::ScopedComPtr<IProcessLauncher> ipl;
- if (!FAILED(ipl.CreateInstance(__uuidof(ProcessLauncherClass)))) {
- ULONG_PTR phandle = NULL;
- DWORD id = GetCurrentProcessId();
- BrowserDistribution* dist = BrowserDistribution::GetDistribution();
- if (!FAILED(ipl->LaunchCmdElevated(dist->GetAppGuid().c_str(),
- google_update::kRegRenameCmdField,
- id,
- &phandle))) {
- HANDLE handle = HANDLE(phandle);
- WaitForSingleObject(handle, INFINITE);
- DWORD exit_code;
- ::GetExitCodeProcess(handle, &exit_code);
- ::CloseHandle(handle);
- if (exit_code == installer::RENAME_SUCCESSFUL)
- return true;
- }
- }
- return false;
-}
-
-} // namespace
-
-// static
-CommandLine* Upgrade::new_command_line_ = NULL;
-
-// static
-bool Upgrade::IsBrowserAlreadyRunning() {
- static HANDLE handle = NULL;
- FilePath exe_path;
- PathService::Get(base::FILE_EXE, &exe_path);
- std::wstring exe = exe_path.value();
- std::replace(exe.begin(), exe.end(), '\\', '!');
- std::transform(exe.begin(), exe.end(), exe.begin(), tolower);
- exe = L"Global\\" + exe;
- if (handle != NULL)
- CloseHandle(handle);
- handle = CreateEvent(NULL, TRUE, TRUE, exe.c_str());
- int error = GetLastError();
- return (error == ERROR_ALREADY_EXISTS || error == ERROR_ACCESS_DENIED);
-}
-
-// static
-bool Upgrade::SwapNewChromeExeIfPresent() {
- FilePath new_chrome_exe;
- if (!GetNewerChromeFile(&new_chrome_exe))
- return false;
- if (!file_util::PathExists(new_chrome_exe))
- return false;
- FilePath cur_chrome_exe;
- if (!PathService::Get(base::FILE_EXE, &cur_chrome_exe))
- return false;
-
- // First try to rename exe by launching rename command ourselves.
- bool user_install =
- InstallUtil::IsPerUserInstall(cur_chrome_exe.value().c_str());
- HKEY reg_root = user_install ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE;
- BrowserDistribution *dist = BrowserDistribution::GetDistribution();
- base::win::RegKey key;
- std::wstring rename_cmd;
- if ((key.Open(reg_root, dist->GetVersionKey().c_str(),
- KEY_READ) == ERROR_SUCCESS) &&
- (key.ReadValue(google_update::kRegRenameCmdField,
- &rename_cmd) == ERROR_SUCCESS)) {
- base::ProcessHandle handle;
- if (base::LaunchApp(rename_cmd, true, true, &handle)) {
- DWORD exit_code;
- ::GetExitCodeProcess(handle, &exit_code);
- ::CloseHandle(handle);
- if (exit_code == installer::RENAME_SUCCESSFUL)
- return true;
- }
- }
-
- // Rename didn't work so try to rename by calling Google Update
- return InvokeGoogleUpdateForRename();
-}
-
-// static
-bool Upgrade::DoUpgradeTasks(const CommandLine& command_line) {
- if (!Upgrade::SwapNewChromeExeIfPresent())
- return false;
- // At this point the chrome.exe has been swapped with the new one.
- if (!Upgrade::RelaunchChromeBrowser(command_line)) {
- // The re-launch fails. Feel free to panic now.
- NOTREACHED();
- }
- return true;
-}
-
-// static
-Upgrade::TryResult Upgrade::ShowTryChromeDialog(
- size_t version,
- ProcessSingleton* process_singleton) {
- if (version > 10000) {
- // This is a test value. We want to make sure we exercise
- // returning this early. See EarlyReturnTest test harness.
- return Upgrade::NOT_NOW;
- }
- TryChromeDialogView dialog(version);
- return dialog.ShowModal(process_singleton);
-}
-
-// static
-bool Upgrade::RelaunchChromeBrowser(const CommandLine& command_line) {
- scoped_ptr<base::Environment> env(base::Environment::Create());
- env->UnSetVar(chrome::kChromeVersionEnvVar);
- return base::LaunchApp(
- command_line.command_line_string(), false, false, NULL);
-}
-
-// static
-bool Upgrade::IsUpdatePendingRestart() {
- FilePath new_chrome_exe;
- if (!GetNewerChromeFile(&new_chrome_exe))
- return false;
- return file_util::PathExists(new_chrome_exe);
-}
« no previous file with comments | « chrome/browser/first_run/upgrade_util_win.cc ('k') | chrome/browser/process_singleton.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698