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

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

Powered by Google App Engine
This is Rietveld 408576698