Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/installer/launcher_support/chrome_launcher_support.h" | 5 #include "chrome/installer/launcher_support/chrome_launcher_support.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <tchar.h> | 8 #include <tchar.h> |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/logging.h" | |
| 11 #ifndef OFFICIAL_BUILD | 12 #ifndef OFFICIAL_BUILD |
| 12 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 13 #endif | 14 #endif |
| 14 #include "base/string16.h" | 15 #include "base/string16.h" |
| 15 #include "base/win/registry.h" | 16 #include "base/win/registry.h" |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 19 // TODO(erikwright): These constants are duplicated all over the place. | 20 // TODO(erikwright): These constants are duplicated all over the place. |
| 20 // Consolidate them somehow. | 21 // Consolidate them somehow. |
| 21 const wchar_t kChromeRegClientStateKey[] = | 22 const wchar_t kChromeBinariesRegClientStateKey[] = |
| 22 L"Software\\Google\\Update\\ClientState\\" | 23 L"Software\\Google\\Update\\ClientState\\" |
| 23 L"{8A69D345-D564-463c-AFF1-A69D9E530F96}"; | 24 L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}"; |
| 24 | 25 |
| 25 const wchar_t kUninstallStringField[] = L"UninstallString"; | 26 const wchar_t kUninstallStringField[] = L"UninstallString"; |
| 26 | 27 |
| 28 // Copied from util_constants.cc | |
| 27 const wchar_t kChromeExe[] = L"chrome.exe"; | 29 const wchar_t kChromeExe[] = L"chrome.exe"; |
| 28 | 30 |
| 29 #ifndef OFFICIAL_BUILD | 31 #ifndef OFFICIAL_BUILD |
| 30 FilePath GetDevelopmentChrome() { | 32 FilePath GetDevelopmentChrome() { |
| 31 FilePath current_directory; | 33 FilePath current_directory; |
| 32 if (PathService::Get(base::DIR_EXE, ¤t_directory)) { | 34 if (PathService::Get(base::DIR_EXE, ¤t_directory)) { |
| 33 FilePath chrome_exe_path(current_directory.Append(kChromeExe)); | 35 FilePath chrome_exe_path(current_directory.Append(kChromeExe)); |
| 34 if (file_util::PathExists(chrome_exe_path)) | 36 if (file_util::PathExists(chrome_exe_path)) |
| 35 return chrome_exe_path; | 37 return chrome_exe_path; |
| 36 } | 38 } |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 49 chrome_path = GetDevelopmentChrome(); | 51 chrome_path = GetDevelopmentChrome(); |
| 50 #endif | 52 #endif |
| 51 if (chrome_path.empty()) | 53 if (chrome_path.empty()) |
| 52 chrome_path = GetChromePathForInstallationLevel(SYSTEM_LEVEL_INSTALLATION); | 54 chrome_path = GetChromePathForInstallationLevel(SYSTEM_LEVEL_INSTALLATION); |
| 53 if (chrome_path.empty()) | 55 if (chrome_path.empty()) |
| 54 chrome_path = GetChromePathForInstallationLevel(USER_LEVEL_INSTALLATION); | 56 chrome_path = GetChromePathForInstallationLevel(USER_LEVEL_INSTALLATION); |
| 55 | 57 |
| 56 return chrome_path; | 58 return chrome_path; |
| 57 } | 59 } |
| 58 | 60 |
| 59 FilePath GetChromePathForInstallationLevel(InstallationLevel level) { | 61 FilePath GetSetupExeForInstallationLevel(InstallationLevel level) { |
| 60 using base::win::RegKey; | 62 using base::win::RegKey; |
| 61 HKEY root_key = (level == USER_LEVEL_INSTALLATION ? | 63 HKEY root_key = (level == USER_LEVEL_INSTALLATION ? |
| 62 HKEY_CURRENT_USER : | 64 HKEY_CURRENT_USER : |
| 63 HKEY_LOCAL_MACHINE); | 65 HKEY_LOCAL_MACHINE); |
| 64 RegKey reg_key(root_key, kChromeRegClientStateKey, KEY_QUERY_VALUE); | 66 RegKey reg_key; |
| 65 | 67 LOG(INFO) << "Seeking reg: " << kChromeBinariesRegClientStateKey; |
|
erikwright (departed)
2012/09/13 01:13:44
remove log statement.
huangs
2012/09/13 04:40:47
Done.
| |
| 66 FilePath chrome_exe_path; | 68 if (reg_key.Open(root_key, kChromeBinariesRegClientStateKey, |
| 67 | 69 KEY_QUERY_VALUE) == ERROR_SUCCESS) { |
| 68 if (reg_key.Valid()) { | 70 // Grab the UninstallString (actually, uninstall progra)m from |
|
erikwright (departed)
2012/09/13 01:13:44
This comment is confusing, and actually no comment
huangs
2012/09/13 04:40:47
Done.
| |
| 69 // Now grab the uninstall string from the appropriate ClientState key | 71 // Chrome Binaries, and use that as the base for a path to setup.exe. |
| 70 // and use that as the base for a path to chrome.exe. | |
| 71 string16 uninstall; | 72 string16 uninstall; |
| 72 if (reg_key.ReadValue(kUninstallStringField, &uninstall) == ERROR_SUCCESS) { | 73 if (reg_key.ReadValue(kUninstallStringField, &uninstall) == ERROR_SUCCESS) { |
| 73 // The uninstall path contains the path to setup.exe which is two levels | 74 // Trim the command line parameters. |
| 74 // down from chrome.exe. Move up two levels (plus one to drop the file | 75 FilePath setup_exe_path(uninstall); |
| 75 // name) and look for chrome.exe from there. | 76 LOG(INFO) << "Seeking file: " << setup_exe_path.value(); |
|
erikwright (departed)
2012/09/13 01:13:44
Remove log statement.
huangs
2012/09/13 04:40:47
Done.
| |
| 76 FilePath uninstall_path(uninstall); | 77 if (file_util::PathExists(setup_exe_path)) |
| 77 chrome_exe_path = | 78 return setup_exe_path; |
| 78 uninstall_path.DirName().DirName().DirName().Append(kChromeExe); | |
| 79 if (!file_util::PathExists(chrome_exe_path)) { | |
| 80 // By way of mild future proofing, look up one to see if there's a | |
| 81 // chrome.exe in the version directory | |
| 82 chrome_exe_path = | |
| 83 uninstall_path.DirName().DirName().Append(kChromeExe); | |
| 84 } | |
| 85 } | 79 } |
| 86 } | 80 } |
| 87 | |
| 88 if (file_util::PathExists(chrome_exe_path)) | |
| 89 return chrome_exe_path; | |
| 90 | |
| 91 return FilePath(); | 81 return FilePath(); |
| 92 } | 82 } |
| 93 | 83 |
| 84 FilePath GetChromePathForInstallationLevel(InstallationLevel level) { | |
| 85 FilePath setup_exe_path(GetSetupExeForInstallationLevel(level)); | |
| 86 if (!setup_exe_path.empty()) { | |
| 87 FilePath chrome_exe_path; | |
| 88 // The uninstall path contains the path to setup.exe which is two levels | |
| 89 // down from chrome.exe. Move up two levels (plus one to drop the file | |
| 90 // name) and look for chrome.exe from there. | |
| 91 chrome_exe_path = | |
| 92 setup_exe_path.DirName().DirName().DirName().Append(kChromeExe); | |
| 93 if (!file_util::PathExists(chrome_exe_path)) { | |
| 94 // By way of mild future proofing, look up one to see if there's a | |
| 95 // chrome.exe in the version directory | |
| 96 chrome_exe_path = | |
| 97 chrome_exe_path.DirName().DirName().Append(kChromeExe); | |
| 98 } | |
| 99 if (file_util::PathExists(chrome_exe_path)) | |
| 100 return chrome_exe_path; | |
| 101 } | |
| 102 return FilePath(); | |
| 103 } | |
| 104 | |
| 94 } // namespace chrome_launcher_support | 105 } // namespace chrome_launcher_support |
| OLD | NEW |