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() { ...@@ -16,11 +16,11 @@ CopyTreeWorkItem::~CopyTreeWorkItem() {
} }
} }
CopyTreeWorkItem::CopyTreeWorkItem(const std::wstring& source_path, CopyTreeWorkItem::CopyTreeWorkItem(const FilePath& source_path,
const std::wstring& dest_path, const FilePath& dest_path,
const std::wstring& temp_dir, const FilePath& temp_dir,
CopyOverWriteOption overwrite_option, CopyOverWriteOption overwrite_option,
const std::wstring& alternative_path) const FilePath& alternative_path)
: source_path_(source_path), : source_path_(source_path),
dest_path_(dest_path), dest_path_(dest_path),
temp_dir_(temp_dir), temp_dir_(temp_dir),
......
...@@ -37,11 +37,11 @@ class CopyTreeWorkItem : public WorkItem { ...@@ -37,11 +37,11 @@ class CopyTreeWorkItem : public WorkItem {
// Notes on temp_path: to facilitate rollback, the caller needs to supply // Notes on temp_path: to facilitate rollback, the caller needs to supply
// a temporary directory to save the original files if they exist under // a temporary directory to save the original files if they exist under
// dest_path. // dest_path.
CopyTreeWorkItem(const std::wstring& source_path, CopyTreeWorkItem(const FilePath& source_path,
const std::wstring& dest_path, const FilePath& dest_path,
const std::wstring& temp_dir, const FilePath& temp_dir,
CopyOverWriteOption overwrite_option, 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) // Checks if the path specified is in use (and hence can not be deleted)
bool IsFileInUse(const FilePath& path); bool IsFileInUse(const FilePath& path);
......
...@@ -107,10 +107,11 @@ TEST_F(CopyTreeWorkItemTest, CopyFile) { ...@@ -107,10 +107,11 @@ TEST_F(CopyTreeWorkItemTest, CopyFile) {
// test Do() // test Do()
scoped_ptr<CopyTreeWorkItem> work_item( scoped_ptr<CopyTreeWorkItem> work_item(
WorkItem::CreateCopyTreeWorkItem(file_name_from.ToWStringHack(), WorkItem::CreateCopyTreeWorkItem(file_name_from,
file_name_to.ToWStringHack(), file_name_to,
temp_dir_.ToWStringHack(), temp_dir_,
WorkItem::ALWAYS)); WorkItem::ALWAYS,
FilePath()));
EXPECT_TRUE(work_item->Do()); EXPECT_TRUE(work_item->Do());
...@@ -148,10 +149,11 @@ TEST_F(CopyTreeWorkItemTest, CopyFileOverwrite) { ...@@ -148,10 +149,11 @@ TEST_F(CopyTreeWorkItemTest, CopyFileOverwrite) {
// test Do() with always_overwrite being true. // test Do() with always_overwrite being true.
scoped_ptr<CopyTreeWorkItem> work_item( scoped_ptr<CopyTreeWorkItem> work_item(
WorkItem::CreateCopyTreeWorkItem(file_name_from.ToWStringHack(), WorkItem::CreateCopyTreeWorkItem(file_name_from,
file_name_to.ToWStringHack(), file_name_to,
temp_dir_.ToWStringHack(), temp_dir_,
WorkItem::ALWAYS)); WorkItem::ALWAYS,
FilePath()));
EXPECT_TRUE(work_item->Do()); EXPECT_TRUE(work_item->Do());
...@@ -171,10 +173,11 @@ TEST_F(CopyTreeWorkItemTest, CopyFileOverwrite) { ...@@ -171,10 +173,11 @@ TEST_F(CopyTreeWorkItemTest, CopyFileOverwrite) {
// test Do() with always_overwrite being false. // test Do() with always_overwrite being false.
// the file is still overwritten since the content is different. // the file is still overwritten since the content is different.
work_item.reset( work_item.reset(
WorkItem::CreateCopyTreeWorkItem(file_name_from.ToWStringHack(), WorkItem::CreateCopyTreeWorkItem(file_name_from,
file_name_to.ToWStringHack(), file_name_to,
temp_dir_.ToWStringHack(), temp_dir_,
WorkItem::IF_DIFFERENT)); WorkItem::IF_DIFFERENT,
FilePath()));
EXPECT_TRUE(work_item->Do()); EXPECT_TRUE(work_item->Do());
...@@ -220,10 +223,11 @@ TEST_F(CopyTreeWorkItemTest, CopyFileSameContent) { ...@@ -220,10 +223,11 @@ TEST_F(CopyTreeWorkItemTest, CopyFileSameContent) {
// test Do() with always_overwrite being true. // test Do() with always_overwrite being true.
scoped_ptr<CopyTreeWorkItem> work_item( scoped_ptr<CopyTreeWorkItem> work_item(
WorkItem::CreateCopyTreeWorkItem(file_name_from.ToWStringHack(), WorkItem::CreateCopyTreeWorkItem(file_name_from,
file_name_to.ToWStringHack(), file_name_to,
temp_dir_.ToWStringHack(), temp_dir_,
WorkItem::ALWAYS)); WorkItem::ALWAYS,
FilePath()));
EXPECT_TRUE(work_item->Do()); EXPECT_TRUE(work_item->Do());
...@@ -248,10 +252,11 @@ TEST_F(CopyTreeWorkItemTest, CopyFileSameContent) { ...@@ -248,10 +252,11 @@ TEST_F(CopyTreeWorkItemTest, CopyFileSameContent) {
// test Do() with always_overwrite being false. nothing should change. // test Do() with always_overwrite being false. nothing should change.
work_item.reset( work_item.reset(
WorkItem::CreateCopyTreeWorkItem(file_name_from.ToWStringHack(), WorkItem::CreateCopyTreeWorkItem(file_name_from,
file_name_to.ToWStringHack(), file_name_to,
temp_dir_.ToWStringHack(), temp_dir_,
WorkItem::IF_DIFFERENT)); WorkItem::IF_DIFFERENT,
FilePath()));
EXPECT_TRUE(work_item->Do()); EXPECT_TRUE(work_item->Do());
...@@ -299,10 +304,11 @@ TEST_F(CopyTreeWorkItemTest, CopyFileAndCleanup) { ...@@ -299,10 +304,11 @@ TEST_F(CopyTreeWorkItemTest, CopyFileAndCleanup) {
{ {
// test Do(). // test Do().
scoped_ptr<CopyTreeWorkItem> work_item( scoped_ptr<CopyTreeWorkItem> work_item(
WorkItem::CreateCopyTreeWorkItem(file_name_from.ToWStringHack(), WorkItem::CreateCopyTreeWorkItem(file_name_from,
file_name_to.ToWStringHack(), file_name_to,
temp_dir_.ToWStringHack(), temp_dir_,
WorkItem::IF_DIFFERENT)); WorkItem::IF_DIFFERENT,
FilePath()));
EXPECT_TRUE(work_item->Do()); EXPECT_TRUE(work_item->Do());
...@@ -361,10 +367,11 @@ TEST_F(CopyTreeWorkItemTest, CopyFileInUse) { ...@@ -361,10 +367,11 @@ TEST_F(CopyTreeWorkItemTest, CopyFileInUse) {
// test Do(). // test Do().
scoped_ptr<CopyTreeWorkItem> work_item( scoped_ptr<CopyTreeWorkItem> work_item(
WorkItem::CreateCopyTreeWorkItem(file_name_from.ToWStringHack(), WorkItem::CreateCopyTreeWorkItem(file_name_from,
file_name_to.ToWStringHack(), file_name_to,
temp_dir_.ToWStringHack(), temp_dir_,
WorkItem::IF_DIFFERENT)); WorkItem::IF_DIFFERENT,
FilePath()));
EXPECT_TRUE(work_item->Do()); EXPECT_TRUE(work_item->Do());
...@@ -439,11 +446,11 @@ TEST_F(CopyTreeWorkItemTest, NewNameAndCopyTest) { ...@@ -439,11 +446,11 @@ TEST_F(CopyTreeWorkItemTest, NewNameAndCopyTest) {
// test Do(). // test Do().
scoped_ptr<CopyTreeWorkItem> work_item( scoped_ptr<CopyTreeWorkItem> work_item(
WorkItem::CreateCopyTreeWorkItem(file_name_from.ToWStringHack(), WorkItem::CreateCopyTreeWorkItem(file_name_from,
file_name_to.ToWStringHack(), file_name_to,
temp_dir_.ToWStringHack(), temp_dir_,
WorkItem::NEW_NAME_IF_IN_USE, WorkItem::NEW_NAME_IF_IN_USE,
alternate_to.ToWStringHack())); alternate_to));
EXPECT_TRUE(work_item->Do()); EXPECT_TRUE(work_item->Do());
...@@ -474,9 +481,9 @@ TEST_F(CopyTreeWorkItemTest, NewNameAndCopyTest) { ...@@ -474,9 +481,9 @@ TEST_F(CopyTreeWorkItemTest, NewNameAndCopyTest) {
// Now the process has terminated, lets try overwriting the file again // Now the process has terminated, lets try overwriting the file again
work_item.reset(WorkItem::CreateCopyTreeWorkItem( work_item.reset(WorkItem::CreateCopyTreeWorkItem(
file_name_from.ToWStringHack(), file_name_to.ToWStringHack(), file_name_from, file_name_to,
temp_dir_.ToWStringHack(), WorkItem::NEW_NAME_IF_IN_USE, temp_dir_, WorkItem::NEW_NAME_IF_IN_USE,
alternate_to.ToWStringHack())); alternate_to));
if (IsFileInUse(file_name_to)) if (IsFileInUse(file_name_to))
base::PlatformThread::Sleep(2000); base::PlatformThread::Sleep(2000);
// If file is still in use, the rest of the test will fail. // If file is still in use, the rest of the test will fail.
...@@ -536,9 +543,11 @@ TEST_F(CopyTreeWorkItemTest, FLAKY_IfNotPresentTest) { ...@@ -536,9 +543,11 @@ TEST_F(CopyTreeWorkItemTest, FLAKY_IfNotPresentTest) {
// test Do(). // test Do().
scoped_ptr<CopyTreeWorkItem> work_item( scoped_ptr<CopyTreeWorkItem> work_item(
WorkItem::CreateCopyTreeWorkItem(file_name_from.ToWStringHack(), WorkItem::CreateCopyTreeWorkItem(
file_name_to.ToWStringHack(), temp_dir_.ToWStringHack(), file_name_from,
WorkItem::IF_NOT_PRESENT, L"")); file_name_to, temp_dir_,
WorkItem::IF_NOT_PRESENT,
FilePath()));
EXPECT_TRUE(work_item->Do()); EXPECT_TRUE(work_item->Do());
// verify that the source, destination have not changed and backup path // verify that the source, destination have not changed and backup path
...@@ -563,8 +572,9 @@ TEST_F(CopyTreeWorkItemTest, FLAKY_IfNotPresentTest) { ...@@ -563,8 +572,9 @@ TEST_F(CopyTreeWorkItemTest, FLAKY_IfNotPresentTest) {
// Now delete the destination and try copying the file again. // Now delete the destination and try copying the file again.
file_util::Delete(file_name_to, true); file_util::Delete(file_name_to, true);
work_item.reset(WorkItem::CreateCopyTreeWorkItem( work_item.reset(WorkItem::CreateCopyTreeWorkItem(
file_name_from.ToWStringHack(), file_name_to.ToWStringHack(), file_name_from, file_name_to,
temp_dir_.ToWStringHack(), WorkItem::IF_NOT_PRESENT, L"")); temp_dir_, WorkItem::IF_NOT_PRESENT,
FilePath()));
EXPECT_TRUE(work_item->Do()); EXPECT_TRUE(work_item->Do());
// verify that the source, destination are the same and backup path // verify that the source, destination are the same and backup path
...@@ -628,10 +638,11 @@ TEST_F(CopyTreeWorkItemTest, FLAKY_CopyFileInUseAndCleanup) { ...@@ -628,10 +638,11 @@ TEST_F(CopyTreeWorkItemTest, FLAKY_CopyFileInUseAndCleanup) {
// test Do(). // test Do().
{ {
scoped_ptr<CopyTreeWorkItem> work_item( scoped_ptr<CopyTreeWorkItem> work_item(
WorkItem::CreateCopyTreeWorkItem(file_name_from.ToWStringHack(), WorkItem::CreateCopyTreeWorkItem(file_name_from,
file_name_to.ToWStringHack(), file_name_to,
temp_dir_.ToWStringHack(), temp_dir_,
WorkItem::IF_DIFFERENT)); WorkItem::IF_DIFFERENT,
FilePath()));
EXPECT_TRUE(work_item->Do()); EXPECT_TRUE(work_item->Do());
...@@ -690,10 +701,11 @@ TEST_F(CopyTreeWorkItemTest, FLAKY_CopyTree) { ...@@ -690,10 +701,11 @@ TEST_F(CopyTreeWorkItemTest, FLAKY_CopyTree) {
// test Do() // test Do()
{ {
scoped_ptr<CopyTreeWorkItem> work_item( scoped_ptr<CopyTreeWorkItem> work_item(
WorkItem::CreateCopyTreeWorkItem(dir_name_from.ToWStringHack(), WorkItem::CreateCopyTreeWorkItem(dir_name_from,
dir_name_to.ToWStringHack(), dir_name_to,
temp_dir_.ToWStringHack(), temp_dir_,
WorkItem::ALWAYS)); WorkItem::ALWAYS,
FilePath()));
EXPECT_TRUE(work_item->Do()); EXPECT_TRUE(work_item->Do());
} }
......
...@@ -23,11 +23,11 @@ WorkItem::~WorkItem() { ...@@ -23,11 +23,11 @@ WorkItem::~WorkItem() {
} }
CopyTreeWorkItem* WorkItem::CreateCopyTreeWorkItem( CopyTreeWorkItem* WorkItem::CreateCopyTreeWorkItem(
const std::wstring& source_path, const FilePath& source_path,
const std::wstring& dest_path, const FilePath& dest_path,
const std::wstring& temp_dir, const FilePath& temp_dir,
CopyOverWriteOption overwrite_option, CopyOverWriteOption overwrite_option,
const std::wstring& alternative_path) { const FilePath& alternative_path) {
return new CopyTreeWorkItem(source_path, dest_path, temp_dir, return new CopyTreeWorkItem(source_path, dest_path, temp_dir,
overwrite_option, alternative_path); overwrite_option, alternative_path);
} }
......
...@@ -59,11 +59,11 @@ class WorkItem { ...@@ -59,11 +59,11 @@ class WorkItem {
// * If overwrite_option is NEW_NAME_IF_IN_USE, file is copied with an // * If overwrite_option is NEW_NAME_IF_IN_USE, file is copied with an
// alternate name specified by alternative_path. // alternate name specified by alternative_path.
static CopyTreeWorkItem* CreateCopyTreeWorkItem( static CopyTreeWorkItem* CreateCopyTreeWorkItem(
const std::wstring& source_path, const FilePath& source_path,
const std::wstring& dest_path, const FilePath& dest_path,
const std::wstring& temp_dir, const FilePath& temp_dir,
CopyOverWriteOption overwrite_option, CopyOverWriteOption overwrite_option,
const std::wstring& alternative_path = L""); const FilePath& alternative_path);
// Create a CreateDirWorkItem that creates a directory at the given path. // Create a CreateDirWorkItem that creates a directory at the given path.
static CreateDirWorkItem* CreateCreateDirWorkItem(const FilePath& path); static CreateDirWorkItem* CreateCreateDirWorkItem(const FilePath& path);
......
...@@ -78,11 +78,11 @@ WorkItem* WorkItemList::AddCopyTreeWorkItem( ...@@ -78,11 +78,11 @@ WorkItem* WorkItemList::AddCopyTreeWorkItem(
const std::wstring& temp_dir, const std::wstring& temp_dir,
CopyOverWriteOption overwrite_option, CopyOverWriteOption overwrite_option,
const std::wstring& alternative_path) { const std::wstring& alternative_path) {
WorkItem* item = WorkItem::CreateCopyTreeWorkItem(source_path, WorkItem* item = WorkItem::CreateCopyTreeWorkItem(FilePath(source_path),
dest_path, FilePath(dest_path),
temp_dir, FilePath(temp_dir),
overwrite_option, overwrite_option,
alternative_path); FilePath(alternative_path));
AddWorkItem(item); AddWorkItem(item);
return 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