diff options
author | kuchhal@chromium.org <kuchhal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-15 21:37:46 +0000 |
---|---|---|
committer | kuchhal@chromium.org <kuchhal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-15 21:37:46 +0000 |
commit | 68c921f8b5d6454307645d4017a3cbf2646904bc (patch) | |
tree | fdd0d0138a4ce706e052de4bab66fa3c4b28b8d4 /chrome/browser | |
parent | 9c6c3065723227dee6bca91df24bb6863ac123f9 (diff) | |
download | chromium_src-68c921f8b5d6454307645d4017a3cbf2646904bc.zip chromium_src-68c921f8b5d6454307645d4017a3cbf2646904bc.tar.gz chromium_src-68c921f8b5d6454307645d4017a3cbf2646904bc.tar.bz2 |
Add a check in Chrome to not run user level mode if machine level Chrome
is already installed.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@3423 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/browser_main.cc | 46 | ||||
-rw-r--r-- | chrome/browser/google_update.cc | 18 |
2 files changed, 57 insertions, 7 deletions
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc index 758d261..049a402 100644 --- a/chrome/browser/browser_main.cc +++ b/chrome/browser/browser_main.cc @@ -49,6 +49,9 @@ #include "chrome/common/pref_service.h" #include "chrome/common/win_util.h" #include "chrome/installer/util/google_update_settings.h" +#include "chrome/installer/util/helper.h" +#include "chrome/installer/util/install_util.h" +#include "chrome/installer/util/version.h" #include "chrome/views/accelerator_handler.h" #include "net/base/net_module.h" #include "net/base/net_resources.h" @@ -221,6 +224,39 @@ bool CreateUniqueChromeEvent() { return already_running; } +// Check if there is any machine level Chrome installed on the current +// machine. If yes and the current Chrome process is user level, we do not +// allow the user level Chrome to run. So we notify the user and uninstall +// user level Chrome. +bool CheckMachineLevelInstall() { + scoped_ptr<installer::Version> version(InstallUtil::GetChromeVersion(true)); + if (version.get()) { + std::wstring exe; + PathService::Get(base::DIR_EXE, &exe); + std::transform(exe.begin(), exe.end(), exe.begin(), tolower); + std::wstring user_exe_path = installer::GetChromeInstallPath(false); + std::transform(user_exe_path.begin(), user_exe_path.end(), + user_exe_path.begin(), tolower); + if (exe == user_exe_path) { + const std::wstring text = + l10n_util::GetString(IDS_MACHINE_LEVEL_INSTALL_CONFLICT); + const std::wstring caption = l10n_util::GetString(IDS_PRODUCT_NAME); + const UINT flags = MB_OK | MB_ICONERROR | MB_TOPMOST; + win_util::MessageBox(NULL, text, caption, flags); + std::wstring uninstall_cmd = InstallUtil::GetChromeUninstallCmd(false); + if (!uninstall_cmd.empty()) { + uninstall_cmd.append(L" --"); + uninstall_cmd.append(installer_util::switches::kForceUninstall); + uninstall_cmd.append(L" --"); + uninstall_cmd.append(installer_util::switches::kDoNotRemoveSharedItems); + process_util::LaunchApp(uninstall_cmd, false, false, NULL); + } + return true; + } + } + return false; +} + // We record in UMA the conditions that can prevent breakpad from generating // and sending crash reports. Namely that the crash reporting registration // failed and that the process is being debugged. @@ -400,6 +436,16 @@ int BrowserMain(CommandLine &parsed_command_line, int show_command, return ResultCodes::NORMAL_EXIT; } + // Check if there is any machine level Chrome installed on the current + // machine. If yes and the current Chrome process is user level, we do not + // allow the user level Chrome to run. So we notify the user and uninstall + // user level Chrome. + // Note this check should only happen here, after all the checks above + // (uninstall, resource bundle initialization, other chrome browser + // processes etc). + if (CheckMachineLevelInstall()) + return ResultCodes::MACHINE_LEVEL_INSTALL_EXISTS; + message_window.Create(); // Show the First Run UI if this is the first time Chrome has been run on diff --git a/chrome/browser/google_update.cc b/chrome/browser/google_update.cc index da56359..71e22e5 100644 --- a/chrome/browser/google_update.cc +++ b/chrome/browser/google_update.cc @@ -12,8 +12,8 @@ #include "base/task.h" #include "base/thread.h" #include "chrome/browser/browser_process.h" -#include "chrome/installer/util/helper.h" #include "chrome/installer/util/google_update_constants.h" +#include "chrome/installer/util/helper.h" #include "google_update_idl_i.c" namespace { @@ -23,16 +23,20 @@ namespace { bool CanUpdateCurrentChrome() { std::wstring current_exe_path; if (PathService::Get(base::DIR_EXE, ¤t_exe_path)) { - std::wstring standard_exe_path = installer::GetChromeInstallPath(false); + std::wstring user_exe_path = installer::GetChromeInstallPath(false); + std::wstring machine_exe_path = installer::GetChromeInstallPath(true); std::transform(current_exe_path.begin(), current_exe_path.end(), current_exe_path.begin(), tolower); - std::transform(standard_exe_path.begin(), standard_exe_path.end(), - standard_exe_path.begin(), tolower); - if (current_exe_path != standard_exe_path) { + std::transform(user_exe_path.begin(), user_exe_path.end(), + user_exe_path.begin(), tolower); + std::transform(machine_exe_path.begin(), machine_exe_path.end(), + machine_exe_path.begin(), tolower); + if (current_exe_path != user_exe_path && + current_exe_path != machine_exe_path ) { LOG(ERROR) << L"Google Update cannot update Chrome installed in a " << L"non-standard location: " << current_exe_path.c_str() - << L". The standard location is: " << standard_exe_path.c_str() - << L"."; + << L". The standard location is: " << user_exe_path.c_str() + << L" or " << machine_exe_path.c_str() << L"."; return false; } } |