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

Side by Side Diff: chrome/installer/launcher_support/chrome_launcher_support.cc

Issue 10905238: If Chrome Binaries version > App Host version, then update App Host. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 3 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 unified diff | Download patch
OLDNEW
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/command_line.h"
9 #include "base/file_path.h" 10 #include "base/file_path.h"
10 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/logging.h"
13 #include "base/process_util.h"
11 #ifndef OFFICIAL_BUILD 14 #ifndef OFFICIAL_BUILD
12 #include "base/path_service.h" 15 #include "base/path_service.h"
13 #endif 16 #endif
14 #include "base/string16.h" 17 #include "base/string16.h"
15 #include "base/win/registry.h" 18 #include "base/win/registry.h"
16 19
17 namespace { 20 namespace {
18 21
19 // TODO(erikwright): These constants are duplicated all over the place. 22 // TODO(erikwright): These constants are duplicated all over the place.
20 // Consolidate them somehow. 23 // Consolidate them somehow.
21 const wchar_t kChromeRegClientStateKey[] = 24 const wchar_t kChromeBinariesRegClientStateKey[] =
22 L"Software\\Google\\Update\\ClientState\\" 25 L"Software\\Google\\Update\\ClientState\\"
23 L"{8A69D345-D564-463c-AFF1-A69D9E530F96}"; 26 L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}";
27 const wchar_t kChromeBinariesRegClientsKey[] =
28 L"Software\\Google\\Update\\Clients\\"
29 L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}";
30 const wchar_t kChromeAppHostRegClientsKey[] =
31 L"Software\\Google\\Update\\Clients\\"
32 L"{FDA71E6F-AC4C-4a00-8B70-9958A68906BF}";
24 33
25 const wchar_t kUninstallStringField[] = L"UninstallString"; 34 const wchar_t kUninstallStringField[] = L"UninstallString";
26 35
36 // Copied from util_constants.cc
37 const wchar_t kSetupExe[] = L"setup.exe";
27 const wchar_t kChromeExe[] = L"chrome.exe"; 38 const wchar_t kChromeExe[] = L"chrome.exe";
39 namespace local_switches {
erikwright (departed) 2012/09/12 15:53:50 It's in an anonymous namespace already. I don't th
huangs 2012/09/12 19:24:27 Done.
40 const char kMultiInstall[] = "multi-install";
41 const char kChromeAppHost[] = "app-host";
42 const char kVerboseLogging[] = "verbose-logging";
43 }
44
45 // Copied from google_update_constants.cc
46 const wchar_t kRegVersionField[] = L"pv";
28 47
29 #ifndef OFFICIAL_BUILD 48 #ifndef OFFICIAL_BUILD
30 FilePath GetDevelopmentChrome() { 49 FilePath GetDevelopmentChrome() {
31 FilePath current_directory; 50 FilePath current_directory;
32 if (PathService::Get(base::DIR_EXE, &current_directory)) { 51 if (PathService::Get(base::DIR_EXE, &current_directory)) {
33 FilePath chrome_exe_path(current_directory.Append(kChromeExe)); 52 FilePath chrome_exe_path(current_directory.Append(kChromeExe));
34 if (file_util::PathExists(chrome_exe_path)) 53 if (file_util::PathExists(chrome_exe_path))
35 return chrome_exe_path; 54 return chrome_exe_path;
36 } 55 }
37 return FilePath(); 56 return FilePath();
(...skipping 11 matching lines...) Expand all
49 chrome_path = GetDevelopmentChrome(); 68 chrome_path = GetDevelopmentChrome();
50 #endif 69 #endif
51 if (chrome_path.empty()) 70 if (chrome_path.empty())
52 chrome_path = GetChromePathForInstallationLevel(SYSTEM_LEVEL_INSTALLATION); 71 chrome_path = GetChromePathForInstallationLevel(SYSTEM_LEVEL_INSTALLATION);
53 if (chrome_path.empty()) 72 if (chrome_path.empty())
54 chrome_path = GetChromePathForInstallationLevel(USER_LEVEL_INSTALLATION); 73 chrome_path = GetChromePathForInstallationLevel(USER_LEVEL_INSTALLATION);
55 74
56 return chrome_path; 75 return chrome_path;
57 } 76 }
58 77
78 FilePath GetSetupExeForInstallationLevel(InstallationLevel level) {
79 using base::win::RegKey;
80 HKEY root_key = (level == USER_LEVEL_INSTALLATION ?
81 HKEY_CURRENT_USER :
82 HKEY_LOCAL_MACHINE);
83 RegKey reg_key;
84
85 LOG(INFO) << "Seeking reg: " << kChromeBinariesRegClientStateKey;
86
87 if (reg_key.Open(root_key, kChromeBinariesRegClientStateKey,
88 KEY_QUERY_VALUE) == ERROR_SUCCESS) {
89 // Grab the uninstall string from the appropriate ClientState key
90 // and use that as the base for a path to setup.exe.
91 string16 uninstall;
92 if (reg_key.ReadValue(kUninstallStringField, &uninstall) == ERROR_SUCCESS) {
93 // Trim the command line parameters.
94 FilePath setup_exe_path(CommandLine::FromString(uninstall).GetProgram());
95 LOG(INFO) << "Seeking file: " << setup_exe_path.value();
96 if (file_util::PathExists(setup_exe_path))
97 return setup_exe_path;
98 }
99 }
100
101 return FilePath();
102 }
103
59 FilePath GetChromePathForInstallationLevel(InstallationLevel level) { 104 FilePath GetChromePathForInstallationLevel(InstallationLevel level) {
60 using base::win::RegKey; 105 using base::win::RegKey;
erikwright (departed) 2012/09/12 15:53:50 this 'using' can go away.
huangs 2012/09/12 19:24:27 Done.
61 HKEY root_key = (level == USER_LEVEL_INSTALLATION ?
62 HKEY_CURRENT_USER :
63 HKEY_LOCAL_MACHINE);
64 RegKey reg_key(root_key, kChromeRegClientStateKey, KEY_QUERY_VALUE);
65
66 FilePath chrome_exe_path; 106 FilePath chrome_exe_path;
erikwright (departed) 2012/09/12 15:53:50 declaration of chrome_exe_path can go inside "if (
huangs 2012/09/12 19:24:27 Done.
67 107 FilePath setup_exe_path(GetSetupExeForInstallationLevel(level));
68 if (reg_key.Valid()) { 108 if (!setup_exe_path.empty()) {
69 // Now grab the uninstall string from the appropriate ClientState key 109 // The uninstall path contains the path to setup.exe which is two levels
70 // and use that as the base for a path to chrome.exe. 110 // down from chrome.exe. Move up two levels (plus one to drop the file
71 string16 uninstall; 111 // name) and look for chrome.exe from there.
72 if (reg_key.ReadValue(kUninstallStringField, &uninstall) == ERROR_SUCCESS) { 112 chrome_exe_path =
73 // The uninstall path contains the path to setup.exe which is two levels 113 setup_exe_path.DirName().DirName().DirName().Append(kChromeExe);
74 // down from chrome.exe. Move up two levels (plus one to drop the file 114 if (!file_util::PathExists(chrome_exe_path)) {
75 // name) and look for chrome.exe from there. 115 // By way of mild future proofing, look up one to see if there's a
76 FilePath uninstall_path(uninstall); 116 // chrome.exe in the version directory
77 chrome_exe_path = 117 chrome_exe_path =
78 uninstall_path.DirName().DirName().DirName().Append(kChromeExe); 118 chrome_exe_path.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 } 119 }
86 } 120 }
87 121
88 if (file_util::PathExists(chrome_exe_path)) 122 if (file_util::PathExists(chrome_exe_path))
89 return chrome_exe_path; 123 return chrome_exe_path;
90 124
91 return FilePath(); 125 return FilePath();
92 } 126 }
93 127
128 bool GetAppHostVersionString(string16* version_str) {
erikwright (departed) 2012/09/12 15:53:50 This should all be de-duped as: GetAppVersionStri
huangs 2012/09/12 19:24:27 Done, but updating Version* instead of string16*;
129 using base::win::RegKey;
130 HKEY root_key = HKEY_CURRENT_USER; // App Host is always user-level.
131 RegKey reg_key;
132 LOG(INFO) << "Trying to get " << kChromeAppHostRegClientsKey;
133 return (reg_key.Open(root_key, kChromeAppHostRegClientsKey, KEY_QUERY_VALUE)
134 == ERROR_SUCCESS) &&
135 (reg_key.ReadValue(kRegVersionField, version_str) == ERROR_SUCCESS);
136 }
137
138 bool GetChromeBinariesVersionStringForInstallationLevel(InstallationLevel level,
139 string16* version_str) {
140 using base::win::RegKey;
141 HKEY root_key = (level == USER_LEVEL_INSTALLATION ?
142 HKEY_CURRENT_USER :
143 HKEY_LOCAL_MACHINE);
144 RegKey reg_key;
145 LOG(INFO) << "Trying to get " << kChromeBinariesRegClientsKey;
146 return (reg_key.Open(root_key, kChromeBinariesRegClientsKey, KEY_QUERY_VALUE)
147 == ERROR_SUCCESS) &&
148 (reg_key.ReadValue(kRegVersionField, version_str) == ERROR_SUCCESS);
149 }
150
151 bool GetAnyChromeBinariesVersionString(string16* version_str) {
152 return GetChromeBinariesVersionStringForInstallationLevel(
153 SYSTEM_LEVEL_INSTALLATION, version_str) ||
154 GetChromeBinariesVersionStringForInstallationLevel(
155 USER_LEVEL_INSTALLATION, version_str);
156 }
157
158 bool UpgradeAppHost() {
159 // Get the path to setup.exe, trying the system-level first.
160 FilePath setup_exe(
161 GetSetupExeForInstallationLevel(SYSTEM_LEVEL_INSTALLATION));
162 if (setup_exe.empty()) {
163 setup_exe = GetSetupExeForInstallationLevel(USER_LEVEL_INSTALLATION);
164 }
165 if (setup_exe.empty()) {
166 LOG(INFO) << "Failed to find setup.exe";
167 return false;
168 }
169 CommandLine cmd_line(setup_exe);
170 cmd_line.AppendSwitch(local_switches::kMultiInstall);
171 cmd_line.AppendSwitch(local_switches::kChromeAppHost);
172 if (CommandLine::ForCurrentProcess()->HasSwitch(
173 local_switches::kVerboseLogging)) {
174 cmd_line.AppendSwitch(local_switches::kVerboseLogging);
175 }
176 LOG(INFO) << "Command line: " << cmd_line.GetCommandLineString();
177 return base::LaunchProcess(cmd_line, base::LaunchOptions(), NULL);
178 }
179
94 } // namespace chrome_launcher_support 180 } // namespace chrome_launcher_support
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698