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/setup/install.h" | 5 #include "chrome/installer/setup/install.h" |
| 6 | 6 |
| 7 #include <shlobj.h> | 7 #include <shlobj.h> |
| 8 #include <time.h> | 8 #include <time.h> |
| 9 | |
| 10 #include <string> | |
| 9 #include <vector> | 11 #include <vector> |
| 10 | 12 |
| 11 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 12 #include "base/file_path.h" | 14 #include "base/file_path.h" |
| 13 #include "base/file_util.h" | 15 #include "base/file_util.h" |
| 14 #include "base/logging.h" | 16 #include "base/logging.h" |
| 15 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/path_service.h" | 18 #include "base/path_service.h" |
| 19 #include "base/string16.h" | |
| 17 #include "base/string_util.h" | 20 #include "base/string_util.h" |
| 21 #include "base/stringprintf.h" | |
| 18 #include "base/utf_string_conversions.h" | 22 #include "base/utf_string_conversions.h" |
| 19 #include "base/win/windows_version.h" | 23 #include "base/win/windows_version.h" |
| 20 #include "chrome/common/chrome_constants.h" | 24 #include "chrome/common/chrome_constants.h" |
| 21 #include "chrome/installer/setup/setup_constants.h" | 25 #include "chrome/installer/setup/setup_constants.h" |
| 22 #include "chrome/installer/setup/install_worker.h" | 26 #include "chrome/installer/setup/install_worker.h" |
| 23 #include "chrome/installer/util/auto_launch_util.h" | 27 #include "chrome/installer/util/auto_launch_util.h" |
| 24 #include "chrome/installer/util/browser_distribution.h" | 28 #include "chrome/installer/util/browser_distribution.h" |
| 25 #include "chrome/installer/util/create_reg_key_work_item.h" | 29 #include "chrome/installer/util/create_reg_key_work_item.h" |
| 26 #include "chrome/installer/util/delete_after_reboot_helper.h" | 30 #include "chrome/installer/util/delete_after_reboot_helper.h" |
| 27 #include "chrome/installer/util/google_update_constants.h" | 31 #include "chrome/installer/util/google_update_constants.h" |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 247 if (installer_state.system_install()) | 251 if (installer_state.system_install()) |
| 248 level = level | ShellUtil::SYSTEM_LEVEL; | 252 level = level | ShellUtil::SYSTEM_LEVEL; |
| 249 ShellUtil::MakeChromeDefault(product.distribution(), level, | 253 ShellUtil::MakeChromeDefault(product.distribution(), level, |
| 250 chrome_exe.value(), true); | 254 chrome_exe.value(), true); |
| 251 } else { | 255 } else { |
| 252 ShellUtil::RegisterChromeBrowser(product.distribution(), chrome_exe.value(), | 256 ShellUtil::RegisterChromeBrowser(product.distribution(), chrome_exe.value(), |
| 253 L"", false); | 257 L"", false); |
| 254 } | 258 } |
| 255 } | 259 } |
| 256 | 260 |
| 261 // Creates VisualElementsManifest.xml beside chrome.exe in |src_path| if | |
| 262 // |src_path|\VisualElements exists. | |
| 263 // Returns true unless the manifest is supposed to be created, but fails to be. | |
| 264 bool CreateVisualElementsManifest(const InstallerState& installer_state, | |
| 265 const FilePath& src_path, | |
| 266 const Version& version) { | |
| 267 | |
| 268 installer_state.UpdateStage(installer::CREATING_VISUAL_MANIFEST); | |
|
grt (UTC plus 2)
2012/05/03 19:37:58
i think you should move this back to where it was.
gab
2012/05/03 19:50:24
I just realized this writing the test :).
Done.
| |
| 269 | |
| 270 // Construct the relative path to the versioned VisualElements directory. | |
| 271 string16 elements_dir(ASCIIToUTF16(version.GetString())); | |
| 272 elements_dir.push_back(FilePath::kSeparators[0]); | |
| 273 elements_dir.append(installer::kVisualElements); | |
| 274 | |
| 275 // Some distributions of Chromium may not include visual elements. Only | |
| 276 // proceed if this distribution does. | |
| 277 if (!file_util::PathExists(src_path.Append(elements_dir))) { | |
| 278 VLOG(1) << "No visual elements found, not writing " | |
| 279 << installer::kVisualElementsManifest << " to " << src_path.value(); | |
| 280 return true; | |
| 281 } else { | |
| 282 // A printf_p-style format string for generating the visual elements | |
| 283 // manifest. Required arguments, in order, are: | |
| 284 // - Localized display name for the product. | |
| 285 // - Relative path to the VisualElements directory. | |
| 286 static const char kManifestTemplate[] = | |
| 287 "<Application>\r\n" | |
| 288 " <VisualElements\r\n" | |
| 289 " DisplayName='%1$ls'\r\n" | |
| 290 " Logo='%2$ls\\Logo.png'\r\n" | |
| 291 " SmallLogo='%2$ls\\SmallLogo.png'\r\n" | |
| 292 " ForegroundText='light'\r\n" | |
| 293 " BackgroundColor='white'>\r\n" | |
| 294 " <DefaultTile ShowName='allLogos'/>\r\n" | |
| 295 " <SplashScreen Image='%2$ls\\splash-620x300.png'/>\r\n" | |
| 296 " </VisualElements>\r\n" | |
| 297 "</Application>"; | |
| 298 | |
| 299 const string16 manifest_template(ASCIIToUTF16(kManifestTemplate)); | |
| 300 | |
| 301 BrowserDistribution* dist = BrowserDistribution::GetSpecificDistribution( | |
| 302 BrowserDistribution::CHROME_BROWSER); | |
| 303 // TODO(grt): http://crbug.com/75152 Write a reference to a localized | |
| 304 // resource for |display_name|. | |
| 305 string16 display_name(dist->GetAppShortCutName()); | |
| 306 // Escape the display name as per the XML AttValue production | |
| 307 // (http://www.w3.org/TR/2008/REC-xml-20081126/#NT-AttValue) for a value in | |
| 308 // single quotes. | |
| 309 ReplaceChars(display_name, L"&", L"&", &display_name); | |
| 310 ReplaceChars(display_name, L"'", L"'", &display_name); | |
| 311 ReplaceChars(display_name, L"<", L"<", &display_name); | |
| 312 | |
| 313 // Fill the manifest with the desired values. | |
| 314 string16 manifest16(base::StringPrintf(manifest_template.c_str(), | |
| 315 display_name.c_str(), | |
| 316 elements_dir.c_str())); | |
| 317 | |
| 318 // Write the manifest to |src_path|. | |
| 319 const std::string manifest(UTF16ToUTF8(manifest16)); | |
| 320 if (file_util::WriteFile( | |
| 321 src_path.Append(installer::kVisualElementsManifest), | |
| 322 manifest.c_str(), manifest.size())) { | |
| 323 VLOG(1) << "Successfully wrote " << installer::kVisualElementsManifest | |
| 324 << " to " << src_path.value(); | |
| 325 return true; | |
| 326 } else { | |
| 327 PLOG(ERROR) << "Error writing " << installer::kVisualElementsManifest | |
| 328 << " to " << src_path.value(); | |
| 329 return false; | |
| 330 } | |
| 331 } | |
| 332 } | |
| 333 | |
| 257 // This function installs a new version of Chrome to the specified location. | 334 // This function installs a new version of Chrome to the specified location. |
| 258 // | 335 // |
| 259 // setup_path: Path to the executable (setup.exe) as it will be copied | 336 // setup_path: Path to the executable (setup.exe) as it will be copied |
| 260 // to Chrome install folder after install is complete | 337 // to Chrome install folder after install is complete |
| 261 // archive_path: Path to the archive (chrome.7z) as it will be copied | 338 // archive_path: Path to the archive (chrome.7z) as it will be copied |
| 262 // to Chrome install folder after install is complete | 339 // to Chrome install folder after install is complete |
| 263 // src_path: the path that contains a complete and unpacked Chrome package | 340 // src_path: the path that contains a complete and unpacked Chrome package |
| 264 // to be installed. | 341 // to be installed. |
| 265 // temp_path: the path of working directory used during installation. This path | 342 // temp_path: the path of working directory used during installation. This path |
| 266 // does not need to exist. | 343 // does not need to exist. |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 370 const Products& products = installer_state.products(); | 447 const Products& products = installer_state.products(); |
| 371 DCHECK(products.size()); | 448 DCHECK(products.size()); |
| 372 if (installer_state.FindProduct(BrowserDistribution::CHROME_FRAME)) { | 449 if (installer_state.FindProduct(BrowserDistribution::CHROME_FRAME)) { |
| 373 // Make sure that we don't end up deleting installed files on next reboot. | 450 // Make sure that we don't end up deleting installed files on next reboot. |
| 374 if (!RemoveFromMovesPendingReboot( | 451 if (!RemoveFromMovesPendingReboot( |
| 375 installer_state.target_path().value().c_str())) { | 452 installer_state.target_path().value().c_str())) { |
| 376 LOG(ERROR) << "Error accessing pending moves value."; | 453 LOG(ERROR) << "Error accessing pending moves value."; |
| 377 } | 454 } |
| 378 } | 455 } |
| 379 | 456 |
| 457 // On Windows 8 and above: create VisualElementManifest.xml in |src_path| (if | |
| 458 // required) so that it looks as if it had been extracted from the archive | |
| 459 // when calling InstallNewVersion() below. | |
| 460 if (base::win::GetVersion() >= base::win::VERSION_WIN8 && | |
| 461 !CreateVisualElementsManifest(installer_state, src_path, new_version)) { | |
| 462 LOG(WARNING) << "Error creating " << kVisualElementsManifest | |
| 463 << ". Proceeding with the install anyways..."; | |
| 464 } | |
| 465 | |
| 380 scoped_ptr<Version> existing_version; | 466 scoped_ptr<Version> existing_version; |
| 381 InstallStatus result = InstallNewVersion(original_state, installer_state, | 467 InstallStatus result = InstallNewVersion(original_state, installer_state, |
| 382 setup_path, archive_path, src_path, install_temp_path, new_version, | 468 setup_path, archive_path, src_path, install_temp_path, new_version, |
| 383 &existing_version); | 469 &existing_version); |
| 384 | 470 |
| 385 // TODO(robertshield): Everything below this line should instead be captured | 471 // TODO(robertshield): Everything below this line should instead be captured |
| 386 // by WorkItems. | 472 // by WorkItems. |
| 387 if (!InstallUtil::GetInstallReturnCode(result)) { | 473 if (!InstallUtil::GetInstallReturnCode(result)) { |
| 388 installer_state.UpdateStage(installer::UPDATING_CHANNELS); | 474 installer_state.UpdateStage(installer::UPDATING_CHANNELS); |
| 389 | 475 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 462 installer_state.RemoveOldVersionDirectories( | 548 installer_state.RemoveOldVersionDirectories( |
| 463 new_version, | 549 new_version, |
| 464 existing_version.get(), | 550 existing_version.get(), |
| 465 install_temp_path); | 551 install_temp_path); |
| 466 } | 552 } |
| 467 | 553 |
| 468 return result; | 554 return result; |
| 469 } | 555 } |
| 470 | 556 |
| 471 } // namespace installer | 557 } // namespace installer |
| OLD | NEW |