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

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

Issue 10160011: Create VisualElementsManifest.xml from template -- install VisualElements in the version directory (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: new line at end of install_unittest.cc Created 8 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 <shlobj.h> 7 #include <shlobj.h>
8 #include <time.h> 8 #include <time.h>
9 #include <vector>
10 9
11 #include "base/command_line.h" 10 #include "base/command_line.h"
12 #include "base/file_path.h" 11 #include "base/file_path.h"
13 #include "base/file_util.h" 12 #include "base/file_util.h"
14 #include "base/logging.h" 13 #include "base/logging.h"
15 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
16 #include "base/path_service.h" 15 #include "base/path_service.h"
16 #include "base/string16.h"
17 #include "base/string_util.h" 17 #include "base/string_util.h"
18 #include "base/stringprintf.h"
18 #include "base/utf_string_conversions.h" 19 #include "base/utf_string_conversions.h"
19 #include "base/win/windows_version.h" 20 #include "base/win/windows_version.h"
20 #include "chrome/common/chrome_constants.h" 21 #include "chrome/common/chrome_constants.h"
21 #include "chrome/installer/setup/setup_constants.h" 22 #include "chrome/installer/setup/setup_constants.h"
22 #include "chrome/installer/setup/install_worker.h" 23 #include "chrome/installer/setup/install_worker.h"
23 #include "chrome/installer/util/auto_launch_util.h" 24 #include "chrome/installer/util/auto_launch_util.h"
24 #include "chrome/installer/util/browser_distribution.h" 25 #include "chrome/installer/util/browser_distribution.h"
25 #include "chrome/installer/util/create_reg_key_work_item.h" 26 #include "chrome/installer/util/create_reg_key_work_item.h"
26 #include "chrome/installer/util/delete_after_reboot_helper.h" 27 #include "chrome/installer/util/delete_after_reboot_helper.h"
27 #include "chrome/installer/util/google_update_constants.h" 28 #include "chrome/installer/util/google_update_constants.h"
28 #include "chrome/installer/util/helper.h" 29 #include "chrome/installer/util/helper.h"
29 #include "chrome/installer/util/install_util.h" 30 #include "chrome/installer/util/install_util.h"
30 #include "chrome/installer/util/installation_state.h" 31 #include "chrome/installer/util/installation_state.h"
31 #include "chrome/installer/util/installer_state.h" 32 #include "chrome/installer/util/installer_state.h"
32 #include "chrome/installer/util/master_preferences.h" 33 #include "chrome/installer/util/master_preferences.h"
33 #include "chrome/installer/util/master_preferences_constants.h" 34 #include "chrome/installer/util/master_preferences_constants.h"
34 #include "chrome/installer/util/product.h"
35 #include "chrome/installer/util/set_reg_value_work_item.h" 35 #include "chrome/installer/util/set_reg_value_work_item.h"
36 #include "chrome/installer/util/shell_util.h" 36 #include "chrome/installer/util/shell_util.h"
37 #include "chrome/installer/util/util_constants.h"
38 #include "chrome/installer/util/work_item_list.h" 37 #include "chrome/installer/util/work_item_list.h"
39 38
40 // Build-time generated include file. 39 // Build-time generated include file.
41 #include "registered_dlls.h" // NOLINT 40 #include "registered_dlls.h" // NOLINT
42 41
43 using installer::InstallerState; 42 using installer::InstallerState;
44 using installer::InstallationState; 43 using installer::InstallationState;
45 using installer::Product; 44 using installer::Product;
46 45
47 namespace { 46 namespace {
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 << ", new version: " << new_version.GetString() 345 << ", new version: " << new_version.GetString()
347 << ", old version: " << (*current_version)->GetString(); 346 << ", old version: " << (*current_version)->GetString();
348 347
349 return installer::INSTALL_FAILED; 348 return installer::INSTALL_FAILED;
350 } 349 }
351 350
352 } // end namespace 351 } // end namespace
353 352
354 namespace installer { 353 namespace installer {
355 354
355 void EscapeXmlAttributeValueInSingleQuotes(string16* att_value) {
356 ReplaceChars(*att_value, L"&", L"&amp;", att_value);
357 ReplaceChars(*att_value, L"'", L"&apos;", att_value);
358 ReplaceChars(*att_value, L"<", L"&lt;", att_value);
359 }
360
361 bool CreateVisualElementsManifest(const FilePath& src_path,
362 const Version& version) {
363 // Construct the relative path to the versioned VisualElements directory.
364 string16 elements_dir(ASCIIToUTF16(version.GetString()));
365 elements_dir.push_back(FilePath::kSeparators[0]);
366 elements_dir.append(installer::kVisualElements);
367
368 // Some distributions of Chromium may not include visual elements. Only
369 // proceed if this distribution does.
370 if (!file_util::PathExists(src_path.Append(elements_dir))) {
371 VLOG(1) << "No visual elements found, not writing "
372 << installer::kVisualElementsManifest << " to " << src_path.value();
373 return true;
374 } else {
375 // A printf_p-style format string for generating the visual elements
376 // manifest. Required arguments, in order, are:
377 // - Localized display name for the product.
378 // - Relative path to the VisualElements directory.
379 static const char kManifestTemplate[] =
380 "<Application>\r\n"
381 " <VisualElements\r\n"
382 " DisplayName='%1$ls'\r\n"
383 " Logo='%2$ls\\Logo.png'\r\n"
384 " SmallLogo='%2$ls\\SmallLogo.png'\r\n"
385 " ForegroundText='light'\r\n"
386 " BackgroundColor='white'>\r\n"
387 " <DefaultTile ShowName='allLogos'/>\r\n"
388 " <SplashScreen Image='%2$ls\\splash-620x300.png'/>\r\n"
389 " </VisualElements>\r\n"
390 "</Application>";
391
392 const string16 manifest_template(ASCIIToUTF16(kManifestTemplate));
393
394 BrowserDistribution* dist = BrowserDistribution::GetSpecificDistribution(
395 BrowserDistribution::CHROME_BROWSER);
396 // TODO(grt): http://crbug.com/75152 Write a reference to a localized
397 // resource for |display_name|.
398 string16 display_name(dist->GetAppShortCutName());
399 EscapeXmlAttributeValueInSingleQuotes(&display_name);
400
401 // Fill the manifest with the desired values.
402 string16 manifest16(base::StringPrintf(manifest_template.c_str(),
403 display_name.c_str(),
404 elements_dir.c_str()));
405
406 // Write the manifest to |src_path|.
407 const std::string manifest(UTF16ToUTF8(manifest16));
408 if (file_util::WriteFile(
409 src_path.Append(installer::kVisualElementsManifest),
410 manifest.c_str(), manifest.size())) {
411 VLOG(1) << "Successfully wrote " << installer::kVisualElementsManifest
412 << " to " << src_path.value();
413 return true;
414 } else {
415 PLOG(ERROR) << "Error writing " << installer::kVisualElementsManifest
416 << " to " << src_path.value();
417 return false;
418 }
419 }
420 }
421
356 InstallStatus InstallOrUpdateProduct( 422 InstallStatus InstallOrUpdateProduct(
357 const InstallationState& original_state, 423 const InstallationState& original_state,
358 const InstallerState& installer_state, 424 const InstallerState& installer_state,
359 const FilePath& setup_path, 425 const FilePath& setup_path,
360 const FilePath& archive_path, 426 const FilePath& archive_path,
361 const FilePath& install_temp_path, 427 const FilePath& install_temp_path,
362 const FilePath& prefs_path, 428 const FilePath& prefs_path,
363 const MasterPreferences& prefs, 429 const MasterPreferences& prefs,
364 const Version& new_version) { 430 const Version& new_version) {
365 FilePath src_path(install_temp_path); 431 FilePath src_path(install_temp_path);
366 src_path = src_path.Append(kInstallSourceDir).Append(kInstallSourceChromeDir); 432 src_path = src_path.Append(kInstallSourceDir).Append(kInstallSourceChromeDir);
367 433
368 // TODO(robertshield): Removing the pending on-reboot moves should be done 434 // TODO(robertshield): Removing the pending on-reboot moves should be done
369 // elsewhere. 435 // elsewhere.
370 const Products& products = installer_state.products(); 436 const Products& products = installer_state.products();
371 DCHECK(products.size()); 437 DCHECK(products.size());
372 if (installer_state.FindProduct(BrowserDistribution::CHROME_FRAME)) { 438 if (installer_state.FindProduct(BrowserDistribution::CHROME_FRAME)) {
373 // Make sure that we don't end up deleting installed files on next reboot. 439 // Make sure that we don't end up deleting installed files on next reboot.
374 if (!RemoveFromMovesPendingReboot( 440 if (!RemoveFromMovesPendingReboot(
375 installer_state.target_path().value().c_str())) { 441 installer_state.target_path().value().c_str())) {
376 LOG(ERROR) << "Error accessing pending moves value."; 442 LOG(ERROR) << "Error accessing pending moves value.";
377 } 443 }
378 } 444 }
379 445
446 // Create VisualElementManifest.xml in |src_path| (if required) so that it
447 // looks as if it had been extracted from the archive when calling
448 // InstallNewVersion() below.
449 installer_state.UpdateStage(installer::CREATING_VISUAL_MANIFEST);
450 CreateVisualElementsManifest(src_path, new_version);
451
380 scoped_ptr<Version> existing_version; 452 scoped_ptr<Version> existing_version;
381 InstallStatus result = InstallNewVersion(original_state, installer_state, 453 InstallStatus result = InstallNewVersion(original_state, installer_state,
382 setup_path, archive_path, src_path, install_temp_path, new_version, 454 setup_path, archive_path, src_path, install_temp_path, new_version,
383 &existing_version); 455 &existing_version);
384 456
385 // TODO(robertshield): Everything below this line should instead be captured 457 // TODO(robertshield): Everything below this line should instead be captured
386 // by WorkItems. 458 // by WorkItems.
387 if (!InstallUtil::GetInstallReturnCode(result)) { 459 if (!InstallUtil::GetInstallReturnCode(result)) {
388 installer_state.UpdateStage(installer::UPDATING_CHANNELS); 460 installer_state.UpdateStage(installer::UPDATING_CHANNELS);
389 461
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 installer_state.RemoveOldVersionDirectories( 534 installer_state.RemoveOldVersionDirectories(
463 new_version, 535 new_version,
464 existing_version.get(), 536 existing_version.get(),
465 install_temp_path); 537 install_temp_path);
466 } 538 }
467 539
468 return result; 540 return result;
469 } 541 }
470 542
471 } // namespace installer 543 } // namespace installer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698