Skip to content

Commit

Permalink
Temp dir cleanup:
Browse files Browse the repository at this point in the history
- use ScopedTempDir in work items that need backup space for rollback
- all work items that need backup space take a parent dir in which they create temp dirs
- use ScopedTempDir in a few other places
- renamed some parameters in certain functions so that the same name is used everywhere

While I was at it, I couldn't help but replace Append(UTF8ToWide(version.GetString())) with the more pleasing AppendASCII(version.GetString())

BUG=70368
TEST=existing tests in installer_util_unittests cover the changes

Review URL: http://codereview.chromium.org/6538025

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75392 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
grt@chromium.org committed Feb 18, 2011
1 parent 7e91c59 commit bdddb67
Show file tree
Hide file tree
Showing 22 changed files with 297 additions and 265 deletions.
4 changes: 1 addition & 3 deletions base/file_util_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -606,13 +606,11 @@ bool CreateTemporaryDirInDir(const FilePath& base_dir,
for (int count = 0; count < 50; ++count) {
// Try create a new temporary directory with random generated name. If
// the one exists, keep trying another path name until we reach some limit.
path_to_create = base_dir;

string16 new_dir_name;
new_dir_name.assign(prefix);
new_dir_name.append(base::IntToString16(rand() % kint16max));

path_to_create = path_to_create.Append(new_dir_name);
path_to_create = base_dir.Append(new_dir_name);
if (::CreateDirectory(path_to_create.value().c_str(), NULL)) {
*new_dir = path_to_create;
return true;
Expand Down
8 changes: 7 additions & 1 deletion chrome/installer/setup/chrome_frame_quick_enable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <windows.h>

#include "base/logging.h"
#include "base/scoped_temp_dir.h"
#include "base/string_util.h"
#include "base/win/registry.h"
#include "chrome/installer/setup/install_worker.h"
Expand Down Expand Up @@ -79,6 +80,11 @@ InstallStatus ChromeFrameQuickEnable(const InstallationState& machine_state,
LOG(ERROR) << "AddProduct failed";
status = INSTALL_FAILED;
} else {
ScopedTempDir temp_path;
if (!temp_path.CreateUniqueTempDir()) {
PLOG(ERROR) << "Failed to create Temp directory";
return INSTALL_FAILED;
}
scoped_ptr<WorkItemList> item_list(WorkItem::CreateWorkItemList());
const ProductState* chrome_state =
machine_state.GetProductState(installer_state->system_install(),
Expand Down Expand Up @@ -106,7 +112,7 @@ InstallStatus ChromeFrameQuickEnable(const InstallationState& machine_state,

const Version* opv = chrome_state->old_version();
AppendPostInstallTasks(*installer_state, setup_path, new_chrome_exe, opv,
new_version, item_list.get());
new_version, temp_path.path(), item_list.get());

// Before updating the channel values, add Chrome back to the mix so that
// all multi-installed products' channel values get updated.
Expand Down
34 changes: 5 additions & 29 deletions chrome/installer/setup/install.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,30 +57,6 @@ void AddChromeToMediaPlayerList() {
LOG(ERROR) << "Could not add Chrome to media player inclusion list.";
}

void AddInstallerCopyTasks(const InstallerState& installer_state,
const FilePath& setup_path,
const FilePath& archive_path,
const FilePath& temp_path,
const Version& new_version,
WorkItemList* install_list) {
DCHECK(install_list);
FilePath installer_dir(installer_state.GetInstallerDirectory(new_version));
install_list->AddCreateDirWorkItem(installer_dir);

FilePath exe_dst(installer_dir.Append(setup_path.BaseName()));
FilePath archive_dst(installer_dir.Append(archive_path.BaseName()));

install_list->AddCopyTreeWorkItem(setup_path.value(), exe_dst.value(),
temp_path.value(), WorkItem::ALWAYS);
if (installer_state.system_install()) {
install_list->AddCopyTreeWorkItem(archive_path.value(), archive_dst.value(),
temp_path.value(), WorkItem::ALWAYS);
} else {
install_list->AddMoveTreeWorkItem(archive_path.value(), archive_dst.value(),
temp_path.value());
}
}

// Copy master preferences file provided to installer, in the same folder
// as chrome.exe so Chrome first run can find it. This function will be called
// only on the first install of Chrome.
Expand Down Expand Up @@ -263,8 +239,8 @@ void RegisterChromeOnMachine(const InstallerState& installer_state,
// to Chrome install folder after install is complete
// src_path: the path that contains a complete and unpacked Chrome package
// to be installed.
// temp_dir: the path of working directory used during installation. This path
// does not need to exist.
// temp_path: the path of working directory used during installation. This path
// does not need to exist.
// new_version: new Chrome version that needs to be installed
// current_version: returns the current active version (if any)
//
Expand All @@ -281,7 +257,7 @@ installer::InstallStatus InstallNewVersion(
const FilePath& setup_path,
const FilePath& archive_path,
const FilePath& src_path,
const FilePath& temp_dir,
const FilePath& temp_path,
const Version& new_version,
scoped_ptr<Version>* current_version) {
DCHECK(current_version);
Expand All @@ -294,7 +270,7 @@ installer::InstallStatus InstallNewVersion(
setup_path,
archive_path,
src_path,
temp_dir,
temp_path,
new_version,
current_version,
install_list.get());
Expand Down Expand Up @@ -425,7 +401,7 @@ InstallStatus InstallOrUpdateProduct(
}

installer_state.RemoveOldVersionDirectories(existing_version.get() ?
*existing_version.get() : new_version);
*existing_version.get() : new_version, install_temp_path);
}

return result;
Expand Down
42 changes: 23 additions & 19 deletions chrome/installer/setup/install_worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ void AddRegisterComDllWorkItemsForPackage(const InstallerState& installer_state,
// saved state instead of assuming it is the same as the registration list.
if (!com_dll_list.empty()) {
if (old_version) {
FilePath old_dll_path(installer_state.target_path().Append(
UTF8ToWide(old_version->GetString())));
FilePath old_dll_path(installer_state.target_path().AppendASCII(
old_version->GetString()));

installer::AddRegisterComDllWorkItems(old_dll_path,
com_dll_list,
Expand All @@ -90,8 +90,8 @@ void AddRegisterComDllWorkItemsForPackage(const InstallerState& installer_state,
work_item_list);
}

FilePath dll_path(installer_state.target_path().Append(
UTF8ToWide(new_version.GetString())));
FilePath dll_path(installer_state.target_path().AppendASCII(
new_version.GetString()));
installer::AddRegisterComDllWorkItems(dll_path,
com_dll_list,
installer_state.system_install(),
Expand Down Expand Up @@ -358,6 +358,7 @@ void AddGoogleUpdateWorkItems(const InstallerState& installer_state,
void AddDeleteUninstallShortcutsForMSIWorkItems(
const InstallerState& installer_state,
const Product& product,
const FilePath& temp_path,
WorkItemList* work_item_list) {
DCHECK(installer_state.is_msi())
<< "This must only be called for MSI installations!";
Expand Down Expand Up @@ -388,7 +389,7 @@ void AddDeleteUninstallShortcutsForMSIWorkItems(
VLOG(1) << "Deleting old uninstall shortcut (if present): "
<< uninstall_link.value();
WorkItem* delete_link = work_item_list->AddDeleteTreeWorkItem(
uninstall_link);
uninstall_link, temp_path);
delete_link->set_ignore_failure(true);
delete_link->set_log_message(
"Failed to delete old uninstall shortcut.");
Expand All @@ -409,6 +410,7 @@ bool AppendPostInstallTasks(const InstallerState& installer_state,
const FilePath& new_chrome_exe,
const Version* current_version,
const Version& new_version,
const FilePath& temp_path,
WorkItemList* post_install_task_list) {
DCHECK(post_install_task_list);

Expand Down Expand Up @@ -514,6 +516,7 @@ bool AppendPostInstallTasks(const InstallerState& installer_state,
// previous non-MSI installations for the same type of install (system or
// per user).
AddDeleteUninstallShortcutsForMSIWorkItems(installer_state, *product,
temp_path,
post_install_task_list);
}
if (installer_state.is_multi_install()) {
Expand All @@ -531,7 +534,7 @@ void AddInstallWorkItems(const InstallationState& original_state,
const FilePath& setup_path,
const FilePath& archive_path,
const FilePath& src_path,
const FilePath& temp_dir,
const FilePath& temp_path,
const Version& new_version,
scoped_ptr<Version>* current_version,
WorkItemList* install_list) {
Expand All @@ -540,55 +543,55 @@ void AddInstallWorkItems(const InstallationState& original_state,
const FilePath& target_path = installer_state.target_path();

// A temp directory that work items need and the actual install directory.
install_list->AddCreateDirWorkItem(temp_dir);
install_list->AddCreateDirWorkItem(temp_path);
install_list->AddCreateDirWorkItem(target_path);

// Delete any new_chrome.exe if present (we will end up creating a new one
// if required) and then copy chrome.exe
FilePath new_chrome_exe(
target_path.Append(installer::kChromeNewExe));

install_list->AddDeleteTreeWorkItem(new_chrome_exe);
install_list->AddDeleteTreeWorkItem(new_chrome_exe, temp_path);
install_list->AddCopyTreeWorkItem(
src_path.Append(installer::kChromeExe).value(),
target_path.Append(installer::kChromeExe).value(),
temp_dir.value(), WorkItem::NEW_NAME_IF_IN_USE, new_chrome_exe.value());
temp_path.value(), WorkItem::NEW_NAME_IF_IN_USE, new_chrome_exe.value());

// Extra executable for 64 bit systems.
if (Is64bit()) {
install_list->AddCopyTreeWorkItem(
src_path.Append(installer::kWowHelperExe).value(),
target_path.Append(installer::kWowHelperExe).value(),
temp_dir.value(), WorkItem::ALWAYS);
temp_path.value(), WorkItem::ALWAYS);
}

// If it is system level install copy the version folder (since we want to
// take the permissions of %ProgramFiles% folder) otherwise just move it.
if (installer_state.system_install()) {
install_list->AddCopyTreeWorkItem(
src_path.Append(UTF8ToWide(new_version.GetString())).value(),
target_path.Append(UTF8ToWide(new_version.GetString())).value(),
temp_dir.value(), WorkItem::ALWAYS);
src_path.AppendASCII(new_version.GetString()).value(),
target_path.AppendASCII(new_version.GetString()).value(),
temp_path.value(), WorkItem::ALWAYS);
} else {
install_list->AddMoveTreeWorkItem(
src_path.Append(UTF8ToWide(new_version.GetString())).value(),
target_path.Append(UTF8ToWide(new_version.GetString())).value(),
temp_dir.value());
src_path.AppendASCII(new_version.GetString()).value(),
target_path.AppendASCII(new_version.GetString()).value(),
temp_path.value());
}

// Copy the default Dictionaries only if the folder doesn't exist already.
install_list->AddCopyTreeWorkItem(
src_path.Append(installer::kDictionaries).value(),
target_path.Append(installer::kDictionaries).value(),
temp_dir.value(), WorkItem::IF_NOT_PRESENT);
temp_path.value(), WorkItem::IF_NOT_PRESENT);

// Delete any old_chrome.exe if present.
install_list->AddDeleteTreeWorkItem(
target_path.Append(installer::kChromeOldExe));
target_path.Append(installer::kChromeOldExe), temp_path);

// Copy installer in install directory and
// add shortcut in Control Panel->Add/Remove Programs.
AddInstallerCopyTasks(installer_state, setup_path, archive_path, temp_dir,
AddInstallerCopyTasks(installer_state, setup_path, archive_path, temp_path,
new_version, install_list);

const HKEY root = installer_state.root_key();
Expand Down Expand Up @@ -623,6 +626,7 @@ void AddInstallWorkItems(const InstallationState& original_state,
new_chrome_exe,
current_version->get(),
new_version,
temp_path,
install_list);
}

Expand Down
7 changes: 4 additions & 3 deletions chrome/installer/setup/install_worker.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ bool AppendPostInstallTasks(const InstallerState& installer_state,
const FilePath& new_chrome_exe,
const Version* current_version,
const Version& new_version,
const FilePath& temp_path,
WorkItemList* post_install_task_list);

// Builds the complete WorkItemList used to build the set of installation steps
Expand All @@ -62,14 +63,14 @@ bool AppendPostInstallTasks(const InstallerState& installer_state,
// to Chrome install folder after install is complete
// src_path: the path that contains a complete and unpacked Chrome package
// to be installed.
// temp_dir: the path of working directory used during installation. This path
// does not need to exist.
// temp_path: the path of working directory used during installation. This path
// does not need to exist.
void AddInstallWorkItems(const InstallationState& original_state,
const InstallerState& installer_state,
const FilePath& setup_path,
const FilePath& archive_path,
const FilePath& src_path,
const FilePath& temp_dir,
const FilePath& temp_path,
const Version& new_version,
scoped_ptr<Version>* current_version,
WorkItemList* install_list);
Expand Down
Loading

0 comments on commit bdddb67

Please sign in to comment.