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

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

Issue 10912096: C++ reability review for gab. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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 // This file contains the definitions of the installer functions that build 5 // This file contains the definitions of the installer functions that build
6 // the WorkItemList used to install the application. 6 // the WorkItemList used to install the application.
7 7
8 //Pickup file for readability review.
9
8 #include "chrome/installer/setup/install_worker.h" 10 #include "chrome/installer/setup/install_worker.h"
9 11
10 #include <oaidl.h> 12 #include <oaidl.h>
11 #include <shlobj.h> 13 #include <shlobj.h>
12 #include <time.h> 14 #include <time.h>
13 15
14 #include <vector> 16 #include <vector>
15 17
16 #include "base/bind.h" 18 #include "base/bind.h"
17 #include "base/command_line.h" 19 #include "base/command_line.h"
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 const FilePath* setup_path, 287 const FilePath* setup_path,
286 const Version* new_version, 288 const Version* new_version,
287 const Product& product, 289 const Product& product,
288 WorkItemList* work_item_list) { 290 WorkItemList* work_item_list) {
289 DCHECK(product.is_chrome_app_host()); 291 DCHECK(product.is_chrome_app_host());
290 292
291 string16 cmd_key(product.distribution()->GetVersionKey()); 293 string16 cmd_key(product.distribution()->GetVersionKey());
292 cmd_key.append(1, L'\\').append(google_update::kRegCommandsKey) 294 cmd_key.append(1, L'\\').append(google_update::kRegCommandsKey)
293 .append(1, L'\\').append(kCmdInstallApp); 295 .append(1, L'\\').append(kCmdInstallApp);
294 296
295 if (installer_state.operation() != InstallerState::UNINSTALL) { 297 if (installer_state.operation() != InstallerState::UNINSTALL) {
dominich 2012/09/06 17:26:12 Consider swapping these conditionals so the positi
gab 2012/09/07 20:56:44 Done.
296 FilePath target_path(installer_state.target_path()); 298 FilePath target_path(installer_state.target_path());
297 CommandLine cmd_line(target_path.Append(installer::kChromeAppHostExe)); 299 CommandLine cmd_line(target_path.Append(installer::kChromeAppHostExe));
298 cmd_line.AppendSwitchASCII(::switches::kAppsInstallFromManifestURL, "%1"); 300 cmd_line.AppendSwitchASCII(::switches::kAppsInstallFromManifestURL, "%1");
299 301
300 AppCommand cmd(cmd_line.GetCommandLineString()); 302 AppCommand cmd(cmd_line.GetCommandLineString());
301 cmd.set_sends_pings(true); 303 cmd.set_sends_pings(true);
302 cmd.set_is_web_accessible(true); 304 cmd.set_is_web_accessible(true);
303 cmd.AddWorkItems(installer_state.root_key(), cmd_key, work_item_list); 305 cmd.AddWorkItems(installer_state.root_key(), cmd_key, work_item_list);
304 } else { 306 } else {
305 work_item_list->AddDeleteRegKeyWorkItem(installer_state.root_key(), 307 work_item_list->AddDeleteRegKeyWorkItem(installer_state.root_key(),
306 cmd_key)->set_log_message( 308 cmd_key)->set_log_message(
307 "removing install-application command"); 309 "removing install-application command");
dominich 2012/09/06 17:26:12 more readable: work_item_list->AddDeleteRegKeyWor
gab 2012/09/07 20:56:44 Done.
308 } 310 }
309 } 311 }
310 312
311 void AddProductSpecificWorkItems(const InstallationState& original_state, 313 void AddProductSpecificWorkItems(const InstallationState& original_state,
312 const InstallerState& installer_state, 314 const InstallerState& installer_state,
313 const FilePath& setup_path, 315 const FilePath& setup_path,
314 const Version& new_version, 316 const Version& new_version,
315 WorkItemList* list) { 317 WorkItemList* list) {
316 const Products& products = installer_state.products(); 318 const Products& products = installer_state.products();
317 for (size_t i = 0; i < products.size(); ++i) { 319 for (size_t i = 0; i < products.size(); ++i) {
dominich 2012/09/06 17:26:12 consider using an iterator for the loop here as it
gab 2012/09/07 20:56:44 Done.
318 const Product& p = *products[i]; 320 const Product& p = *products[i];
319 if (p.is_chrome_frame()) { 321 if (p.is_chrome_frame()) {
320 AddChromeFrameWorkItems(original_state, installer_state, setup_path, 322 AddChromeFrameWorkItems(original_state, installer_state, setup_path,
321 new_version, p, list); 323 new_version, p, list);
322 } 324 }
323 if (p.is_chrome_app_host()) { 325 if (p.is_chrome_app_host()) {
324 AddInstallAppCommandWorkItems(installer_state, original_state, 326 AddInstallAppCommandWorkItems(installer_state, original_state,
325 &setup_path, &new_version, p, list); 327 &setup_path, &new_version, p, list);
326 } 328 }
327 if (p.is_chrome()) { 329 if (p.is_chrome()) {
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 747
746 if (current_version != NULL && current_version->get() != NULL) { 748 if (current_version != NULL && current_version->get() != NULL) {
747 // Delete the archive from an existing install to save some disk space. We 749 // Delete the archive from an existing install to save some disk space. We
748 // make this an unconditional work item since there's no need to roll this 750 // make this an unconditional work item since there's no need to roll this
749 // back; if installation fails we'll be moved to the "-full" channel anyway. 751 // back; if installation fails we'll be moved to the "-full" channel anyway.
750 FilePath old_installer_dir( 752 FilePath old_installer_dir(
751 installer_state.GetInstallerDirectory(**current_version)); 753 installer_state.GetInstallerDirectory(**current_version));
752 FilePath old_archive(old_installer_dir.Append(installer::kChromeArchive)); 754 FilePath old_archive(old_installer_dir.Append(installer::kChromeArchive));
753 // Don't delete the archive that we are actually installing from. 755 // Don't delete the archive that we are actually installing from.
754 if (archive_path != old_archive) { 756 if (archive_path != old_archive) {
755 install_list->AddDeleteTreeWorkItem(old_archive, temp_path) 757 install_list->AddDeleteTreeWorkItem(old_archive, temp_path)
dominich 2012/09/06 17:26:12 nit: can you move the -> up to this line? it makes
gab 2012/09/07 20:56:44 Done.
756 ->set_ignore_failure(true); 758 ->set_ignore_failure(true);
757 } 759 }
758 } 760 }
759 761
760 // Delete any new_chrome.exe if present (we will end up creating a new one 762 // Delete any new_chrome.exe if present (we will end up creating a new one
761 // if required) and then copy chrome.exe 763 // if required) and then copy chrome.exe
762 FilePath new_chrome_exe(target_path.Append(installer::kChromeNewExe)); 764 FilePath new_chrome_exe(target_path.Append(installer::kChromeNewExe));
763 765
764 install_list->AddDeleteTreeWorkItem(new_chrome_exe, temp_path); 766 install_list->AddDeleteTreeWorkItem(new_chrome_exe, temp_path);
765 767
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 install_list->AddMoveTreeWorkItem( 845 install_list->AddMoveTreeWorkItem(
844 src_path.AppendASCII(new_version.GetString()).value(), 846 src_path.AppendASCII(new_version.GetString()).value(),
845 target_path.AppendASCII(new_version.GetString()).value(), 847 target_path.AppendASCII(new_version.GetString()).value(),
846 temp_path.value(), 848 temp_path.value(),
847 check_for_duplicates ? WorkItem::CHECK_DUPLICATES : 849 check_for_duplicates ? WorkItem::CHECK_DUPLICATES :
848 WorkItem::ALWAYS_MOVE); 850 WorkItem::ALWAYS_MOVE);
849 851
850 // Delete any old_chrome.exe if present (ignore failure if it's in use). 852 // Delete any old_chrome.exe if present (ignore failure if it's in use).
851 install_list->AddDeleteTreeWorkItem( 853 install_list->AddDeleteTreeWorkItem(
852 target_path.Append(installer::kChromeOldExe), temp_path) 854 target_path.Append(installer::kChromeOldExe), temp_path)
853 ->set_ignore_failure(true); 855 ->set_ignore_failure(true);
dominich 2012/09/06 17:26:12 nit: 4 space indent.
gab 2012/09/07 20:56:44 Done.
854 856
855 // Copy installer in install directory and 857 // Copy installer in install directory and
856 // add shortcut in Control Panel->Add/Remove Programs. 858 // add shortcut in Control Panel->Add/Remove Programs.
857 AddInstallerCopyTasks(installer_state, setup_path, archive_path, temp_path, 859 AddInstallerCopyTasks(installer_state, setup_path, archive_path, temp_path,
858 new_version, install_list); 860 new_version, install_list);
859 861
860 } 862 }
861 863
862 void AddInstallWorkItems(const InstallationState& original_state, 864 void AddInstallWorkItems(const InstallationState& original_state,
863 const InstallerState& installer_state, 865 const InstallerState& installer_state,
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
1005 BrowserDistribution* dist = 1007 BrowserDistribution* dist =
1006 installer_state.multi_package_binaries_distribution(); 1008 installer_state.multi_package_binaries_distribution();
1007 if (ready_mode) { 1009 if (ready_mode) {
1008 // If GCF is being installed in ready mode, we write an entry to the 1010 // If GCF is being installed in ready mode, we write an entry to the
1009 // multi-install state key. If the value already exists, we will not 1011 // multi-install state key. If the value already exists, we will not
1010 // overwrite it since the user might have opted out. 1012 // overwrite it since the user might have opted out.
1011 list->AddCreateRegKeyWorkItem(root, dist->GetStateKey()); 1013 list->AddCreateRegKeyWorkItem(root, dist->GetStateKey());
1012 list->AddSetRegValueWorkItem(root, dist->GetStateKey(), 1014 list->AddSetRegValueWorkItem(root, dist->GetStateKey(),
1013 kChromeFrameReadyModeField, 1015 kChromeFrameReadyModeField,
1014 static_cast<int64>(is_install ? 1 : 0), // The value we want to set. 1016 static_cast<int64>(is_install ? 1 : 0), // The value we want to set.
1015 is_install ? false : true); // Overwrite existing value. 1017 is_install ? false : true); // Overwrite existing value.
dominich 2012/09/06 17:26:12 nit: !is_install
gab 2012/09/07 20:56:44 Done.
1016 if (is_install) { 1018 if (is_install) {
1017 FilePath installer_path(installer_state 1019 FilePath installer_path(installer_state
1018 .GetInstallerDirectory(new_version).Append(setup_path.BaseName())); 1020 .GetInstallerDirectory(new_version).Append(setup_path.BaseName()));
1019 1021
1020 CommandLine basic_cl(installer_path); 1022 CommandLine basic_cl(installer_path);
1021 basic_cl.AppendSwitch(switches::kChromeFrame); 1023 basic_cl.AppendSwitch(switches::kChromeFrame);
1022 basic_cl.AppendSwitch(switches::kMultiInstall); 1024 basic_cl.AppendSwitch(switches::kMultiInstall);
1023 1025
1024 if (installer_state.system_install()) 1026 if (installer_state.system_install())
1025 basic_cl.AppendSwitch(switches::kSystemLevel); 1027 basic_cl.AppendSwitch(switches::kSystemLevel);
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
1398 installer_state.operation() == InstallerState::UNINSTALL); 1400 installer_state.operation() == InstallerState::UNINSTALL);
1399 DCHECK(work_item_list); 1401 DCHECK(work_item_list);
1400 1402
1401 const bool system_install = installer_state.system_install(); 1403 const bool system_install = installer_state.system_install();
1402 bool have_chrome_binaries = false; 1404 bool have_chrome_binaries = false;
1403 1405
1404 // STEP 1: Figure out the state of the machine before the operation. 1406 // STEP 1: Figure out the state of the machine before the operation.
1405 const ProductState* product_state = NULL; 1407 const ProductState* product_state = NULL;
1406 1408
1407 // Are the Chrome Binaries already on the machine? 1409 // Are the Chrome Binaries already on the machine?
1408 product_state = 1410 product_state =
dominich 2012/09/06 17:26:12 shorter: product_state = machine_state.GetProduct
gab 2012/09/07 20:56:44 Done.
1409 machine_state.GetProductState(system_install, 1411 machine_state.GetProductState(system_install,
1410 BrowserDistribution::CHROME_BINARIES); 1412 BrowserDistribution::CHROME_BINARIES);
1411 if (product_state != NULL && product_state->is_multi_install()) 1413 if (product_state != NULL && product_state->is_multi_install())
1412 have_chrome_binaries = true; 1414 have_chrome_binaries = true;
1413 1415
1414 // STEP 2: Now take into account the current operation. 1416 // STEP 2: Now take into account the current operation.
1415 const Product* product = NULL; 1417 const Product* product = NULL;
1416 1418
1417 if (installer_state.operation() == InstallerState::UNINSTALL) { 1419 if (installer_state.operation() == InstallerState::UNINSTALL) {
1418 // Forget about multi-install Chrome if it is being uninstalled. 1420 // Forget about multi-install Chrome if it is being uninstalled.
1419 product = 1421 product =
dominich 2012/09/06 17:26:12 this _should_ fit on one line. 1 other place in t
gab 2012/09/07 20:56:44 Done.
1420 installer_state.FindProduct(BrowserDistribution::CHROME_BINARIES); 1422 installer_state.FindProduct(BrowserDistribution::CHROME_BINARIES);
1421 if (product != NULL && installer_state.is_multi_install()) 1423 if (product != NULL && installer_state.is_multi_install())
1422 have_chrome_binaries = false; 1424 have_chrome_binaries = false;
1423 } else { 1425 } else {
1424 // Check if we're installing Chrome Binaries 1426 // Check if we're installing Chrome Binaries
1425 product = 1427 product =
1426 installer_state.FindProduct(BrowserDistribution::CHROME_BINARIES); 1428 installer_state.FindProduct(BrowserDistribution::CHROME_BINARIES);
1427 if (product != NULL && installer_state.is_multi_install()) 1429 if (product != NULL && installer_state.is_multi_install())
1428 have_chrome_binaries = true; 1430 have_chrome_binaries = true;
1429 } 1431 }
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
1618 AppCommand cmd(cmd_line.GetCommandLineString()); 1620 AppCommand cmd(cmd_line.GetCommandLineString());
1619 cmd.set_is_auto_run_on_os_upgrade(true); 1621 cmd.set_is_auto_run_on_os_upgrade(true);
1620 cmd.AddWorkItems(installer_state.root_key(), cmd_key, install_list); 1622 cmd.AddWorkItems(installer_state.root_key(), cmd_key, install_list);
1621 } else { 1623 } else {
1622 install_list->AddDeleteRegKeyWorkItem(root_key, cmd_key) 1624 install_list->AddDeleteRegKeyWorkItem(root_key, cmd_key)
1623 ->set_log_message("Removing OS upgrade command"); 1625 ->set_log_message("Removing OS upgrade command");
1624 } 1626 }
1625 } 1627 }
1626 1628
1627 } // namespace installer 1629 } // namespace installer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698