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

Side by Side Diff: chrome/installer/setup/install.cc

Issue 296593003: Make various string_util functions take StringPieces instead of char[]. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 7 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 | Annotate | Revision Log
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/setup/install.h" 5 #include "chrome/installer/setup/install.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <shlobj.h> 8 #include <shlobj.h>
9 #include <time.h> 9 #include <time.h>
10 10
(...skipping 24 matching lines...) Expand all
35 #include "chrome/installer/util/google_update_constants.h" 35 #include "chrome/installer/util/google_update_constants.h"
36 #include "chrome/installer/util/helper.h" 36 #include "chrome/installer/util/helper.h"
37 #include "chrome/installer/util/install_util.h" 37 #include "chrome/installer/util/install_util.h"
38 #include "chrome/installer/util/master_preferences.h" 38 #include "chrome/installer/util/master_preferences.h"
39 #include "chrome/installer/util/master_preferences_constants.h" 39 #include "chrome/installer/util/master_preferences_constants.h"
40 #include "chrome/installer/util/set_reg_value_work_item.h" 40 #include "chrome/installer/util/set_reg_value_work_item.h"
41 #include "chrome/installer/util/shell_util.h" 41 #include "chrome/installer/util/shell_util.h"
42 #include "chrome/installer/util/util_constants.h" 42 #include "chrome/installer/util/util_constants.h"
43 #include "chrome/installer/util/work_item_list.h" 43 #include "chrome/installer/util/work_item_list.h"
44 44
45 using base::ASCIIToUTF16;
46 using base::UTF16ToUTF8;
47 using installer::InstallerState;
48 using installer::InstallationState;
49 using installer::Product;
50 45
51 namespace { 46 namespace {
52 47
53 void LogShortcutOperation(ShellUtil::ShortcutLocation location, 48 void LogShortcutOperation(ShellUtil::ShortcutLocation location,
54 BrowserDistribution* dist, 49 BrowserDistribution* dist,
55 const ShellUtil::ShortcutProperties& properties, 50 const ShellUtil::ShortcutProperties& properties,
56 ShellUtil::ShortcutOperation operation, 51 ShellUtil::ShortcutOperation operation,
57 bool failed) { 52 bool failed) {
58 // ShellUtil::SHELL_SHORTCUT_UPDATE_EXISTING should not be used at install and 53 // ShellUtil::SHELL_SHORTCUT_UPDATE_EXISTING should not be used at install and
59 // thus this method does not handle logging a message for it. 54 // thus this method does not handle logging a message for it.
(...skipping 11 matching lines...) Expand all
71 "all-users "); 66 "all-users ");
72 switch (location) { 67 switch (location) {
73 case ShellUtil::SHORTCUT_LOCATION_DESKTOP: 68 case ShellUtil::SHORTCUT_LOCATION_DESKTOP:
74 message.append("Desktop "); 69 message.append("Desktop ");
75 break; 70 break;
76 case ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH: 71 case ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH:
77 message.append("Quick Launch "); 72 message.append("Quick Launch ");
78 break; 73 break;
79 case ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR: 74 case ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR:
80 message.append("Start menu/" + 75 message.append("Start menu/" +
81 UTF16ToUTF8(dist->GetStartMenuShortcutSubfolder( 76 base::UTF16ToUTF8(dist->GetStartMenuShortcutSubfolder(
82 BrowserDistribution::SUBFOLDER_CHROME)) + 77 BrowserDistribution::SUBFOLDER_CHROME)) +
83 " "); 78 " ");
84 break; 79 break;
85 case ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR: 80 case ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR:
86 message.append("Start menu/" + 81 message.append("Start menu/" +
87 UTF16ToUTF8(dist->GetStartMenuShortcutSubfolder( 82 base::UTF16ToUTF8(dist->GetStartMenuShortcutSubfolder(
88 BrowserDistribution::SUBFOLDER_APPS)) + 83 BrowserDistribution::SUBFOLDER_APPS)) +
89 " "); 84 " ");
90 break; 85 break;
91 default: 86 default:
92 NOTREACHED(); 87 NOTREACHED();
93 } 88 }
94 89
95 message.push_back('"'); 90 message.push_back('"');
96 if (properties.has_shortcut_name()) 91 if (properties.has_shortcut_name())
97 message.append(UTF16ToUTF8(properties.shortcut_name)); 92 message.append(base::UTF16ToUTF8(properties.shortcut_name));
98 else 93 else
99 message.append(UTF16ToUTF8(dist->GetDisplayName())); 94 message.append(base::UTF16ToUTF8(dist->GetDisplayName()));
100 message.push_back('"'); 95 message.push_back('"');
101 96
102 message.append(" shortcut to "); 97 message.append(" shortcut to ");
103 message.append(UTF16ToUTF8(properties.target.value())); 98 message.append(base::UTF16ToUTF8(properties.target.value()));
104 if (properties.has_arguments()) 99 if (properties.has_arguments())
105 message.append(UTF16ToUTF8(properties.arguments)); 100 message.append(base::UTF16ToUTF8(properties.arguments));
106 101
107 if (properties.pin_to_taskbar && 102 if (properties.pin_to_taskbar &&
108 base::win::GetVersion() >= base::win::VERSION_WIN7) { 103 base::win::GetVersion() >= base::win::VERSION_WIN7) {
109 message.append(" and pinning to the taskbar."); 104 message.append(" and pinning to the taskbar.");
110 } else { 105 } else {
111 message.push_back('.'); 106 message.push_back('.');
112 } 107 }
113 108
114 if (failed) 109 if (failed)
115 LOG(WARNING) << message; 110 LOG(WARNING) << message;
(...skipping 23 matching lines...) Expand all
139 HKEY_LOCAL_MACHINE, reg_path)); 134 HKEY_LOCAL_MACHINE, reg_path));
140 135
141 // if the operation fails we log the error but still continue 136 // if the operation fails we log the error but still continue
142 if (!work_item.get()->Do()) 137 if (!work_item.get()->Do())
143 LOG(ERROR) << "Could not add Chrome to media player inclusion list."; 138 LOG(ERROR) << "Could not add Chrome to media player inclusion list.";
144 } 139 }
145 140
146 // Copy master_preferences file provided to installer, in the same folder 141 // Copy master_preferences file provided to installer, in the same folder
147 // as chrome.exe so Chrome first run can find it. This function will be called 142 // as chrome.exe so Chrome first run can find it. This function will be called
148 // only on the first install of Chrome. 143 // only on the first install of Chrome.
149 void CopyPreferenceFileForFirstRun(const InstallerState& installer_state, 144 void CopyPreferenceFileForFirstRun(
150 const base::FilePath& prefs_source_path) { 145 const installer::InstallerState& installer_state,
146 const base::FilePath& prefs_source_path) {
151 base::FilePath prefs_dest_path(installer_state.target_path().AppendASCII( 147 base::FilePath prefs_dest_path(installer_state.target_path().AppendASCII(
152 installer::kDefaultMasterPrefs)); 148 installer::kDefaultMasterPrefs));
153 if (!base::CopyFile(prefs_source_path, prefs_dest_path)) { 149 if (!base::CopyFile(prefs_source_path, prefs_dest_path)) {
154 VLOG(1) << "Failed to copy master preferences from:" 150 VLOG(1) << "Failed to copy master preferences from:"
155 << prefs_source_path.value() << " gle: " << ::GetLastError(); 151 << prefs_source_path.value() << " gle: " << ::GetLastError();
156 } 152 }
157 } 153 }
158 154
159 // This function installs a new version of Chrome to the specified location. 155 // This function installs a new version of Chrome to the specified location.
160 // 156 //
161 // setup_path: Path to the executable (setup.exe) as it will be copied 157 // setup_path: Path to the executable (setup.exe) as it will be copied
162 // to Chrome install folder after install is complete 158 // to Chrome install folder after install is complete
163 // archive_path: Path to the archive (chrome.7z) as it will be copied 159 // archive_path: Path to the archive (chrome.7z) as it will be copied
164 // to Chrome install folder after install is complete 160 // to Chrome install folder after install is complete
165 // src_path: the path that contains a complete and unpacked Chrome package 161 // src_path: the path that contains a complete and unpacked Chrome package
166 // to be installed. 162 // to be installed.
167 // temp_path: the path of working directory used during installation. This path 163 // temp_path: the path of working directory used during installation. This path
168 // does not need to exist. 164 // does not need to exist.
169 // new_version: new Chrome version that needs to be installed 165 // new_version: new Chrome version that needs to be installed
170 // current_version: returns the current active version (if any) 166 // current_version: returns the current active version (if any)
171 // 167 //
172 // This function makes best effort to do installation in a transactional 168 // This function makes best effort to do installation in a transactional
173 // manner. If failed it tries to rollback all changes on the file system 169 // manner. If failed it tries to rollback all changes on the file system
174 // and registry. For example, if package exists before calling the 170 // and registry. For example, if package exists before calling the
175 // function, it rolls back all new file and directory changes under 171 // function, it rolls back all new file and directory changes under
176 // package. If package does not exist before calling the function 172 // package. If package does not exist before calling the function
177 // (typical new install), the function creates package during install 173 // (typical new install), the function creates package during install
178 // and removes the whole directory during rollback. 174 // and removes the whole directory during rollback.
179 installer::InstallStatus InstallNewVersion( 175 installer::InstallStatus InstallNewVersion(
180 const InstallationState& original_state, 176 const installer::InstallationState& original_state,
181 const InstallerState& installer_state, 177 const installer::InstallerState& installer_state,
182 const base::FilePath& setup_path, 178 const base::FilePath& setup_path,
183 const base::FilePath& archive_path, 179 const base::FilePath& archive_path,
184 const base::FilePath& src_path, 180 const base::FilePath& src_path,
185 const base::FilePath& temp_path, 181 const base::FilePath& temp_path,
186 const Version& new_version, 182 const Version& new_version,
187 scoped_ptr<Version>* current_version) { 183 scoped_ptr<Version>* current_version) {
188 DCHECK(current_version); 184 DCHECK(current_version);
189 185
190 installer_state.UpdateStage(installer::BUILDING); 186 installer_state.UpdateStage(installer::BUILDING);
191 187
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 << ", old version: " << (*current_version)->GetString(); 245 << ", old version: " << (*current_version)->GetString();
250 246
251 return installer::INSTALL_FAILED; 247 return installer::INSTALL_FAILED;
252 } 248 }
253 249
254 // Deletes the old "Uninstall Google Chrome" shortcut in the Start menu and, if 250 // Deletes the old "Uninstall Google Chrome" shortcut in the Start menu and, if
255 // this is a system-level install, also deletes the old Default user Quick 251 // this is a system-level install, also deletes the old Default user Quick
256 // Launch shortcut. Both of these were created prior to Chrome 24; in Chrome 24, 252 // Launch shortcut. Both of these were created prior to Chrome 24; in Chrome 24,
257 // the uninstall shortcut was removed and the Default user Quick Launch shortcut 253 // the uninstall shortcut was removed and the Default user Quick Launch shortcut
258 // was replaced by per-user shortcuts created via Active Setup. 254 // was replaced by per-user shortcuts created via Active Setup.
259 void CleanupLegacyShortcuts(const InstallerState& installer_state, 255 void CleanupLegacyShortcuts(const installer::InstallerState& installer_state,
260 BrowserDistribution* dist, 256 BrowserDistribution* dist,
261 const base::FilePath& chrome_exe) { 257 const base::FilePath& chrome_exe) {
262 ShellUtil::ShellChange shortcut_level = installer_state.system_install() ? 258 ShellUtil::ShellChange shortcut_level = installer_state.system_install() ?
263 ShellUtil::SYSTEM_LEVEL : ShellUtil::CURRENT_USER; 259 ShellUtil::SYSTEM_LEVEL : ShellUtil::CURRENT_USER;
264 base::FilePath uninstall_shortcut_path; 260 base::FilePath uninstall_shortcut_path;
265 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR, 261 ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR,
266 dist, shortcut_level, &uninstall_shortcut_path); 262 dist, shortcut_level, &uninstall_shortcut_path);
267 uninstall_shortcut_path = uninstall_shortcut_path.Append( 263 uninstall_shortcut_path = uninstall_shortcut_path.Append(
268 dist->GetUninstallLinkName() + installer::kLnkExt); 264 dist->GetUninstallLinkName() + installer::kLnkExt);
269 base::DeleteFile(uninstall_shortcut_path, false); 265 base::DeleteFile(uninstall_shortcut_path, false);
270 266
271 if (installer_state.system_install()) { 267 if (installer_state.system_install()) {
272 ShellUtil::RemoveShortcuts( 268 ShellUtil::RemoveShortcuts(
273 ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH, dist, 269 ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH, dist,
274 ShellUtil::SYSTEM_LEVEL, chrome_exe); 270 ShellUtil::SYSTEM_LEVEL, chrome_exe);
275 } 271 }
276 } 272 }
277 273
278 // Returns the appropriate shortcut operations for App Launcher, 274 // Returns the appropriate shortcut operations for App Launcher,
279 // based on state of installation and master_preferences. 275 // based on state of installation and master_preferences.
280 installer::InstallShortcutOperation GetAppLauncherShortcutOperation( 276 installer::InstallShortcutOperation GetAppLauncherShortcutOperation(
281 const InstallationState& original_state, 277 const installer::InstallationState& original_state,
282 const InstallerState& installer_state) { 278 const installer::InstallerState& installer_state) {
283 const installer::ProductState* original_app_host_state = 279 const installer::ProductState* original_app_host_state =
284 original_state.GetProductState(installer_state.system_install(), 280 original_state.GetProductState(installer_state.system_install(),
285 BrowserDistribution::CHROME_APP_HOST); 281 BrowserDistribution::CHROME_APP_HOST);
286 bool app_launcher_exists = original_app_host_state && 282 bool app_launcher_exists = original_app_host_state &&
287 original_app_host_state->uninstall_command() 283 original_app_host_state->uninstall_command()
288 .HasSwitch(installer::switches::kChromeAppLauncher); 284 .HasSwitch(installer::switches::kChromeAppLauncher);
289 if (!app_launcher_exists) 285 if (!app_launcher_exists)
290 return installer::INSTALL_SHORTCUT_CREATE_ALL; 286 return installer::INSTALL_SHORTCUT_CREATE_ALL;
291 287
292 return installer::INSTALL_SHORTCUT_REPLACE_EXISTING; 288 return installer::INSTALL_SHORTCUT_REPLACE_EXISTING;
293 } 289 }
294 290
295 } // end namespace 291 } // end namespace
296 292
297 namespace installer { 293 namespace installer {
298 294
299 void EscapeXmlAttributeValueInSingleQuotes(base::string16* att_value) { 295 void EscapeXmlAttributeValueInSingleQuotes(base::string16* att_value) {
300 base::ReplaceChars(*att_value, L"&", L"&amp;", att_value); 296 base::ReplaceChars(*att_value, base::ASCIIToUTF16("&"),
301 base::ReplaceChars(*att_value, L"'", L"&apos;", att_value); 297 base::ASCIIToUTF16("&amp;"), att_value);
302 base::ReplaceChars(*att_value, L"<", L"&lt;", att_value); 298 base::ReplaceChars(*att_value, base::ASCIIToUTF16("'"),
299 base::ASCIIToUTF16("&apos;"), att_value);
300 base::ReplaceChars(*att_value, base::ASCIIToUTF16("<"),
301 base::ASCIIToUTF16("&lt;"), att_value);
303 } 302 }
304 303
305 bool CreateVisualElementsManifest(const base::FilePath& src_path, 304 bool CreateVisualElementsManifest(const base::FilePath& src_path,
306 const Version& version) { 305 const Version& version) {
307 // Construct the relative path to the versioned VisualElements directory. 306 // Construct the relative path to the versioned VisualElements directory.
308 base::string16 elements_dir(ASCIIToUTF16(version.GetString())); 307 base::string16 elements_dir(base::ASCIIToUTF16(version.GetString()));
309 elements_dir.push_back(base::FilePath::kSeparators[0]); 308 elements_dir.push_back(base::FilePath::kSeparators[0]);
310 elements_dir.append(installer::kVisualElements); 309 elements_dir.append(installer::kVisualElements);
311 310
312 // Some distributions of Chromium may not include visual elements. Only 311 // Some distributions of Chromium may not include visual elements. Only
313 // proceed if this distribution does. 312 // proceed if this distribution does.
314 if (!base::PathExists(src_path.Append(elements_dir))) { 313 if (!base::PathExists(src_path.Append(elements_dir))) {
315 VLOG(1) << "No visual elements found, not writing " 314 VLOG(1) << "No visual elements found, not writing "
316 << installer::kVisualElementsManifest << " to " << src_path.value(); 315 << installer::kVisualElementsManifest << " to " << src_path.value();
317 return true; 316 return true;
318 } else { 317 } else {
319 // A printf_p-style format string for generating the visual elements 318 // A printf_p-style format string for generating the visual elements
320 // manifest. Required arguments, in order, are: 319 // manifest. Required arguments, in order, are:
321 // - Localized display name for the product. 320 // - Localized display name for the product.
322 // - Relative path to the VisualElements directory. 321 // - Relative path to the VisualElements directory.
323 static const char kManifestTemplate[] = 322 static const char kManifestTemplate[] =
324 "<Application>\r\n" 323 "<Application>\r\n"
325 " <VisualElements\r\n" 324 " <VisualElements\r\n"
326 " DisplayName='%1$ls'\r\n" 325 " DisplayName='%1$ls'\r\n"
327 " Logo='%2$ls\\Logo.png'\r\n" 326 " Logo='%2$ls\\Logo.png'\r\n"
328 " SmallLogo='%2$ls\\SmallLogo.png'\r\n" 327 " SmallLogo='%2$ls\\SmallLogo.png'\r\n"
329 " ForegroundText='light'\r\n" 328 " ForegroundText='light'\r\n"
330 " BackgroundColor='#323232'>\r\n" 329 " BackgroundColor='#323232'>\r\n"
331 " <DefaultTile ShowName='allLogos'/>\r\n" 330 " <DefaultTile ShowName='allLogos'/>\r\n"
332 " <SplashScreen Image='%2$ls\\splash-620x300.png'/>\r\n" 331 " <SplashScreen Image='%2$ls\\splash-620x300.png'/>\r\n"
333 " </VisualElements>\r\n" 332 " </VisualElements>\r\n"
334 "</Application>"; 333 "</Application>";
335 334
336 const base::string16 manifest_template(ASCIIToUTF16(kManifestTemplate)); 335 const base::string16 manifest_template(
336 base::ASCIIToUTF16(kManifestTemplate));
337 337
338 BrowserDistribution* dist = BrowserDistribution::GetSpecificDistribution( 338 BrowserDistribution* dist = BrowserDistribution::GetSpecificDistribution(
339 BrowserDistribution::CHROME_BROWSER); 339 BrowserDistribution::CHROME_BROWSER);
340 // TODO(grt): http://crbug.com/75152 Write a reference to a localized 340 // TODO(grt): http://crbug.com/75152 Write a reference to a localized
341 // resource for |display_name|. 341 // resource for |display_name|.
342 base::string16 display_name(dist->GetDisplayName()); 342 base::string16 display_name(dist->GetDisplayName());
343 EscapeXmlAttributeValueInSingleQuotes(&display_name); 343 EscapeXmlAttributeValueInSingleQuotes(&display_name);
344 344
345 // Fill the manifest with the desired values. 345 // Fill the manifest with the desired values.
346 base::string16 manifest16(base::StringPrintf( 346 base::string16 manifest16(base::StringPrintf(
347 manifest_template.c_str(), display_name.c_str(), elements_dir.c_str())); 347 manifest_template.c_str(), display_name.c_str(), elements_dir.c_str()));
348 348
349 // Write the manifest to |src_path|. 349 // Write the manifest to |src_path|.
350 const std::string manifest(UTF16ToUTF8(manifest16)); 350 const std::string manifest(base::UTF16ToUTF8(manifest16));
351 int size = base::checked_cast<int>(manifest.size()); 351 int size = base::checked_cast<int>(manifest.size());
352 if (base::WriteFile( 352 if (base::WriteFile(
353 src_path.Append(installer::kVisualElementsManifest), 353 src_path.Append(installer::kVisualElementsManifest),
354 manifest.c_str(), size) == size) { 354 manifest.c_str(), size) == size) {
355 VLOG(1) << "Successfully wrote " << installer::kVisualElementsManifest 355 VLOG(1) << "Successfully wrote " << installer::kVisualElementsManifest
356 << " to " << src_path.value(); 356 << " to " << src_path.value();
357 return true; 357 return true;
358 } else { 358 } else {
359 PLOG(ERROR) << "Error writing " << installer::kVisualElementsManifest 359 PLOG(ERROR) << "Error writing " << installer::kVisualElementsManifest
360 << " to " << src_path.value(); 360 << " to " << src_path.value();
361 return false; 361 return false;
362 } 362 }
363 } 363 }
364 } 364 }
365 365
366 void CreateOrUpdateShortcuts( 366 void CreateOrUpdateShortcuts(
367 const base::FilePath& target, 367 const base::FilePath& target,
368 const Product& product, 368 const installer::Product& product,
369 const MasterPreferences& prefs, 369 const MasterPreferences& prefs,
370 InstallShortcutLevel install_level, 370 InstallShortcutLevel install_level,
371 InstallShortcutOperation install_operation) { 371 InstallShortcutOperation install_operation) {
372 bool do_not_create_any_shortcuts = false; 372 bool do_not_create_any_shortcuts = false;
373 prefs.GetBool(master_preferences::kDoNotCreateAnyShortcuts, 373 prefs.GetBool(master_preferences::kDoNotCreateAnyShortcuts,
374 &do_not_create_any_shortcuts); 374 &do_not_create_any_shortcuts);
375 if (do_not_create_any_shortcuts) 375 if (do_not_create_any_shortcuts)
376 return; 376 return;
377 377
378 // Extract shortcut preferences from |prefs|. 378 // Extract shortcut preferences from |prefs|.
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 (shortcut_operation == ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS || 462 (shortcut_operation == ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS ||
463 shortcut_operation == 463 shortcut_operation ==
464 ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL)) { 464 ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL)) {
465 start_menu_properties.set_pin_to_taskbar(true); 465 start_menu_properties.set_pin_to_taskbar(true);
466 } 466 }
467 ExecuteAndLogShortcutOperation( 467 ExecuteAndLogShortcutOperation(
468 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR, dist, 468 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR, dist,
469 start_menu_properties, shortcut_operation); 469 start_menu_properties, shortcut_operation);
470 } 470 }
471 471
472 void RegisterChromeOnMachine(const InstallerState& installer_state, 472 void RegisterChromeOnMachine(const installer::InstallerState& installer_state,
473 const Product& product, 473 const installer::Product& product,
474 bool make_chrome_default) { 474 bool make_chrome_default) {
475 DCHECK(product.is_chrome()); 475 DCHECK(product.is_chrome());
476 476
477 // Try to add Chrome to Media Player shim inclusion list. We don't do any 477 // Try to add Chrome to Media Player shim inclusion list. We don't do any
478 // error checking here because this operation will fail if user doesn't 478 // error checking here because this operation will fail if user doesn't
479 // have admin rights and we want to ignore the error. 479 // have admin rights and we want to ignore the error.
480 AddChromeToMediaPlayerList(); 480 AddChromeToMediaPlayerList();
481 481
482 // Make Chrome the default browser if desired when possible. Otherwise, only 482 // Make Chrome the default browser if desired when possible. Otherwise, only
483 // register it with Windows. 483 // register it with Windows.
484 BrowserDistribution* dist = product.distribution(); 484 BrowserDistribution* dist = product.distribution();
485 const base::string16 chrome_exe( 485 const base::string16 chrome_exe(
486 installer_state.target_path().Append(installer::kChromeExe).value()); 486 installer_state.target_path().Append(installer::kChromeExe).value());
487 VLOG(1) << "Registering Chrome as browser: " << chrome_exe; 487 VLOG(1) << "Registering Chrome as browser: " << chrome_exe;
488 if (make_chrome_default && ShellUtil::CanMakeChromeDefaultUnattended()) { 488 if (make_chrome_default && ShellUtil::CanMakeChromeDefaultUnattended()) {
489 int level = ShellUtil::CURRENT_USER; 489 int level = ShellUtil::CURRENT_USER;
490 if (installer_state.system_install()) 490 if (installer_state.system_install())
491 level = level | ShellUtil::SYSTEM_LEVEL; 491 level = level | ShellUtil::SYSTEM_LEVEL;
492 ShellUtil::MakeChromeDefault(dist, level, chrome_exe, true); 492 ShellUtil::MakeChromeDefault(dist, level, chrome_exe, true);
493 } else { 493 } else {
494 ShellUtil::RegisterChromeBrowser(dist, chrome_exe, base::string16(), false); 494 ShellUtil::RegisterChromeBrowser(dist, chrome_exe, base::string16(), false);
495 } 495 }
496 } 496 }
497 497
498 InstallStatus InstallOrUpdateProduct( 498 InstallStatus InstallOrUpdateProduct(
499 const InstallationState& original_state, 499 const installer::InstallationState& original_state,
500 const InstallerState& installer_state, 500 const installer::InstallerState& installer_state,
501 const base::FilePath& setup_path, 501 const base::FilePath& setup_path,
502 const base::FilePath& archive_path, 502 const base::FilePath& archive_path,
503 const base::FilePath& install_temp_path, 503 const base::FilePath& install_temp_path,
504 const base::FilePath& src_path, 504 const base::FilePath& src_path,
505 const base::FilePath& prefs_path, 505 const base::FilePath& prefs_path,
506 const MasterPreferences& prefs, 506 const MasterPreferences& prefs,
507 const Version& new_version) { 507 const Version& new_version) {
508 DCHECK(!installer_state.products().empty()); 508 DCHECK(!installer_state.products().empty());
509 509
510 // TODO(robertshield): Removing the pending on-reboot moves should be done 510 // TODO(robertshield): Removing the pending on-reboot moves should be done
(...skipping 24 matching lines...) Expand all
535 // installed and for the binaries in case of multi-install. 535 // installed and for the binaries in case of multi-install.
536 installer_state.UpdateChannels(); 536 installer_state.UpdateChannels();
537 537
538 installer_state.UpdateStage(installer::COPYING_PREFERENCES_FILE); 538 installer_state.UpdateStage(installer::COPYING_PREFERENCES_FILE);
539 539
540 if (result == FIRST_INSTALL_SUCCESS && !prefs_path.empty()) 540 if (result == FIRST_INSTALL_SUCCESS && !prefs_path.empty())
541 CopyPreferenceFileForFirstRun(installer_state, prefs_path); 541 CopyPreferenceFileForFirstRun(installer_state, prefs_path);
542 542
543 installer_state.UpdateStage(installer::CREATING_SHORTCUTS); 543 installer_state.UpdateStage(installer::CREATING_SHORTCUTS);
544 544
545 const Product* app_launcher_product = 545 const installer::Product* app_launcher_product =
546 installer_state.FindProduct(BrowserDistribution::CHROME_APP_HOST); 546 installer_state.FindProduct(BrowserDistribution::CHROME_APP_HOST);
547 // Creates shortcuts for App Launcher. 547 // Creates shortcuts for App Launcher.
548 if (app_launcher_product) { 548 if (app_launcher_product) {
549 // TODO(huangs): Remove this check once we have system-level App Host. 549 // TODO(huangs): Remove this check once we have system-level App Host.
550 DCHECK(!installer_state.system_install()); 550 DCHECK(!installer_state.system_install());
551 const base::FilePath app_host_exe( 551 const base::FilePath app_host_exe(
552 installer_state.target_path().Append(kChromeAppHostExe)); 552 installer_state.target_path().Append(kChromeAppHostExe));
553 InstallShortcutOperation app_launcher_shortcut_operation = 553 InstallShortcutOperation app_launcher_shortcut_operation =
554 GetAppLauncherShortcutOperation(original_state, installer_state); 554 GetAppLauncherShortcutOperation(original_state, installer_state);
555 555
556 // Always install per-user shortcuts for App Launcher. 556 // Always install per-user shortcuts for App Launcher.
557 CreateOrUpdateShortcuts(app_host_exe, *app_launcher_product, prefs, 557 CreateOrUpdateShortcuts(app_host_exe, *app_launcher_product, prefs,
558 CURRENT_USER, app_launcher_shortcut_operation); 558 CURRENT_USER, app_launcher_shortcut_operation);
559 } 559 }
560 560
561 const Product* chrome_product = 561 const installer::Product* chrome_product =
562 installer_state.FindProduct(BrowserDistribution::CHROME_BROWSER); 562 installer_state.FindProduct(BrowserDistribution::CHROME_BROWSER);
563 // Creates shortcuts for Chrome. 563 // Creates shortcuts for Chrome.
564 if (chrome_product) { 564 if (chrome_product) {
565 BrowserDistribution* chrome_dist = chrome_product->distribution(); 565 BrowserDistribution* chrome_dist = chrome_product->distribution();
566 const base::FilePath chrome_exe( 566 const base::FilePath chrome_exe(
567 installer_state.target_path().Append(kChromeExe)); 567 installer_state.target_path().Append(kChromeExe));
568 CleanupLegacyShortcuts(installer_state, chrome_dist, chrome_exe); 568 CleanupLegacyShortcuts(installer_state, chrome_dist, chrome_exe);
569 569
570 // Install per-user shortcuts on user-level installs and all-users 570 // Install per-user shortcuts on user-level installs and all-users
571 // shortcuts on system-level installs. Note that Active Setup will take 571 // shortcuts on system-level installs. Note that Active Setup will take
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 if (result == FIRST_INSTALL_SUCCESS) { 616 if (result == FIRST_INSTALL_SUCCESS) {
617 installer_state.UpdateStage(installer::CONFIGURE_AUTO_LAUNCH); 617 installer_state.UpdateStage(installer::CONFIGURE_AUTO_LAUNCH);
618 618
619 // Add auto-launch key if specified in master_preferences. 619 // Add auto-launch key if specified in master_preferences.
620 bool auto_launch_chrome = false; 620 bool auto_launch_chrome = false;
621 prefs.GetBool( 621 prefs.GetBool(
622 installer::master_preferences::kAutoLaunchChrome, 622 installer::master_preferences::kAutoLaunchChrome,
623 &auto_launch_chrome); 623 &auto_launch_chrome);
624 if (auto_launch_chrome) { 624 if (auto_launch_chrome) {
625 auto_launch_util::EnableForegroundStartAtLogin( 625 auto_launch_util::EnableForegroundStartAtLogin(
626 ASCIIToUTF16(chrome::kInitialProfile), 626 base::ASCIIToUTF16(chrome::kInitialProfile),
627 installer_state.target_path()); 627 installer_state.target_path());
628 } 628 }
629 } 629 }
630 } 630 }
631 631
632 installer_state.UpdateStage(installer::REMOVING_OLD_VERSIONS); 632 installer_state.UpdateStage(installer::REMOVING_OLD_VERSIONS);
633 633
634 installer_state.RemoveOldVersionDirectories( 634 installer_state.RemoveOldVersionDirectories(
635 new_version, 635 new_version,
636 existing_version.get(), 636 existing_version.get(),
637 install_temp_path); 637 install_temp_path);
638 } 638 }
639 639
640 return result; 640 return result;
641 } 641 }
642 642
643 void HandleOsUpgradeForBrowser(const InstallerState& installer_state, 643 void HandleOsUpgradeForBrowser(const installer::InstallerState& installer_state,
644 const Product& chrome) { 644 const installer::Product& chrome) {
645 DCHECK(chrome.is_chrome()); 645 DCHECK(chrome.is_chrome());
646 // Upon upgrading to Windows 8, we need to fix Chrome shortcuts and register 646 // Upon upgrading to Windows 8, we need to fix Chrome shortcuts and register
647 // Chrome, so that Metro Chrome would work if Chrome is the default browser. 647 // Chrome, so that Metro Chrome would work if Chrome is the default browser.
648 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { 648 if (base::win::GetVersion() >= base::win::VERSION_WIN8) {
649 VLOG(1) << "Updating and registering shortcuts."; 649 VLOG(1) << "Updating and registering shortcuts.";
650 // Read master_preferences copied beside chrome.exe at install. 650 // Read master_preferences copied beside chrome.exe at install.
651 MasterPreferences prefs( 651 MasterPreferences prefs(
652 installer_state.target_path().AppendASCII(kDefaultMasterPrefs)); 652 installer_state.target_path().AppendASCII(kDefaultMasterPrefs));
653 653
654 // Unfortunately, if this is a system-level install, we can't update the 654 // Unfortunately, if this is a system-level install, we can't update the
655 // shortcuts of each individual user (this only matters if this is an OS 655 // shortcuts of each individual user (this only matters if this is an OS
656 // upgrade from XP/Vista to Win7+ as some properties are only set on 656 // upgrade from XP/Vista to Win7+ as some properties are only set on
657 // shortcuts as of Win7). 657 // shortcuts as of Win7).
658 // At least attempt to update potentially existing all-users shortcuts. 658 // At least attempt to update potentially existing all-users shortcuts.
659 InstallShortcutLevel level = installer_state.system_install() ? 659 InstallShortcutLevel level = installer_state.system_install() ?
660 ALL_USERS : CURRENT_USER; 660 ALL_USERS : CURRENT_USER;
661 base::FilePath chrome_exe(installer_state.target_path().Append(kChromeExe)); 661 base::FilePath chrome_exe(installer_state.target_path().Append(kChromeExe));
662 CreateOrUpdateShortcuts( 662 CreateOrUpdateShortcuts(
663 chrome_exe, chrome, prefs, level, INSTALL_SHORTCUT_REPLACE_EXISTING); 663 chrome_exe, chrome, prefs, level, INSTALL_SHORTCUT_REPLACE_EXISTING);
664 RegisterChromeOnMachine(installer_state, chrome, false); 664 RegisterChromeOnMachine(installer_state, chrome, false);
665 } 665 }
666 } 666 }
667 667
668 // NOTE: Should the work done here, on Active Setup, change: kActiveSetupVersion 668 // NOTE: Should the work done here, on Active Setup, change: kActiveSetupVersion
669 // in install_worker.cc needs to be increased for Active Setup to invoke this 669 // in install_worker.cc needs to be increased for Active Setup to invoke this
670 // again for all users of this install. 670 // again for all users of this install.
671 void HandleActiveSetupForBrowser(const base::FilePath& installation_root, 671 void HandleActiveSetupForBrowser(const base::FilePath& installation_root,
672 const Product& chrome, 672 const installer::Product& chrome,
673 bool force) { 673 bool force) {
674 DCHECK(chrome.is_chrome()); 674 DCHECK(chrome.is_chrome());
675 // Only create shortcuts on Active Setup if the first run sentinel is not 675 // Only create shortcuts on Active Setup if the first run sentinel is not
676 // present for this user (as some shortcuts used to be installed on first 676 // present for this user (as some shortcuts used to be installed on first
677 // run and this could otherwise re-install shortcuts for users that have 677 // run and this could otherwise re-install shortcuts for users that have
678 // already deleted them in the past). 678 // already deleted them in the past).
679 // Decide whether to create the shortcuts or simply replace existing 679 // Decide whether to create the shortcuts or simply replace existing
680 // shortcuts; if the decision is to create them, only shortcuts whose matching 680 // shortcuts; if the decision is to create them, only shortcuts whose matching
681 // all-users shortcut isn't present on the system will be created. 681 // all-users shortcut isn't present on the system will be created.
682 InstallShortcutOperation install_operation = 682 InstallShortcutOperation install_operation =
(...skipping 13 matching lines...) Expand all
696 if (app_host_path.empty()) 696 if (app_host_path.empty())
697 return false; 697 return false;
698 698
699 CommandLine cmd(app_host_path); 699 CommandLine cmd(app_host_path);
700 cmd.AppendSwitchASCII(::switches::kInstallFromWebstore, app_code); 700 cmd.AppendSwitchASCII(::switches::kInstallFromWebstore, app_code);
701 VLOG(1) << "App install command: " << cmd.GetCommandLineString(); 701 VLOG(1) << "App install command: " << cmd.GetCommandLineString();
702 return base::LaunchProcess(cmd, base::LaunchOptions(), NULL); 702 return base::LaunchProcess(cmd, base::LaunchOptions(), NULL);
703 } 703 }
704 704
705 } // namespace installer 705 } // namespace installer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698