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

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: refactored the new code --> template logic in install_util.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
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
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 FilePath& src_path,
265 const Version& new_version) {
grt (UTC plus 2) 2012/05/03 17:49:37 nit: within the context of this function, i think
gab 2012/05/03 19:03:48 Done.
266
267 // Construct the relative path to the versioned VisualElements directory.
268 string16 elements_dir(ASCIIToUTF16(new_version.GetString()));
269 elements_dir.push_back(FilePath::kSeparators[0]);
270 elements_dir.append(installer::kVisualElements);
271
272 // Some distributions of Chromium may not include visual elements. Only
273 // proceed if this distribution does.
274 if (!file_util::PathExists(src_path.Append(elements_dir))) {
275 VLOG(1) << "No visual elements found, not writing "
276 << installer::kVisualElementsManifest << " to " << src_path.value();
277 return true;
278 } else {
279 // A printf_p-style format string for generating the visual elements
280 // manifest. Required arguments, in order, are:
281 // - Localized display name for the product.
282 // - Relative path to the VisualElements directory.
283 static const char kManifestTemplate[] =
284 "<Application>\r\n"
285 " <VisualElements\r\n"
286 " DisplayName='%1$ls'\r\n"
287 " Logo='%2$ls\\Logo.png'\r\n"
288 " SmallLogo='%2$ls\\SmallLogo.png'\r\n"
289 " ForegroundText='light'\r\n"
290 " BackgroundColor='white'>\r\n"
291 " <DefaultTile ShowName='allLogos'/>\r\n"
292 " <SplashScreen Image='%2$ls\\splash-620x300.png'/>\r\n"
293 " </VisualElements>\r\n"
294 "</Application>";
295
296 const string16 manifest_template16(ASCIIToUTF16(kManifestTemplate));
grt (UTC plus 2) 2012/05/03 17:49:37 manifest_template16 -> manifest_template
gab 2012/05/03 19:03:48 Done.
297
298 BrowserDistribution* dist = BrowserDistribution::GetSpecificDistribution(
299 BrowserDistribution::CHROME_BROWSER);
300 // TODO(grt): http://crbug.com/75152 Write a reference to a localized
301 // resource for |display_name|.
302 string16 display_name(dist->GetAppShortCutName());
303 // Escape the display name as per the XML AttValue production
304 // (http://www.w3.org/TR/2008/REC-xml-20081126/#NT-AttValue) for a value in
305 // single quotes.
306 ReplaceChars(display_name, L"&", L"&amp", &display_name);
grt (UTC plus 2) 2012/05/03 17:49:37 &amp -> &amp;
gab 2012/05/03 19:03:48 Done.
307 ReplaceChars(display_name, L"'", L"&apos", &display_name);
grt (UTC plus 2) 2012/05/03 17:49:37 &apos -> &apos;
gab 2012/05/03 19:03:48 Done.
308 ReplaceChars(display_name, L"<", L"&lt", &display_name);
grt (UTC plus 2) 2012/05/03 17:49:37 &lt -> &lt;
gab 2012/05/03 19:03:48 Done.
309
310 // Fill the manifest with the desired values.
311 string16 manifest16(base::StringPrintf(manifest_template16.c_str(),
312 display_name.c_str(),
313 elements_dir.c_str()));
314
315 // Write the manifest to |src_path|.
316 const std::string manifest(UTF16ToUTF8(manifest16));
317 if (file_util::WriteFile(
318 src_path.Append(installer::kVisualElementsManifest),
319 manifest.c_str(), manifest.size())) {
320 VLOG(1) << "Successfully wrote " << installer::kVisualElementsManifest
321 << " to " << src_path.value();
322 return true;
323 } else {
324 PLOG(ERROR) << "Error writing " << installer::kVisualElementsManifest
325 << " to " << src_path.value();
326 return false;
327 }
328 }
329 }
330
257 // This function installs a new version of Chrome to the specified location. 331 // This function installs a new version of Chrome to the specified location.
258 // 332 //
259 // setup_path: Path to the executable (setup.exe) as it will be copied 333 // setup_path: Path to the executable (setup.exe) as it will be copied
260 // to Chrome install folder after install is complete 334 // to Chrome install folder after install is complete
261 // archive_path: Path to the archive (chrome.7z) as it will be copied 335 // archive_path: Path to the archive (chrome.7z) as it will be copied
262 // to Chrome install folder after install is complete 336 // to Chrome install folder after install is complete
263 // src_path: the path that contains a complete and unpacked Chrome package 337 // src_path: the path that contains a complete and unpacked Chrome package
264 // to be installed. 338 // to be installed.
265 // temp_path: the path of working directory used during installation. This path 339 // temp_path: the path of working directory used during installation. This path
266 // does not need to exist. 340 // does not need to exist.
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 const Products& products = installer_state.products(); 444 const Products& products = installer_state.products();
371 DCHECK(products.size()); 445 DCHECK(products.size());
372 if (installer_state.FindProduct(BrowserDistribution::CHROME_FRAME)) { 446 if (installer_state.FindProduct(BrowserDistribution::CHROME_FRAME)) {
373 // Make sure that we don't end up deleting installed files on next reboot. 447 // Make sure that we don't end up deleting installed files on next reboot.
374 if (!RemoveFromMovesPendingReboot( 448 if (!RemoveFromMovesPendingReboot(
375 installer_state.target_path().value().c_str())) { 449 installer_state.target_path().value().c_str())) {
376 LOG(ERROR) << "Error accessing pending moves value."; 450 LOG(ERROR) << "Error accessing pending moves value.";
377 } 451 }
378 } 452 }
379 453
454 // On Windows 8 and above: create VisualElementManifest.xml in |src_path| (if
455 // required) so that it looks as if it had been extracted from the archive
456 // when calling InstallNewVersion() below.
457 if (base::win::GetVersion() >= base::win::VERSION_WIN8) {
458 installer_state.UpdateStage(installer::CREATING_VISUAL_MANIFEST);
459 if (!CreateVisualElementsManifest(src_path, new_version)) {
460 LOG(WARNING) << "Error creating " << kVisualElementsManifest
461 << ". Proceeding with the install anyways...";
grt (UTC plus 2) 2012/05/03 17:49:37 the log message in CreateVisualElementsManifest is
gab 2012/05/03 19:03:48 I debated that. If we say the log is sufficient in
grt (UTC plus 2) 2012/05/03 19:37:58 It doesn't need to return bool in the current use,
gab 2012/05/03 19:50:24 Done.
462 }
463 }
464
380 scoped_ptr<Version> existing_version; 465 scoped_ptr<Version> existing_version;
381 InstallStatus result = InstallNewVersion(original_state, installer_state, 466 InstallStatus result = InstallNewVersion(original_state, installer_state,
382 setup_path, archive_path, src_path, install_temp_path, new_version, 467 setup_path, archive_path, src_path, install_temp_path, new_version,
383 &existing_version); 468 &existing_version);
384 469
385 // TODO(robertshield): Everything below this line should instead be captured 470 // TODO(robertshield): Everything below this line should instead be captured
386 // by WorkItems. 471 // by WorkItems.
387 if (!InstallUtil::GetInstallReturnCode(result)) { 472 if (!InstallUtil::GetInstallReturnCode(result)) {
388 installer_state.UpdateStage(installer::UPDATING_CHANNELS); 473 installer_state.UpdateStage(installer::UPDATING_CHANNELS);
389 474
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 installer_state.RemoveOldVersionDirectories( 547 installer_state.RemoveOldVersionDirectories(
463 new_version, 548 new_version,
464 existing_version.get(), 549 existing_version.get(),
465 install_temp_path); 550 install_temp_path);
466 } 551 }
467 552
468 return result; 553 return result;
469 } 554 }
470 555
471 } // namespace installer 556 } // namespace installer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698