Commit ee1f3c13 authored by evan@chromium.org's avatar evan@chromium.org

wstring: use a few more FilePaths to remove Hack functions

BUG=69467

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72728 0039d316-1c4b-4281-b951-d872f2087c98
parent cd431217
......@@ -16,11 +16,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),
......
......@@ -37,11 +37,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);
......
......@@ -107,10 +107,11 @@ 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::ALWAYS));
WorkItem::CreateCopyTreeWorkItem(file_name_from,
file_name_to,
temp_dir_,
WorkItem::ALWAYS,
FilePath()));
EXPECT_TRUE(work_item->Do());
......@@ -148,10 +149,11 @@ 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::ALWAYS));
WorkItem::CreateCopyTreeWorkItem(file_name_from,
file_name_to,
temp_dir_,
WorkItem::ALWAYS,
FilePath()));
EXPECT_TRUE(work_item->Do());
......@@ -171,10 +173,11 @@ 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::IF_DIFFERENT));
WorkItem::CreateCopyTreeWorkItem(file_name_from,
file_name_to,
temp_dir_,
WorkItem::IF_DIFFERENT,
FilePath()));
EXPECT_TRUE(work_item->Do());
......@@ -220,10 +223,11 @@ 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::ALWAYS));
WorkItem::CreateCopyTreeWorkItem(file_name_from,
file_name_to,
temp_dir_,
WorkItem::ALWAYS,
FilePath()));
EXPECT_TRUE(work_item->Do());
......@@ -248,10 +252,11 @@ 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::IF_DIFFERENT));
WorkItem::CreateCopyTreeWorkItem(file_name_from,
file_name_to,
temp_dir_,
WorkItem::IF_DIFFERENT,
FilePath()));
EXPECT_TRUE(work_item->Do());
......@@ -299,10 +304,11 @@ 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::IF_DIFFERENT));
WorkItem::CreateCopyTreeWorkItem(file_name_from,
file_name_to,
temp_dir_,
WorkItem::IF_DIFFERENT,
FilePath()));
EXPECT_TRUE(work_item->Do());
......@@ -361,10 +367,11 @@ 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,
FilePath()));
EXPECT_TRUE(work_item->Do());
......@@ -439,11 +446,11 @@ 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::CreateCopyTreeWorkItem(file_name_from,
file_name_to,
temp_dir_,
WorkItem::NEW_NAME_IF_IN_USE,
alternate_to.ToWStringHack()));
alternate_to));
EXPECT_TRUE(work_item->Do());
......@@ -474,9 +481,9 @@ TEST_F(CopyTreeWorkItemTest, NewNameAndCopyTest) {
// 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()));
file_name_from, file_name_to,
temp_dir_, WorkItem::NEW_NAME_IF_IN_USE,
alternate_to));
if (IsFileInUse(file_name_to))
base::PlatformThread::Sleep(2000);
// If file is still in use, the rest of the test will fail.
......@@ -536,9 +543,11 @@ TEST_F(CopyTreeWorkItemTest, FLAKY_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
......@@ -563,8 +572,9 @@ TEST_F(CopyTreeWorkItemTest, FLAKY_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""));
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
......@@ -628,10 +638,11 @@ TEST_F(CopyTreeWorkItemTest, FLAKY_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,
FilePath()));
EXPECT_TRUE(work_item->Do());
......@@ -690,10 +701,11 @@ TEST_F(CopyTreeWorkItemTest, FLAKY_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,
FilePath()));
EXPECT_TRUE(work_item->Do());
}
......
......@@ -23,11 +23,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);
}
......
......@@ -59,11 +59,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);
// Create a CreateDirWorkItem that creates a directory at the given path.
static CreateDirWorkItem* CreateCreateDirWorkItem(const FilePath& path);
......
......@@ -78,11 +78,11 @@ WorkItem* WorkItemList::AddCopyTreeWorkItem(
const std::wstring& temp_dir,
CopyOverWriteOption overwrite_option,
const std::wstring& alternative_path) {
WorkItem* item = WorkItem::CreateCopyTreeWorkItem(source_path,
dest_path,
temp_dir,
WorkItem* item = WorkItem::CreateCopyTreeWorkItem(FilePath(source_path),
FilePath(dest_path),
FilePath(temp_dir),
overwrite_option,
alternative_path);
FilePath(alternative_path));
AddWorkItem(item);
return item;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment