diff options
Diffstat (limited to 'chrome/installer')
-rw-r--r-- | chrome/installer/setup/install.cc | 13 | ||||
-rw-r--r-- | chrome/installer/setup/setup_main.cc | 7 | ||||
-rw-r--r-- | chrome/installer/util/copy_tree_work_item.cc | 53 | ||||
-rw-r--r-- | chrome/installer/util/copy_tree_work_item.h | 14 | ||||
-rw-r--r-- | chrome/installer/util/copy_tree_work_item_unittest.cc | 8 | ||||
-rw-r--r-- | chrome/installer/util/delete_after_reboot_helper.cc | 2 | ||||
-rw-r--r-- | chrome/installer/util/delete_tree_work_item.cc | 19 | ||||
-rw-r--r-- | chrome/installer/util/delete_tree_work_item.h | 12 | ||||
-rw-r--r-- | chrome/installer/util/move_tree_work_item.cc | 31 | ||||
-rw-r--r-- | chrome/installer/util/move_tree_work_item.h | 8 | ||||
-rw-r--r-- | chrome/installer/util/shell_util.cc | 4 |
11 files changed, 83 insertions, 88 deletions
diff --git a/chrome/installer/setup/install.cc b/chrome/installer/setup/install.cc index ce211fd1..1bc8164 100644 --- a/chrome/installer/setup/install.cc +++ b/chrome/installer/setup/install.cc @@ -157,13 +157,12 @@ void AddUninstallShortcutWorkItems(HKEY reg_root, // only on the first install of Chrome. void CopyPreferenceFileForFirstRun(bool system_level, const std::wstring& prefs_source_path) { - FilePath prefs_dest_path = FilePath::FromWStringHack( + std::wstring prefs_dest_path( installer::GetChromeInstallPath(system_level)); - prefs_dest_path = prefs_dest_path.Append(installer_util::kDefaultMasterPrefs); - if (!file_util::CopyFile(FilePath::FromWStringHack(prefs_source_path), - prefs_dest_path)) { + file_util::AppendToPath(&prefs_dest_path, + installer_util::kDefaultMasterPrefs); + if (!file_util::CopyFile(prefs_source_path, prefs_dest_path)) LOG(INFO) << "Failed to copy master preferences."; - } } // This method creates Chrome shortcuts in Start->Programs for all users or @@ -305,7 +304,7 @@ bool DoPostInstallTasks(HKEY reg_root, BrowserDistribution* dist = BrowserDistribution::GetDistribution(); std::wstring version_key = dist->GetVersionKey(); - if (file_util::PathExists(FilePath::FromWStringHack(new_chrome_exe))) { + if (file_util::PathExists(new_chrome_exe)) { // Looks like this was in use update. So make sure we update the 'opv' key // with the current version that is active and 'cmd' key with the rename // command to run. @@ -493,7 +492,7 @@ bool InstallNewVersion(const std::wstring& exe_path, installer_util::kChromeNewExe); BrowserDistribution* dist = BrowserDistribution::GetDistribution(); RegKey chrome_key(reg_root, dist->GetVersionKey().c_str(), KEY_READ); - if (file_util::PathExists(FilePath::FromWStringHack(new_chrome_exe))) + if (file_util::PathExists(new_chrome_exe)) chrome_key.ReadValue(google_update::kRegOldVersionField, current_version); if (current_version->empty()) chrome_key.ReadValue(google_update::kRegVersionField, current_version); diff --git a/chrome/installer/setup/setup_main.cc b/chrome/installer/setup/setup_main.cc index f20e307..3b5377d 100644 --- a/chrome/installer/setup/setup_main.cc +++ b/chrome/installer/setup/setup_main.cc @@ -67,7 +67,7 @@ DWORD UnPackArchive(const std::wstring& archive, bool system_install, // Check if this is differential update and if it is, patch it to the // installer archive that should already be on the machine. We assume // it is a differential installer if chrome.7z is not found. - if (!file_util::PathExists(FilePath::FromWStringHack(uncompressed_archive))) { + if (!file_util::PathExists(uncompressed_archive)) { incremental_install = true; LOG(INFO) << "Differential patch found. Applying to existing archive."; if (!installed_version) { @@ -163,11 +163,10 @@ bool CheckPreInstallConditions(const installer::Version* installed_version, // either does not exist or can be deleted (i.e. is not locked by some other // process). if (!installed_version) { - FilePath install_path = FilePath::FromWStringHack( - installer::GetChromeInstallPath(system_install)); + std::wstring install_path(installer::GetChromeInstallPath(system_install)); if (file_util::PathExists(install_path) && !file_util::Delete(install_path, true)) { - LOG(ERROR) << "Installation directory " << install_path.value() + LOG(ERROR) << "Installation directory " << install_path << " exists and can not be deleted."; status = installer_util::INSTALL_DIR_IN_USE; int str_id = IDS_INSTALL_DIR_IN_USE_BASE; diff --git a/chrome/installer/util/copy_tree_work_item.cc b/chrome/installer/util/copy_tree_work_item.cc index 22007990..ffb3d34 100644 --- a/chrome/installer/util/copy_tree_work_item.cc +++ b/chrome/installer/util/copy_tree_work_item.cc @@ -31,7 +31,7 @@ CopyTreeWorkItem::CopyTreeWorkItem(const std::wstring& source_path, bool CopyTreeWorkItem::Do() { if (!file_util::PathExists(source_path_)) { - LOG(ERROR) << source_path_.value() << " does not exist"; + LOG(ERROR) << source_path_ << " does not exist"; return false; } @@ -39,29 +39,29 @@ bool CopyTreeWorkItem::Do() { // handle overwrite_option_ = IF_DIFFERENT case. if ((dest_exist) && (overwrite_option_ == WorkItem::IF_DIFFERENT) && // only for single file - (!file_util::DirectoryExists(source_path_)) && - (!file_util::DirectoryExists(dest_path_)) && + (!PathIsDirectory(source_path_.c_str())) && + (!PathIsDirectory(dest_path_.c_str())) && (file_util::ContentsEqual(source_path_, dest_path_))) { - LOG(INFO) << "Source file " << source_path_.value() - << " and destination file " << dest_path_.value() + LOG(INFO) << "Source file " << source_path_ + << " and destination file " << dest_path_ << " are exactly same. Returning true."; return true; } else if ((dest_exist) && (overwrite_option_ == WorkItem::NEW_NAME_IF_IN_USE) && - (!file_util::DirectoryExists(source_path_)) && - (!file_util::DirectoryExists(dest_path_)) && + (!PathIsDirectory(source_path_.c_str())) && + (!PathIsDirectory(dest_path_.c_str())) && (IsFileInUse(dest_path_))) { // handle overwrite_option_ = NEW_NAME_IF_IN_USE case. if (alternative_path_.empty() || file_util::PathExists(alternative_path_) || !file_util::CopyFile(source_path_, alternative_path_)) { - LOG(ERROR) << "failed to copy " << source_path_.value() << - " to " << alternative_path_.value(); + LOG(ERROR) << "failed to copy " << source_path_ << + " to " << alternative_path_; return false; } else { copied_to_alternate_path_ = true; - LOG(INFO) << "Copied source file " << source_path_.value() - << " to alternative path " << alternative_path_.value(); + LOG(INFO) << "Copied source file " << source_path_ + << " to alternative path " << alternative_path_; return true; } } else if ((dest_exist) && @@ -77,11 +77,10 @@ bool CopyTreeWorkItem::Do() { if (file_util::Move(dest_path_, backup_path_)) { moved_to_backup_ = true; - LOG(INFO) << "Moved destination " << dest_path_.value() << - " to backup path " << backup_path_.value(); + LOG(INFO) << "Moved destination " << dest_path_ + << " to backup path " << backup_path_; } else { - LOG(ERROR) << "failed moving " << dest_path_.value() << " to " << - backup_path_.value(); + LOG(ERROR) << "failed moving " << dest_path_ << " to " << backup_path_; return false; } } @@ -89,11 +88,10 @@ bool CopyTreeWorkItem::Do() { // In all cases that reach here, copy source to destination. if (file_util::CopyDirectory(source_path_, dest_path_, true)) { copied_to_dest_path_ = true; - LOG(INFO) << "Copied source " << source_path_.value() - << " to destination " << dest_path_.value(); + LOG(INFO) << "Copied source " << source_path_ + << " to destination " << dest_path_; } else { - LOG(ERROR) << "failed copy " << source_path_.value() << - " to " << dest_path_.value(); + LOG(ERROR) << "failed copy " << source_path_ << " to " << dest_path_; return false; } @@ -107,23 +105,22 @@ void CopyTreeWorkItem::Rollback() { // Delete here. For now we just log the error and continue with the // rest of rollback operation. if (copied_to_dest_path_ && !file_util::Delete(dest_path_, true)) { - LOG(ERROR) << "Can not delete " << dest_path_.value(); + LOG(ERROR) << "Can not delete " << dest_path_; } if (moved_to_backup_ && !file_util::Move(backup_path_, dest_path_)) { - LOG(ERROR) << "failed move " << backup_path_.value() << " to " << - dest_path_.value(); + LOG(ERROR) << "failed move " << backup_path_ << " to " << dest_path_; } if (copied_to_alternate_path_ && !file_util::Delete(alternative_path_, true)) { - LOG(ERROR) << "Can not delete " << alternative_path_.value(); + LOG(ERROR) << "Can not delete " << alternative_path_; } } -bool CopyTreeWorkItem::IsFileInUse(const FilePath& path) { +bool CopyTreeWorkItem::IsFileInUse(const std::wstring& path) { if (!file_util::PathExists(path)) return false; - HANDLE handle = ::CreateFile(path.value().c_str(), FILE_ALL_ACCESS, + HANDLE handle = ::CreateFile(path.c_str(), FILE_ALL_ACCESS, NULL, NULL, OPEN_EXISTING, NULL, NULL); if (handle == INVALID_HANDLE_VALUE) return true; @@ -133,14 +130,16 @@ bool CopyTreeWorkItem::IsFileInUse(const FilePath& path) { } bool CopyTreeWorkItem::GetBackupPath() { - backup_path_ = temp_dir_.Append(dest_path_.BaseName()); + std::wstring file_name = file_util::GetFilenameFromPath(dest_path_); + backup_path_.assign(temp_dir_); + file_util::AppendToPath(&backup_path_, file_name); if (file_util::PathExists(backup_path_)) { // Ideally we should not fail immediately. Instead we could try some // random paths under temp_dir_ until we reach certain limit. // For now our caller always provides a good temporary directory so // we don't bother. - LOG(ERROR) << "backup path " << backup_path_.value() << " already exists"; + LOG(ERROR) << "backup path " << backup_path_ << " already exists"; return false; } diff --git a/chrome/installer/util/copy_tree_work_item.h b/chrome/installer/util/copy_tree_work_item.h index b899324..9fa1d96 100644 --- a/chrome/installer/util/copy_tree_work_item.h +++ b/chrome/installer/util/copy_tree_work_item.h @@ -7,8 +7,6 @@ #include <string> #include <windows.h> - -#include "base/file_path.h" #include "chrome/installer/util/work_item.h" // A WorkItem subclass that recursively copies a file system hierarchy from @@ -42,20 +40,20 @@ class CopyTreeWorkItem : public WorkItem { const std::wstring& alternative_path); // Checks if the path specified is in use (and hence can not be deleted) - bool IsFileInUse(const FilePath& path); + bool IsFileInUse(const std::wstring& path); // Get a backup path that can keep the original files under dest_path_, // and set backup_path_ with the result. bool GetBackupPath(); // Source path to copy files from. - FilePath source_path_; + std::wstring source_path_; // Destination path to copy files to. - FilePath dest_path_; + std::wstring dest_path_; // Temporary directory that can be used. - FilePath temp_dir_; + std::wstring temp_dir_; // Controls the behavior for overwriting. CopyOverWriteOption overwrite_option_; @@ -63,7 +61,7 @@ class CopyTreeWorkItem : public WorkItem { // If overwrite_option_ = NEW_NAME_IF_IN_USE, this variables stores the path // to be used if the file is in use and hence we want to copy it to a // different path. - FilePath alternative_path_; + std::wstring alternative_path_; // Whether the source was copied to dest_path_ bool copied_to_dest_path_; @@ -78,7 +76,7 @@ class CopyTreeWorkItem : public WorkItem { // The full path in temporary directory that the original dest_path_ has // been moved to. - FilePath backup_path_; + std::wstring backup_path_; }; #endif // CHROME_INSTALLER_UTIL_COPY_TREE_WORK_ITEM_H_ diff --git a/chrome/installer/util/copy_tree_work_item_unittest.cc b/chrome/installer/util/copy_tree_work_item_unittest.cc index bc187e61..c8cae21 100644 --- a/chrome/installer/util/copy_tree_work_item_unittest.cc +++ b/chrome/installer/util/copy_tree_work_item_unittest.cc @@ -61,11 +61,11 @@ namespace { file.close(); } - bool IsFileInUse(const FilePath& path) { + bool IsFileInUse(const std::wstring& path) { if (!file_util::PathExists(path)) return false; - HANDLE handle = ::CreateFile(path.value().c_str(), FILE_ALL_ACCESS, + HANDLE handle = ::CreateFile(path.c_str(), FILE_ALL_ACCESS, NULL, NULL, OPEN_EXISTING, NULL, NULL); if (handle == INVALID_HANDLE_VALUE) return true; @@ -478,10 +478,10 @@ TEST_F(CopyTreeWorkItemTest, NewNameAndCopyTest) { file_name_from.ToWStringHack(), file_name_to.ToWStringHack(), temp_dir_.ToWStringHack(), WorkItem::NEW_NAME_IF_IN_USE, alternate_to.ToWStringHack())); - if (IsFileInUse(file_name_to)) + if (IsFileInUse(file_name_to.value())) PlatformThread::Sleep(2000); // If file is still in use, the rest of the test will fail. - ASSERT_FALSE(IsFileInUse(file_name_to)); + ASSERT_FALSE(IsFileInUse(file_name_to.value())); EXPECT_TRUE(work_item->Do()); EXPECT_TRUE(file_util::PathExists(file_name_from)); diff --git a/chrome/installer/util/delete_after_reboot_helper.cc b/chrome/installer/util/delete_after_reboot_helper.cc index 1bc322c..a54acb3 100644 --- a/chrome/installer/util/delete_after_reboot_helper.cc +++ b/chrome/installer/util/delete_after_reboot_helper.cc @@ -64,7 +64,7 @@ bool ScheduleFileSystemEntityForDeletion(const wchar_t* path) { } DWORD flags = MOVEFILE_DELAY_UNTIL_REBOOT; - if (!file_util::DirectoryExists(FilePath::FromWStringHack(path))) { + if (!file_util::DirectoryExists(path)) { // This flag valid only for files flags |= MOVEFILE_REPLACE_EXISTING; } diff --git a/chrome/installer/util/delete_tree_work_item.cc b/chrome/installer/util/delete_tree_work_item.cc index 3102485..8e5610a 100644 --- a/chrome/installer/util/delete_tree_work_item.cc +++ b/chrome/installer/util/delete_tree_work_item.cc @@ -7,11 +7,11 @@ #include "chrome/installer/util/delete_tree_work_item.h" DeleteTreeWorkItem::~DeleteTreeWorkItem() { - FilePath tmp_dir = backup_path_.DirName(); + std::wstring tmp_dir = file_util::GetDirectoryFromPath(backup_path_); if (file_util::PathExists(tmp_dir)) { file_util::Delete(tmp_dir, true); } - tmp_dir = key_backup_path_.DirName(); + tmp_dir = file_util::GetDirectoryFromPath(key_backup_path_); if (file_util::PathExists(tmp_dir)) { file_util::Delete(tmp_dir, true); } @@ -30,8 +30,8 @@ bool DeleteTreeWorkItem::Do() { if (!GetBackupPath(key_path_, &key_backup_path_) || !file_util::CopyDirectory(key_path_, key_backup_path_, true) || !file_util::Delete(key_path_, true)) { - LOG(ERROR) << "can not delete " << key_path_.value() - << " OR copy it to backup path " << key_backup_path_.value(); + LOG(ERROR) << "can not delete " << key_path_ + << " OR copy it to backup path " << key_backup_path_; return false; } } @@ -40,8 +40,8 @@ bool DeleteTreeWorkItem::Do() { if (!GetBackupPath(root_path_, &backup_path_) || !file_util::CopyDirectory(root_path_, backup_path_, true) || !file_util::Delete(root_path_, true)) { - LOG(ERROR) << "can not delete " << root_path_.value() - << " OR copy it to backup path " << backup_path_.value(); + LOG(ERROR) << "can not delete " << root_path_ + << " OR copy it to backup path " << backup_path_; return false; } } @@ -58,14 +58,15 @@ void DeleteTreeWorkItem::Rollback() { } } -bool DeleteTreeWorkItem::GetBackupPath(const FilePath& for_path, - FilePath* backup_path) { +bool DeleteTreeWorkItem::GetBackupPath(const std::wstring& for_path, + std::wstring* backup_path) { if (!file_util::CreateNewTempDirectory(L"", backup_path)) { // We assume that CreateNewTempDirectory() is doing its job well. LOG(ERROR) << "Couldn't get backup path for delete."; return false; } + std::wstring file_name = file_util::GetFilenameFromPath(for_path); + file_util::AppendToPath(backup_path, file_name); - *backup_path = backup_path->Append(for_path.BaseName()); return true; } diff --git a/chrome/installer/util/delete_tree_work_item.h b/chrome/installer/util/delete_tree_work_item.h index b5bcb50..cf7b4be 100644 --- a/chrome/installer/util/delete_tree_work_item.h +++ b/chrome/installer/util/delete_tree_work_item.h @@ -7,8 +7,6 @@ #include <string> #include <windows.h> - -#include "base/file_path.h" #include "chrome/installer/util/work_item.h" // A WorkItem subclass that recursively deletes a file system hierarchy at the @@ -28,25 +26,25 @@ class DeleteTreeWorkItem : public WorkItem { friend class WorkItem; // Get a backup path that can keep root_path_ or key_path_ - bool GetBackupPath(const FilePath& for_path, FilePath* backup_path); + bool GetBackupPath(const std::wstring& for_path, std::wstring* backup_path); DeleteTreeWorkItem(const std::wstring& root_path, const std::wstring& key_path); // Root path to delete. - FilePath root_path_; + std::wstring root_path_; // Path to the key file. If the key file is specified, deletion will be // performed only if the key file is not in use. - FilePath key_path_; + std::wstring key_path_; // The full path in temporary directory that the original root_path_ has // been moved to. - FilePath backup_path_; + std::wstring backup_path_; // The full path in temporary directory that the original key_path_ has // been moved to. - FilePath key_backup_path_; + std::wstring key_backup_path_; }; #endif // CHROME_INSTALLER_UTIL_DELETE_TREE_WORK_ITEM_H_ diff --git a/chrome/installer/util/move_tree_work_item.cc b/chrome/installer/util/move_tree_work_item.cc index 45c03b2..b90665e 100644 --- a/chrome/installer/util/move_tree_work_item.cc +++ b/chrome/installer/util/move_tree_work_item.cc @@ -26,26 +26,30 @@ MoveTreeWorkItem::MoveTreeWorkItem(const std::wstring& source_path, bool MoveTreeWorkItem::Do() { if (!file_util::PathExists(source_path_)) { - LOG(ERROR) << source_path_.value() << " does not exist"; + LOG(ERROR) << source_path_ << " does not exist"; return false; } + FilePath backup_path; + // If dest_path_ exists, move destination to a backup path. if (file_util::PathExists(dest_path_)) { // Generate a backup path that can keep the original files under dest_path_. if (!file_util::CreateTemporaryFileInDir(FilePath(temp_dir_), - &backup_path_)) { - LOG(ERROR) << "Failed to get backup path in folder " << temp_dir_.value(); + &backup_path)) { + LOG(ERROR) << "Failed to get backup path in folder " << temp_dir_; return false; } + backup_path_ = backup_path.value(); + if (file_util::Move(dest_path_, backup_path_)) { moved_to_backup_ = true; - LOG(INFO) << "Moved destination " << dest_path_.value() - << " to backup path " << backup_path_.value(); + LOG(INFO) << "Moved destination " << dest_path_ + << " to backup path " << backup_path_; } else { - LOG(ERROR) << "failed moving " << dest_path_.value() - << " to " << backup_path_.value(); + LOG(ERROR) << "failed moving " << dest_path_ + << " to " << backup_path_; return false; } } @@ -53,11 +57,10 @@ bool MoveTreeWorkItem::Do() { // Now move source to destination. if (file_util::Move(source_path_, dest_path_)) { moved_to_dest_path_ = true; - LOG(INFO) << "Moved source " << source_path_.value() - << " to destination " << dest_path_.value(); + LOG(INFO) << "Moved source " << source_path_ + << " to destination " << dest_path_; } else { - LOG(ERROR) << "failed move " << source_path_.value() << " to " << - dest_path_.value(); + LOG(ERROR) << "failed move " << source_path_ << " to " << dest_path_; return false; } @@ -66,10 +69,8 @@ bool MoveTreeWorkItem::Do() { void MoveTreeWorkItem::Rollback() { if (moved_to_dest_path_ && !file_util::Move(dest_path_, source_path_)) - LOG(ERROR) << "Can not move " << dest_path_.value() << - " to " << source_path_.value(); + LOG(ERROR) << "Can not move " << dest_path_ << " to " << source_path_; if (moved_to_backup_ && !file_util::Move(backup_path_, dest_path_)) - LOG(ERROR) << "failed move " << backup_path_.value() << - " to " << dest_path_.value(); + LOG(ERROR) << "failed move " << backup_path_ << " to " << dest_path_; } diff --git a/chrome/installer/util/move_tree_work_item.h b/chrome/installer/util/move_tree_work_item.h index cfa86c4..95964fb 100644 --- a/chrome/installer/util/move_tree_work_item.h +++ b/chrome/installer/util/move_tree_work_item.h @@ -38,17 +38,17 @@ class MoveTreeWorkItem : public WorkItem { const std::wstring& temp_dir); // Source path to move files from. - FilePath source_path_; + std::wstring source_path_; // Destination path to move files to. - FilePath dest_path_; + std::wstring dest_path_; // Temporary directory to backup dest_path_ (if it already exists). - FilePath temp_dir_; + std::wstring temp_dir_; // The full path in temp_dir_ where the original dest_path_ has // been moved to. - FilePath backup_path_; + std::wstring backup_path_; // Whether the source was moved to dest_path_ bool moved_to_dest_path_; diff --git a/chrome/installer/util/shell_util.cc b/chrome/installer/util/shell_util.cc index 8e00ba2..86e588b 100644 --- a/chrome/installer/util/shell_util.cc +++ b/chrome/installer/util/shell_util.cc @@ -295,7 +295,7 @@ bool ElevateAndRegisterChrome(const std::wstring& chrome_exe, const std::wstring& suffix) { std::wstring exe_path(file_util::GetDirectoryFromPath(chrome_exe)); file_util::AppendToPath(&exe_path, installer_util::kSetupExe); - if (!file_util::PathExists(FilePath::FromWStringHack(exe_path))) { + if (!file_util::PathExists(exe_path)) { BrowserDistribution* dist = BrowserDistribution::GetDistribution(); HKEY reg_root = InstallUtil::IsPerUserInstall(chrome_exe.c_str()) ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; @@ -305,7 +305,7 @@ bool ElevateAndRegisterChrome(const std::wstring& chrome_exe, command_line.ParseFromString(exe_path); exe_path = command_line.program(); } - if (file_util::PathExists(FilePath::FromWStringHack(exe_path))) { + if (file_util::PathExists(exe_path)) { std::wstring params(L"--"); params.append(installer_util::switches::kRegisterChromeBrowser); params.append(L"=\"" + chrome_exe + L"\""); |