diff options
author | kuchhal@chromium.org <kuchhal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-23 18:10:13 +0000 |
---|---|---|
committer | kuchhal@chromium.org <kuchhal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-23 18:10:13 +0000 |
commit | d54030f704e1050a052a56515a007e1787793037 (patch) | |
tree | 9ecc9b80eee4891ea599fd44521e81029e609e88 /chrome/installer/util | |
parent | 7f1f8e39214e49ea62c3038f886b4df540aadb42 (diff) | |
download | chromium_src-d54030f704e1050a052a56515a007e1787793037.zip chromium_src-d54030f704e1050a052a56515a007e1787793037.tar.gz chromium_src-d54030f704e1050a052a56515a007e1787793037.tar.bz2 |
installer: clean up to use FilePath instead of std::wstring.
BUG=24672
TEST=installer_util_unittests and setup_unittests
Review URL: http://codereview.chromium.org/385129
Patch from Thiago Farina <thiago.farina@gmail.com>.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@32811 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/installer/util')
21 files changed, 148 insertions, 165 deletions
diff --git a/chrome/installer/util/browser_distribution.cc b/chrome/installer/util/browser_distribution.cc index fe9884f..e5f1af9 100644 --- a/chrome/installer/util/browser_distribution.cc +++ b/chrome/installer/util/browser_distribution.cc @@ -40,7 +40,7 @@ BrowserDistribution* BrowserDistribution::GetDistribution(bool chrome_frame) { } void BrowserDistribution::DoPostUninstallOperations( - const installer::Version& version, const std::wstring& local_data_path, + const installer::Version& version, const FilePath& local_data_path, const std::wstring& distribution_data) { } diff --git a/chrome/installer/util/browser_distribution.h b/chrome/installer/util/browser_distribution.h index 8948bdc..2ffb74c 100644 --- a/chrome/installer/util/browser_distribution.h +++ b/chrome/installer/util/browser_distribution.h @@ -11,6 +11,7 @@ #include "chrome/installer/util/util_constants.h" #include "chrome/installer/util/version.h" +class FilePath; class RegKey; class BrowserDistribution { @@ -20,7 +21,7 @@ class BrowserDistribution { static BrowserDistribution* GetDistribution(); virtual void DoPostUninstallOperations(const installer::Version& version, - const std::wstring& local_data_path, + const FilePath& local_data_path, const std::wstring& distribution_data); virtual std::wstring GetAppGuid(); diff --git a/chrome/installer/util/copy_tree_work_item.cc b/chrome/installer/util/copy_tree_work_item.cc index 22007990..d161ed9 100644 --- a/chrome/installer/util/copy_tree_work_item.cc +++ b/chrome/installer/util/copy_tree_work_item.cc @@ -14,11 +14,11 @@ CopyTreeWorkItem::~CopyTreeWorkItem() { } } -CopyTreeWorkItem::CopyTreeWorkItem(const std::wstring& source_path, - const std::wstring& dest_path, - const std::wstring& temp_dir, +CopyTreeWorkItem::CopyTreeWorkItem(const FilePath& source_path, + const FilePath& dest_path, + const FilePath& temp_dir, CopyOverWriteOption overwrite_option, - const std::wstring& alternative_path) + const FilePath& alternative_path) : source_path_(source_path), dest_path_(dest_path), temp_dir_(temp_dir), diff --git a/chrome/installer/util/copy_tree_work_item.h b/chrome/installer/util/copy_tree_work_item.h index b899324..c1478922 100644 --- a/chrome/installer/util/copy_tree_work_item.h +++ b/chrome/installer/util/copy_tree_work_item.h @@ -35,11 +35,11 @@ class CopyTreeWorkItem : public WorkItem { // Notes on temp_path: to facilitate rollback, the caller needs to supply // a temporary directory to save the original files if they exist under // dest_path. - CopyTreeWorkItem(const std::wstring& source_path, - const std::wstring& dest_path, - const std::wstring& temp_dir, + CopyTreeWorkItem(const FilePath& source_path, + const FilePath& dest_path, + const FilePath& temp_dir, CopyOverWriteOption overwrite_option, - const std::wstring& alternative_path); + const FilePath& alternative_path); // Checks if the path specified is in use (and hence can not be deleted) bool IsFileInUse(const FilePath& path); diff --git a/chrome/installer/util/copy_tree_work_item_unittest.cc b/chrome/installer/util/copy_tree_work_item_unittest.cc index bc187e61..a9aa986 100644 --- a/chrome/installer/util/copy_tree_work_item_unittest.cc +++ b/chrome/installer/util/copy_tree_work_item_unittest.cc @@ -108,9 +108,9 @@ TEST_F(CopyTreeWorkItemTest, CopyFile) { // test Do() scoped_ptr<CopyTreeWorkItem> work_item( - WorkItem::CreateCopyTreeWorkItem(file_name_from.ToWStringHack(), - file_name_to.ToWStringHack(), - temp_dir_.ToWStringHack(), + WorkItem::CreateCopyTreeWorkItem(file_name_from, + file_name_to, + temp_dir_, WorkItem::ALWAYS)); EXPECT_TRUE(work_item->Do()); @@ -149,9 +149,9 @@ TEST_F(CopyTreeWorkItemTest, CopyFileOverwrite) { // test Do() with always_overwrite being true. scoped_ptr<CopyTreeWorkItem> work_item( - WorkItem::CreateCopyTreeWorkItem(file_name_from.ToWStringHack(), - file_name_to.ToWStringHack(), - temp_dir_.ToWStringHack(), + WorkItem::CreateCopyTreeWorkItem(file_name_from, + file_name_to, + temp_dir_, WorkItem::ALWAYS)); EXPECT_TRUE(work_item->Do()); @@ -172,9 +172,9 @@ TEST_F(CopyTreeWorkItemTest, CopyFileOverwrite) { // test Do() with always_overwrite being false. // the file is still overwritten since the content is different. work_item.reset( - WorkItem::CreateCopyTreeWorkItem(file_name_from.ToWStringHack(), - file_name_to.ToWStringHack(), - temp_dir_.ToWStringHack(), + WorkItem::CreateCopyTreeWorkItem(file_name_from, + file_name_to, + temp_dir_, WorkItem::IF_DIFFERENT)); EXPECT_TRUE(work_item->Do()); @@ -221,9 +221,9 @@ TEST_F(CopyTreeWorkItemTest, CopyFileSameContent) { // test Do() with always_overwrite being true. scoped_ptr<CopyTreeWorkItem> work_item( - WorkItem::CreateCopyTreeWorkItem(file_name_from.ToWStringHack(), - file_name_to.ToWStringHack(), - temp_dir_.ToWStringHack(), + WorkItem::CreateCopyTreeWorkItem(file_name_from, + file_name_to, + temp_dir_, WorkItem::ALWAYS)); EXPECT_TRUE(work_item->Do()); @@ -249,9 +249,9 @@ TEST_F(CopyTreeWorkItemTest, CopyFileSameContent) { // test Do() with always_overwrite being false. nothing should change. work_item.reset( - WorkItem::CreateCopyTreeWorkItem(file_name_from.ToWStringHack(), - file_name_to.ToWStringHack(), - temp_dir_.ToWStringHack(), + WorkItem::CreateCopyTreeWorkItem(file_name_from, + file_name_to, + temp_dir_, WorkItem::IF_DIFFERENT)); EXPECT_TRUE(work_item->Do()); @@ -300,9 +300,9 @@ TEST_F(CopyTreeWorkItemTest, CopyFileAndCleanup) { { // test Do(). scoped_ptr<CopyTreeWorkItem> work_item( - WorkItem::CreateCopyTreeWorkItem(file_name_from.ToWStringHack(), - file_name_to.ToWStringHack(), - temp_dir_.ToWStringHack(), + WorkItem::CreateCopyTreeWorkItem(file_name_from, + file_name_to, + temp_dir_, WorkItem::IF_DIFFERENT)); EXPECT_TRUE(work_item->Do()); @@ -362,10 +362,8 @@ TEST_F(CopyTreeWorkItemTest, CopyFileInUse) { // test Do(). scoped_ptr<CopyTreeWorkItem> work_item( - WorkItem::CreateCopyTreeWorkItem(file_name_from.ToWStringHack(), - file_name_to.ToWStringHack(), - temp_dir_.ToWStringHack(), - WorkItem::IF_DIFFERENT)); + WorkItem::CreateCopyTreeWorkItem(file_name_from, file_name_to, temp_dir_, + WorkItem::IF_DIFFERENT)); EXPECT_TRUE(work_item->Do()); @@ -440,11 +438,8 @@ TEST_F(CopyTreeWorkItemTest, NewNameAndCopyTest) { // test Do(). scoped_ptr<CopyTreeWorkItem> work_item( - WorkItem::CreateCopyTreeWorkItem(file_name_from.ToWStringHack(), - file_name_to.ToWStringHack(), - temp_dir_.ToWStringHack(), - WorkItem::NEW_NAME_IF_IN_USE, - alternate_to.ToWStringHack())); + WorkItem::CreateCopyTreeWorkItem(file_name_from, file_name_to, temp_dir_, + WorkItem::NEW_NAME_IF_IN_USE, alternate_to)); EXPECT_TRUE(work_item->Do()); @@ -474,10 +469,11 @@ TEST_F(CopyTreeWorkItemTest, NewNameAndCopyTest) { CloseHandle(pi.hThread); // Now the process has terminated, lets try overwriting the file again - work_item.reset(WorkItem::CreateCopyTreeWorkItem( - file_name_from.ToWStringHack(), file_name_to.ToWStringHack(), - temp_dir_.ToWStringHack(), WorkItem::NEW_NAME_IF_IN_USE, - alternate_to.ToWStringHack())); + work_item.reset(WorkItem::CreateCopyTreeWorkItem(file_name_from, + file_name_to, + temp_dir_, + WorkItem::NEW_NAME_IF_IN_USE, + alternate_to)); if (IsFileInUse(file_name_to)) PlatformThread::Sleep(2000); // If file is still in use, the rest of the test will fail. @@ -536,9 +532,8 @@ TEST_F(CopyTreeWorkItemTest, IfNotPresentTest) { // test Do(). scoped_ptr<CopyTreeWorkItem> work_item( - WorkItem::CreateCopyTreeWorkItem(file_name_from.ToWStringHack(), - file_name_to.ToWStringHack(), temp_dir_.ToWStringHack(), - WorkItem::IF_NOT_PRESENT, L"")); + WorkItem::CreateCopyTreeWorkItem(file_name_from, file_name_to, temp_dir_, + WorkItem::IF_NOT_PRESENT, FilePath())); EXPECT_TRUE(work_item->Do()); // verify that the source, destination have not changed and backup path @@ -562,9 +557,8 @@ TEST_F(CopyTreeWorkItemTest, IfNotPresentTest) { // Now delete the destination and try copying the file again. file_util::Delete(file_name_to, true); - work_item.reset(WorkItem::CreateCopyTreeWorkItem( - file_name_from.ToWStringHack(), file_name_to.ToWStringHack(), - temp_dir_.ToWStringHack(), WorkItem::IF_NOT_PRESENT, L"")); + work_item.reset(WorkItem::CreateCopyTreeWorkItem(file_name_from, file_name_to, + temp_dir_, WorkItem::IF_NOT_PRESENT, FilePath())); EXPECT_TRUE(work_item->Do()); // verify that the source, destination are the same and backup path @@ -627,10 +621,8 @@ TEST_F(CopyTreeWorkItemTest, CopyFileInUseAndCleanup) { // test Do(). { scoped_ptr<CopyTreeWorkItem> work_item( - WorkItem::CreateCopyTreeWorkItem(file_name_from.ToWStringHack(), - file_name_to.ToWStringHack(), - temp_dir_.ToWStringHack(), - WorkItem::IF_DIFFERENT)); + WorkItem::CreateCopyTreeWorkItem(file_name_from, file_name_to, + temp_dir_, WorkItem::IF_DIFFERENT)); EXPECT_TRUE(work_item->Do()); @@ -688,10 +680,8 @@ TEST_F(CopyTreeWorkItemTest, CopyTree) { // test Do() { scoped_ptr<CopyTreeWorkItem> work_item( - WorkItem::CreateCopyTreeWorkItem(dir_name_from.ToWStringHack(), - dir_name_to.ToWStringHack(), - temp_dir_.ToWStringHack(), - WorkItem::ALWAYS)); + WorkItem::CreateCopyTreeWorkItem(dir_name_from, dir_name_to, temp_dir_, + WorkItem::ALWAYS)); EXPECT_TRUE(work_item->Do()); } diff --git a/chrome/installer/util/delete_tree_work_item.cc b/chrome/installer/util/delete_tree_work_item.cc index 839f6bb..531f10a 100644 --- a/chrome/installer/util/delete_tree_work_item.cc +++ b/chrome/installer/util/delete_tree_work_item.cc @@ -21,8 +21,8 @@ DeleteTreeWorkItem::~DeleteTreeWorkItem() { } } -DeleteTreeWorkItem::DeleteTreeWorkItem(const std::wstring& root_path, - const std::wstring& key_path) +DeleteTreeWorkItem::DeleteTreeWorkItem(const FilePath& root_path, + const FilePath& key_path) : root_path_(root_path), key_path_(key_path) { } diff --git a/chrome/installer/util/delete_tree_work_item.h b/chrome/installer/util/delete_tree_work_item.h index b5bcb50..ff347dd 100644 --- a/chrome/installer/util/delete_tree_work_item.h +++ b/chrome/installer/util/delete_tree_work_item.h @@ -30,8 +30,8 @@ class DeleteTreeWorkItem : public WorkItem { // Get a backup path that can keep root_path_ or key_path_ bool GetBackupPath(const FilePath& for_path, FilePath* backup_path); - DeleteTreeWorkItem(const std::wstring& root_path, - const std::wstring& key_path); + DeleteTreeWorkItem(const FilePath& root_path, + const FilePath& key_path); // Root path to delete. FilePath root_path_; diff --git a/chrome/installer/util/delete_tree_work_item_unittest.cc b/chrome/installer/util/delete_tree_work_item_unittest.cc index 02c2bb0..acd66cc 100644 --- a/chrome/installer/util/delete_tree_work_item_unittest.cc +++ b/chrome/installer/util/delete_tree_work_item_unittest.cc @@ -87,8 +87,7 @@ TEST_F(DeleteTreeWorkItemTest, DeleteTreeNoKeyPath) { // test Do() scoped_ptr<DeleteTreeWorkItem> work_item( - WorkItem::CreateDeleteTreeWorkItem(dir_name_delete.ToWStringHack(), - std::wstring())); + WorkItem::CreateDeleteTreeWorkItem(dir_name_delete, FilePath())); EXPECT_TRUE(work_item->Do()); // everything should be gone @@ -135,8 +134,7 @@ TEST_F(DeleteTreeWorkItemTest, DeleteTree) { // test Do() scoped_ptr<DeleteTreeWorkItem> work_item( - WorkItem::CreateDeleteTreeWorkItem(dir_name_delete.ToWStringHack(), - file_name_delete_1.ToWStringHack())); + WorkItem::CreateDeleteTreeWorkItem(dir_name_delete, file_name_delete_1)); EXPECT_TRUE(work_item->Do()); // everything should be gone @@ -204,8 +202,7 @@ TEST_F(DeleteTreeWorkItemTest, DeleteTreeInUse) { // test Do(). { scoped_ptr<DeleteTreeWorkItem> work_item( - WorkItem::CreateDeleteTreeWorkItem(dir_name_delete.ToWStringHack(), - key_path.ToWStringHack())); + WorkItem::CreateDeleteTreeWorkItem(dir_name_delete, key_path)); // delete should fail as file in use. EXPECT_FALSE(work_item->Do()); diff --git a/chrome/installer/util/google_chrome_distribution.cc b/chrome/installer/util/google_chrome_distribution.cc index faf574b..b3a09c4 100644 --- a/chrome/installer/util/google_chrome_distribution.cc +++ b/chrome/installer/util/google_chrome_distribution.cc @@ -68,11 +68,11 @@ int FileTimeToHours(const FILETIME& time) { // Returns the directory last write time in hours since January 1, 1601. // Returns -1 if there was an error retrieving the directory time. -int GetDirectoryWriteTimeInHours(const wchar_t* path) { +int GetDirectoryWriteTimeInHours(const FilePath& path) { // To open a directory you need to pass FILE_FLAG_BACKUP_SEMANTICS. DWORD share = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE; - HANDLE file = ::CreateFileW(path, 0, share, NULL, OPEN_EXISTING, - FILE_FLAG_BACKUP_SEMANTICS, NULL); + HANDLE file = ::CreateFileW(path.value().c_str(), 0, share, NULL, + OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); if (INVALID_HANDLE_VALUE == file) return -1; FILETIME time; @@ -84,7 +84,7 @@ int GetDirectoryWriteTimeInHours(const wchar_t* path) { // Returns the directory last-write time age in hours, relative to current // time, so if it returns 14 it means that the directory was last written 14 // hours ago. Returns -1 if there was an error retrieving the directory. -int GetDirectoryWriteAgeInHours(const wchar_t* path) { +int GetDirectoryWriteAgeInHours(const FilePath& path) { int dir_time = GetDirectoryWriteTimeInHours(path); if (dir_time < 0) return dir_time; @@ -128,9 +128,9 @@ bool GoogleChromeDistribution::BuildUninstallMetricsString( } bool GoogleChromeDistribution::ExtractUninstallMetricsFromFile( - const std::wstring& file_path, std::wstring* uninstall_metrics_string) { + const FilePath& file_path, std::wstring* uninstall_metrics_string) { - JSONFileValueSerializer json_serializer(FilePath::FromWStringHack(file_path)); + JSONFileValueSerializer json_serializer(file_path); std::string json_error_string; scoped_ptr<Value> root(json_serializer.Deserialize(NULL)); @@ -172,7 +172,7 @@ bool GoogleChromeDistribution::ExtractUninstallMetrics( } void GoogleChromeDistribution::DoPostUninstallOperations( - const installer::Version& version, const std::wstring& local_data_path, + const installer::Version& version, const FilePath& local_data_path, const std::wstring& distribution_data) { // Send the Chrome version and OS version as params to the form. // It would be nice to send the locale, too, but I don't see an @@ -447,9 +447,9 @@ void GoogleChromeDistribution::LaunchUserExperiment( LOG(INFO) << "User in experiment locale"; // Check browser usage inactivity by the age of the last-write time of the // chrome user data directory. Ninety days is our trigger. - std::wstring user_data_dir = installer::GetChromeUserDataPath(); + FilePath user_data_dir(installer::GetChromeUserDataPath()); const int kSixtyDays = 60 * 24; - int dir_age_hours = GetDirectoryWriteAgeInHours(user_data_dir.c_str()); + int dir_age_hours = GetDirectoryWriteAgeInHours(user_data_dir); if (dir_age_hours < kSixtyDays) return; // At this point the user qualifies for the experiment, however we need to diff --git a/chrome/installer/util/google_chrome_distribution.h b/chrome/installer/util/google_chrome_distribution.h index c696e61..2e88858 100644 --- a/chrome/installer/util/google_chrome_distribution.h +++ b/chrome/installer/util/google_chrome_distribution.h @@ -14,6 +14,7 @@ #include "testing/gtest/include/gtest/gtest_prod.h" // for FRIEND_TEST class DictionaryValue; +class FilePath; class GoogleChromeDistribution : public BrowserDistribution { public: @@ -27,7 +28,7 @@ class GoogleChromeDistribution : public BrowserDistribution { // concatenated to the survey url if the file in local_data_path indicates // the user has opted in to providing anonymous usage data. virtual void DoPostUninstallOperations(const installer::Version& version, - const std::wstring& local_data_path, + const FilePath& local_data_path, const std::wstring& distribution_data); virtual std::wstring GetAppGuid(); @@ -51,7 +52,8 @@ class GoogleChromeDistribution : public BrowserDistribution { // install_status: if 0, means installation was successful. // value: current value of Google Update "ap" key. std::wstring GetNewGoogleUpdateApKey(bool diff_install, - installer_util::InstallStatus status, const std::wstring& value); + installer_util::InstallStatus status, + const std::wstring& value); virtual std::wstring GetPublisherName(); @@ -100,12 +102,12 @@ class GoogleChromeDistribution : public BrowserDistribution { // has GET parameters, i.e. &metric1=foo&metric2=bar. // Returns true if uninstall_metrics has been successfully populated with // the uninstall metrics, false otherwise. - virtual bool ExtractUninstallMetricsFromFile( - const std::wstring& file_path, std::wstring* uninstall_metrics); + virtual bool ExtractUninstallMetricsFromFile(const FilePath& file_path, + std::wstring* uninstall_metrics); // Extracts uninstall metrics from the given JSON value. virtual bool ExtractUninstallMetrics(const DictionaryValue& root, - std::wstring* uninstall_metrics); + std::wstring* uninstall_metrics); // Given a DictionaryValue containing a set of uninstall metrics, // this builds a URL parameter list of all the contained metrics. diff --git a/chrome/installer/util/helper.cc b/chrome/installer/util/helper.cc index af18e9e..a2038c4 100644 --- a/chrome/installer/util/helper.cc +++ b/chrome/installer/util/helper.cc @@ -18,8 +18,8 @@ namespace { -std::wstring GetChromeInstallBasePath(bool system_install, - const wchar_t* subpath) { +FilePath GetChromeInstallBasePath(bool system_install, + const wchar_t* subpath) { FilePath install_path; if (system_install) { PathService::Get(base::DIR_PROGRAM_FILES, &install_path); @@ -31,41 +31,42 @@ std::wstring GetChromeInstallBasePath(bool system_install, install_path = install_path.Append(dist->GetInstallSubDir()); install_path = install_path.Append(subpath); } - return install_path.ToWStringHack(); + return install_path; } } // namespace -std::wstring installer::GetChromeInstallPath(bool system_install) { +FilePath installer::GetChromeInstallPath(bool system_install) { return GetChromeInstallBasePath(system_install, installer_util::kInstallBinaryDir); } -std::wstring installer::GetChromeUserDataPath() { +FilePath installer::GetChromeUserDataPath() { return GetChromeInstallBasePath(false, installer_util::kInstallUserDataDir); } bool installer::LaunchChrome(bool system_install) { - std::wstring chrome_exe(L"\""); - chrome_exe.append(installer::GetChromeInstallPath(system_install)); - file_util::AppendToPath(&chrome_exe, installer_util::kChromeExe); - chrome_exe.append(L"\""); - return base::LaunchApp(chrome_exe, false, false, NULL); + FilePath chrome_exe(FILE_PATH_LITERAL("\"")); + chrome_exe = chrome_exe.Append(installer::GetChromeInstallPath( + system_install)); + chrome_exe = chrome_exe.Append(installer_util::kChromeExe); + chrome_exe = chrome_exe.Append(FILE_PATH_LITERAL("\"")); + return base::LaunchApp(chrome_exe.value(), false, false, NULL); } bool installer::LaunchChromeAndWaitForResult(bool system_install, const std::wstring& options, int32* exit_code) { - std::wstring chrome_exe(installer::GetChromeInstallPath(system_install)); + FilePath chrome_exe(installer::GetChromeInstallPath(system_install)); if (chrome_exe.empty()) return false; - file_util::AppendToPath(&chrome_exe, installer_util::kChromeExe); + chrome_exe = chrome_exe.Append(installer_util::kChromeExe); - std::wstring command_line(L"\"" + chrome_exe + L"\""); + std::wstring command_line(L"\"" + chrome_exe.value() + L"\""); command_line.append(options); STARTUPINFOW si = {sizeof(si)}; PROCESS_INFORMATION pi = {0}; - if (!::CreateProcessW(chrome_exe.c_str(), + if (!::CreateProcessW(chrome_exe.value().c_str(), const_cast<wchar_t*>(command_line.c_str()), NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi)) { @@ -85,13 +86,13 @@ bool installer::LaunchChromeAndWaitForResult(bool system_install, return true; } -void installer::RemoveOldVersionDirs(const std::wstring& chrome_path, +void installer::RemoveOldVersionDirs(const FilePath& chrome_path, const std::wstring& latest_version_str) { - std::wstring search_path(chrome_path); - file_util::AppendToPath(&search_path, L"*"); + FilePath search_path(chrome_path.AppendASCII("*")); WIN32_FIND_DATA find_file_data; - HANDLE file_handle = FindFirstFile(search_path.c_str(), &find_file_data); + HANDLE file_handle = FindFirstFile(search_path.value().c_str(), + &find_file_data); if (file_handle == INVALID_HANDLE_VALUE) return; @@ -108,11 +109,9 @@ void installer::RemoveOldVersionDirs(const std::wstring& chrome_path, version.reset( installer::Version::GetVersionFromString(find_file_data.cFileName)); if (version.get() && latest_version->IsHigherThan(version.get())) { - std::wstring remove_dir(chrome_path); - file_util::AppendToPath(&remove_dir, find_file_data.cFileName); - std::wstring chrome_dll_path(remove_dir); - file_util::AppendToPath(&chrome_dll_path, installer_util::kChromeDll); - LOG(INFO) << "deleting directory " << remove_dir; + FilePath remove_dir(chrome_path.Append(find_file_data.cFileName)); + FilePath chrome_dll_path(remove_dir.Append(installer_util::kChromeDll)); + LOG(INFO) << "deleting directory " << remove_dir.value(); scoped_ptr<DeleteTreeWorkItem> item; item.reset(WorkItem::CreateDeleteTreeWorkItem(remove_dir, chrome_dll_path)); diff --git a/chrome/installer/util/helper.h b/chrome/installer/util/helper.h index 132d718..975ec8a 100644 --- a/chrome/installer/util/helper.h +++ b/chrome/installer/util/helper.h @@ -9,6 +9,8 @@ #include <string> +class FilePath; + namespace installer { // This function returns the install path for Chrome depending on whether its @@ -16,13 +18,13 @@ namespace installer { // system_install: if true, the function returns system wide location // (ProgramFiles\Google). Otherwise it returns user specific // location (Document And Settings\<user>\Local Settings...) -std::wstring GetChromeInstallPath(bool system_install); +FilePath GetChromeInstallPath(bool system_install); // This function returns the path to the directory that holds the user data, // this is always inside "Document And Settings\<user>\Local Settings.". Note // that this is the default user data directory and does not take into account // that it can be overriden with a command line parameter. -std::wstring GetChromeUserDataPath(); +FilePath GetChromeUserDataPath(); // Launches Chrome without waiting for its exit. bool LaunchChrome(bool system_install); @@ -42,7 +44,7 @@ bool LaunchChromeAndWaitForResult(bool system_install, // // chrome_path: the root path of Chrome installation. // latest_version_str: the latest version of Chrome installed. -void RemoveOldVersionDirs(const std::wstring& chrome_path, +void RemoveOldVersionDirs(const FilePath& chrome_path, const std::wstring& latest_version_str); } // namespace installer diff --git a/chrome/installer/util/helper_unittest.cc b/chrome/installer/util/helper_unittest.cc index 6ccbd29..fa297a5 100644 --- a/chrome/installer/util/helper_unittest.cc +++ b/chrome/installer/util/helper_unittest.cc @@ -105,7 +105,7 @@ TEST_F(SetupHelperTest, Delete) { ASSERT_TRUE(file_util::PathExists(chrome_dll_4)); std::wstring latest_version(L"1.0.4.0"); - installer::RemoveOldVersionDirs(chrome_dir.value(), latest_version); + installer::RemoveOldVersionDirs(chrome_dir, latest_version); // old versions should be gone EXPECT_FALSE(file_util::PathExists(chrome_dir_1)); @@ -178,7 +178,7 @@ TEST_F(SetupHelperTest, DeleteInUsed) { ASSERT_TRUE(file_util::PathExists(chrome_dll_4)); std::wstring latest_version(L"1.0.4.0"); - installer::RemoveOldVersionDirs(chrome_dir.value(), latest_version); + installer::RemoveOldVersionDirs(chrome_dir, latest_version); // old versions not in used should be gone EXPECT_FALSE(file_util::PathExists(chrome_dir_1)); diff --git a/chrome/installer/util/logging_installer.cc b/chrome/installer/util/logging_installer.cc index e03c25b..a7ac607 100644 --- a/chrome/installer/util/logging_installer.cc +++ b/chrome/installer/util/logging_installer.cc @@ -50,8 +50,7 @@ void EndInstallerLogging() { } std::wstring GetLogFilePath(const CommandLine& command_line) { - if (command_line.HasSwitch( - WideToASCII(installer_util::switches::kLogFile))) { + if (command_line.HasSwitch(WideToASCII(installer_util::switches::kLogFile))) { return command_line.GetSwitchValue( WideToASCII(installer_util::switches::kLogFile)); } @@ -64,10 +63,9 @@ std::wstring GetLogFilePath(const CommandLine& command_line) { } FilePath log_path; - if (PathService::Get(base::DIR_TEMP, &log_path)) { log_path = log_path.Append(log_filename); - return log_path.ToWStringHack(); + return log_path.value(); } else { return log_filename; } diff --git a/chrome/installer/util/move_tree_work_item.cc b/chrome/installer/util/move_tree_work_item.cc index 45c03b2..be5b7af 100644 --- a/chrome/installer/util/move_tree_work_item.cc +++ b/chrome/installer/util/move_tree_work_item.cc @@ -14,9 +14,9 @@ MoveTreeWorkItem::~MoveTreeWorkItem() { } } -MoveTreeWorkItem::MoveTreeWorkItem(const std::wstring& source_path, - const std::wstring& dest_path, - const std::wstring& temp_dir) +MoveTreeWorkItem::MoveTreeWorkItem(const FilePath& source_path, + const FilePath& dest_path, + const FilePath& temp_dir) : source_path_(source_path), dest_path_(dest_path), temp_dir_(temp_dir), diff --git a/chrome/installer/util/move_tree_work_item.h b/chrome/installer/util/move_tree_work_item.h index cfa86c4..1ab3644 100644 --- a/chrome/installer/util/move_tree_work_item.h +++ b/chrome/installer/util/move_tree_work_item.h @@ -33,9 +33,9 @@ class MoveTreeWorkItem : public WorkItem { // specified by dest_path. To facilitate rollback, the caller needs to supply // a temporary directory (temp_dir) to save the original files if they exist // under dest_path. - MoveTreeWorkItem(const std::wstring& source_path, - const std::wstring& dest_path, - const std::wstring& temp_dir); + MoveTreeWorkItem(const FilePath& source_path, + const FilePath& dest_path, + const FilePath& temp_dir); // Source path to move files from. FilePath source_path_; diff --git a/chrome/installer/util/move_tree_work_item_unittest.cc b/chrome/installer/util/move_tree_work_item_unittest.cc index 9662b18..90e6c2b 100644 --- a/chrome/installer/util/move_tree_work_item_unittest.cc +++ b/chrome/installer/util/move_tree_work_item_unittest.cc @@ -27,11 +27,11 @@ namespace { // Create a fresh, empty copy of this test directory. file_util::Delete(test_dir_, true); - file_util::CreateDirectoryW(test_dir_); + file_util::CreateDirectory(test_dir_); // Create a tempory directory under the test directory. temp_dir_ = test_dir_.AppendASCII("temp"); - file_util::CreateDirectoryW(temp_dir_); + file_util::CreateDirectory(temp_dir_); ASSERT_TRUE(file_util::PathExists(test_dir_)); ASSERT_TRUE(file_util::PathExists(temp_dir_)); @@ -104,8 +104,7 @@ TEST_F(MoveTreeWorkItemTest, MoveDirectory) { // test Do() scoped_ptr<MoveTreeWorkItem> work_item(WorkItem::CreateMoveTreeWorkItem( - from_dir1.ToWStringHack(), to_dir.ToWStringHack(), - temp_dir_.ToWStringHack())); + from_dir1, to_dir, temp_dir_)); EXPECT_TRUE(work_item->Do()); EXPECT_FALSE(file_util::PathExists(from_dir1)); @@ -157,8 +156,7 @@ TEST_F(MoveTreeWorkItemTest, MoveDirectoryDestExists) { // test Do() scoped_ptr<MoveTreeWorkItem> work_item(WorkItem::CreateMoveTreeWorkItem( - from_dir1.ToWStringHack(), to_dir.ToWStringHack(), - temp_dir_.ToWStringHack())); + from_dir1, to_dir, temp_dir_)); EXPECT_TRUE(work_item->Do()); EXPECT_FALSE(file_util::PathExists(from_dir1)); @@ -199,8 +197,7 @@ TEST_F(MoveTreeWorkItemTest, MoveAFile) { // test Do() scoped_ptr<MoveTreeWorkItem> work_item(WorkItem::CreateMoveTreeWorkItem( - from_file.ToWStringHack(), to_file.ToWStringHack(), - temp_dir_.ToWStringHack())); + from_file, to_file, temp_dir_)); EXPECT_TRUE(work_item->Do()); EXPECT_TRUE(file_util::PathExists(from_dir)); @@ -244,8 +241,7 @@ TEST_F(MoveTreeWorkItemTest, MoveFileDestExists) { // test Do() scoped_ptr<MoveTreeWorkItem> work_item(WorkItem::CreateMoveTreeWorkItem( - from_file.ToWStringHack(), to_dir.ToWStringHack(), - temp_dir_.ToWStringHack())); + from_file, to_dir, temp_dir_)); EXPECT_TRUE(work_item->Do()); EXPECT_TRUE(file_util::PathExists(from_dir)); @@ -302,8 +298,7 @@ TEST_F(MoveTreeWorkItemTest, MoveFileDestInUse) { // test Do() scoped_ptr<MoveTreeWorkItem> work_item(WorkItem::CreateMoveTreeWorkItem( - from_file.ToWStringHack(), to_file.ToWStringHack(), - temp_dir_.ToWStringHack())); + from_file, to_file, temp_dir_)); EXPECT_TRUE(work_item->Do()); EXPECT_TRUE(file_util::PathExists(from_dir)); @@ -363,8 +358,7 @@ TEST_F(MoveTreeWorkItemTest, MoveFileInUse) { // test Do() scoped_ptr<MoveTreeWorkItem> work_item(WorkItem::CreateMoveTreeWorkItem( - from_file.ToWStringHack(), to_file.ToWStringHack(), - temp_dir_.ToWStringHack())); + from_file, to_file, temp_dir_)); EXPECT_TRUE(work_item->Do()); EXPECT_TRUE(file_util::PathExists(from_dir)); diff --git a/chrome/installer/util/work_item.cc b/chrome/installer/util/work_item.cc index af14379..1c337e1 100644 --- a/chrome/installer/util/work_item.cc +++ b/chrome/installer/util/work_item.cc @@ -21,11 +21,11 @@ WorkItem::~WorkItem() { } CopyTreeWorkItem* WorkItem::CreateCopyTreeWorkItem( - const std::wstring& source_path, - const std::wstring& dest_path, - const std::wstring& temp_dir, + const FilePath& source_path, + const FilePath& dest_path, + const FilePath& temp_dir, CopyOverWriteOption overwrite_option, - const std::wstring& alternative_path) { + const FilePath& alternative_path) { return new CopyTreeWorkItem(source_path, dest_path, temp_dir, overwrite_option, alternative_path); } @@ -49,14 +49,14 @@ DeleteRegValueWorkItem* WorkItem::CreateDeleteRegValueWorkItem( } DeleteTreeWorkItem* WorkItem::CreateDeleteTreeWorkItem( - const std::wstring& root_path, const std::wstring& key_path) { + const FilePath& root_path, const FilePath& key_path) { return new DeleteTreeWorkItem(root_path, key_path); } MoveTreeWorkItem* WorkItem::CreateMoveTreeWorkItem( - const std::wstring& source_path, - const std::wstring& dest_path, - const std::wstring& temp_dir) { + const FilePath& source_path, + const FilePath& dest_path, + const FilePath& temp_dir) { return new MoveTreeWorkItem(source_path, dest_path, temp_dir); } diff --git a/chrome/installer/util/work_item.h b/chrome/installer/util/work_item.h index 9a61363..45b72ae 100644 --- a/chrome/installer/util/work_item.h +++ b/chrome/installer/util/work_item.h @@ -46,11 +46,11 @@ class WorkItem { // * If overwrite_option is NEW_NAME_IF_IN_USE, file is copied with an // alternate name specified by alternative_path. static CopyTreeWorkItem* CreateCopyTreeWorkItem( - const std::wstring& source_path, - const std::wstring& dest_path, - const std::wstring& temp_dir, + const FilePath& source_path, + const FilePath& dest_path, + const FilePath& temp_dir, CopyOverWriteOption overwrite_option, - const std::wstring& alternative_path = L""); + const FilePath& alternative_path = FilePath()); // Create a CreateDirWorkItem that creates a directory at the given path. static CreateDirWorkItem* CreateCreateDirWorkItem(const FilePath& path); @@ -71,14 +71,14 @@ class WorkItem { // hierarchy at the given root path. A key file can be optionally specified // by key_path. static DeleteTreeWorkItem* CreateDeleteTreeWorkItem( - const std::wstring& root_path, const std::wstring& key_path); + const FilePath& root_path, const FilePath& key_path); // Create a MoveTreeWorkItem that recursively moves a file system hierarchy // from source path to destination path. static MoveTreeWorkItem* CreateMoveTreeWorkItem( - const std::wstring& source_path, - const std::wstring& dest_path, - const std::wstring& temp_dir); + const FilePath& source_path, + const FilePath& dest_path, + const FilePath& temp_dir); // Create a SetRegValueWorkItem that sets a registry value with REG_SZ type // at the key with specified path. diff --git a/chrome/installer/util/work_item_list.cc b/chrome/installer/util/work_item_list.cc index 8f4c702..76d0dfa 100644 --- a/chrome/installer/util/work_item_list.cc +++ b/chrome/installer/util/work_item_list.cc @@ -63,11 +63,11 @@ bool WorkItemList::AddWorkItem(WorkItem* work_item) { return true; } -bool WorkItemList::AddCopyTreeWorkItem(const std::wstring& source_path, - const std::wstring& dest_path, - const std::wstring& temp_dir, +bool WorkItemList::AddCopyTreeWorkItem(const FilePath& source_path, + const FilePath& dest_path, + const FilePath& temp_dir, CopyOverWriteOption overwrite_option, - const std::wstring& alternative_path) { + const FilePath& alternative_path) { WorkItem* item = reinterpret_cast<WorkItem*>( WorkItem::CreateCopyTreeWorkItem(source_path, dest_path, temp_dir, overwrite_option, alternative_path)); @@ -97,16 +97,16 @@ bool WorkItemList::AddDeleteRegValueWorkItem(HKEY predefined_root, return AddWorkItem(item); } -bool WorkItemList::AddDeleteTreeWorkItem(const std::wstring& root_path, - const std::wstring& key_path) { +bool WorkItemList::AddDeleteTreeWorkItem(const FilePath& root_path, + const FilePath& key_path) { WorkItem* item = reinterpret_cast<WorkItem*>( WorkItem::CreateDeleteTreeWorkItem(root_path, key_path)); return AddWorkItem(item); } -bool WorkItemList::AddMoveTreeWorkItem(const std::wstring& source_path, - const std::wstring& dest_path, - const std::wstring& temp_dir) { +bool WorkItemList::AddMoveTreeWorkItem(const FilePath& source_path, + const FilePath& dest_path, + const FilePath& temp_dir) { WorkItem* item = reinterpret_cast<WorkItem*>( WorkItem::CreateMoveTreeWorkItem(source_path, dest_path, temp_dir)); return AddWorkItem(item); diff --git a/chrome/installer/util/work_item_list.h b/chrome/installer/util/work_item_list.h index 1390701..71bec61 100644 --- a/chrome/installer/util/work_item_list.h +++ b/chrome/installer/util/work_item_list.h @@ -36,11 +36,11 @@ class WorkItemList : public WorkItem { bool AddWorkItem(WorkItem* work_item); // Add a CopyTreeWorkItem to the list of work items. - bool AddCopyTreeWorkItem(const std::wstring& source_path, - const std::wstring& dest_path, - const std::wstring& temp_dir, + bool AddCopyTreeWorkItem(const FilePath& source_path, + const FilePath& dest_path, + const FilePath& temp_dir, CopyOverWriteOption overwrite_option, - const std::wstring& alternative_path = L""); + const FilePath& alternative_path = FilePath()); // Add a CreateDirWorkItem that creates a directory at the given path. bool AddCreateDirWorkItem(const FilePath& path); @@ -59,13 +59,13 @@ class WorkItemList : public WorkItem { // Add a DeleteTreeWorkItem that recursively deletes a file system // hierarchy at the given root path. A key file can be optionally specified // by key_path. - bool AddDeleteTreeWorkItem(const std::wstring& root_path, - const std::wstring& key_path); + bool AddDeleteTreeWorkItem(const FilePath& root_path, + const FilePath& key_path); // Add a MoveTreeWorkItem to the list of work items. - bool AddMoveTreeWorkItem(const std::wstring& source_path, - const std::wstring& dest_path, - const std::wstring& temp_dir); + bool AddMoveTreeWorkItem(const FilePath& source_path, + const FilePath& dest_path, + const FilePath& temp_dir); // Add a SetRegValueWorkItem that sets a registry value with REG_SZ type // at the key with specified path. |