Skip to content

Commit

Permalink
Replace FilePath with base::FilePath.
Browse files Browse the repository at this point in the history
This is im preparation for removing the 'using" in file_path.h

Review URL: https://codereview.chromium.org/12286020

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@183021 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
brettw@chromium.org committed Feb 17, 2013
1 parent 9e784da commit 023ad6a
Show file tree
Hide file tree
Showing 75 changed files with 350 additions and 316 deletions.
2 changes: 2 additions & 0 deletions base/command_line_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "base/utf_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"

using base::FilePath;

// To test Windows quoting behavior, we use a string that has some backslashes
// and quotes.
// Consider the command-line argument: q\"bs1\bs2\\bs3q\\\"
Expand Down
4 changes: 4 additions & 0 deletions base/file_path_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// This macro constructs strings which can contain NULs.
#define FPS(x) FilePath::StringType(FPL(x), arraysize(FPL(x)) - 1)

namespace base {

struct UnaryTestData {
const FilePath::CharType* input;
const FilePath::CharType* expected;
Expand Down Expand Up @@ -1196,3 +1198,5 @@ TEST_F(FilePathTest, NormalizePathSeparators) {
}

#endif

} // namespace base
2 changes: 2 additions & 0 deletions base/file_util_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
// This macro helps avoid wrapped lines in the test structs.
#define FPL(x) FILE_PATH_LITERAL(x)

using base::FilePath;

namespace {

// To test that file_util::Normalize FilePath() deals with NTFS reparse points
Expand Down
9 changes: 5 additions & 4 deletions base/i18n/file_util_icu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ bool IsFilenameLegal(const string16& file_name) {
return IllegalCharacters::GetInstance()->containsNone(file_name);
}

void ReplaceIllegalCharactersInPath(FilePath::StringType* file_name,
void ReplaceIllegalCharactersInPath(base::FilePath::StringType* file_name,
char replace_char) {
DCHECK(file_name);

Expand Down Expand Up @@ -180,7 +180,8 @@ void ReplaceIllegalCharactersInPath(FilePath::StringType* file_name,
}
}

bool LocaleAwareCompareFilenames(const FilePath& a, const FilePath& b) {
bool LocaleAwareCompareFilenames(const base::FilePath& a,
const base::FilePath& b) {
#if defined(OS_WIN)
return LocaleAwareComparator::GetInstance()->Compare(a.value().c_str(),
b.value().c_str()) < 0;
Expand All @@ -200,13 +201,13 @@ bool LocaleAwareCompareFilenames(const FilePath& a, const FilePath& b) {
#endif
}

void NormalizeFileNameEncoding(FilePath* file_name) {
void NormalizeFileNameEncoding(base::FilePath* file_name) {
#if defined(OS_CHROMEOS)
std::string normalized_str;
if (base::ConvertToUtf8AndNormalize(file_name->BaseName().value(),
base::kCodepageUTF8,
&normalized_str)) {
*file_name = file_name->DirName().Append(FilePath(normalized_str));
*file_name = file_name->DirName().Append(base::FilePath(normalized_str));
}
#endif
}
Expand Down
18 changes: 9 additions & 9 deletions base/path_service_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace {
// Returns true if PathService::Get returns true and sets the path parameter
// to non-empty for the given PathService::DirType enumeration value.
bool ReturnsValidPath(int dir_type) {
FilePath path;
base::FilePath path;
bool result = PathService::Get(dir_type, &path);

// Some paths might not exist on some platforms in which case confirming
Expand Down Expand Up @@ -81,7 +81,7 @@ bool ReturnsValidPath(int dir_type) {
// of Windows. Checks that the function fails and that the returned path is
// empty.
bool ReturnsInvalidPath(int dir_type) {
FilePath path;
base::FilePath path;
bool result = PathService::Get(dir_type, &path);
return !result && path.empty();
}
Expand Down Expand Up @@ -152,13 +152,13 @@ TEST_F(PathServiceTest, Override) {
int my_special_key = 666;
base::ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
FilePath fake_cache_dir(temp_dir.path().AppendASCII("cache"));
base::FilePath fake_cache_dir(temp_dir.path().AppendASCII("cache"));
// PathService::Override should always create the path provided if it doesn't
// exist.
EXPECT_TRUE(PathService::Override(my_special_key, fake_cache_dir));
EXPECT_TRUE(file_util::PathExists(fake_cache_dir));

FilePath fake_cache_dir2(temp_dir.path().AppendASCII("cache2"));
base::FilePath fake_cache_dir2(temp_dir.path().AppendASCII("cache2"));
// PathService::OverrideAndCreateIfNeeded should obey the |create| parameter.
PathService::OverrideAndCreateIfNeeded(my_special_key,
fake_cache_dir2,
Expand All @@ -175,17 +175,17 @@ TEST_F(PathServiceTest, OverrideMultiple) {
int my_special_key = 666;
base::ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
FilePath fake_cache_dir1(temp_dir.path().AppendASCII("1"));
base::FilePath fake_cache_dir1(temp_dir.path().AppendASCII("1"));
EXPECT_TRUE(PathService::Override(my_special_key, fake_cache_dir1));
EXPECT_TRUE(file_util::PathExists(fake_cache_dir1));
ASSERT_EQ(1, file_util::WriteFile(fake_cache_dir1.AppendASCII("t1"), ".", 1));

FilePath fake_cache_dir2(temp_dir.path().AppendASCII("2"));
base::FilePath fake_cache_dir2(temp_dir.path().AppendASCII("2"));
EXPECT_TRUE(PathService::Override(my_special_key + 1, fake_cache_dir2));
EXPECT_TRUE(file_util::PathExists(fake_cache_dir2));
ASSERT_EQ(1, file_util::WriteFile(fake_cache_dir2.AppendASCII("t2"), ".", 1));

FilePath result;
base::FilePath result;
EXPECT_TRUE(PathService::Get(my_special_key, &result));
// Override might have changed the path representation but our test file
// should be still there.
Expand All @@ -199,14 +199,14 @@ TEST_F(PathServiceTest, RemoveOverride) {
// clear any overrides that might have been left from other tests.
PathService::RemoveOverride(base::DIR_TEMP);

FilePath original_user_data_dir;
base::FilePath original_user_data_dir;
EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &original_user_data_dir));
EXPECT_FALSE(PathService::RemoveOverride(base::DIR_TEMP));

base::ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
EXPECT_TRUE(PathService::Override(base::DIR_TEMP, temp_dir.path()));
FilePath new_user_data_dir;
base::FilePath new_user_data_dir;
EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &new_user_data_dir));
EXPECT_NE(original_user_data_dir, new_user_data_dir);

Expand Down
2 changes: 1 addition & 1 deletion base/perftimer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

static FILE* perf_log_file = NULL;

bool InitPerfLog(const FilePath& log_file) {
bool InitPerfLog(const base::FilePath& log_file) {
if (perf_log_file) {
// trying to initialize twice
NOTREACHED();
Expand Down
2 changes: 2 additions & 0 deletions base/platform_file_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "base/time.h"
#include "testing/gtest/include/gtest/gtest.h"

using base::FilePath;

namespace {

// Reads from a file the given number of bytes, or until EOF is reached.
Expand Down
18 changes: 9 additions & 9 deletions base/prefs/json_pref_store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
namespace {

// Some extensions we'll tack on to copies of the Preferences files.
const FilePath::CharType* kBadExtension = FILE_PATH_LITERAL("bad");
const base::FilePath::CharType* kBadExtension = FILE_PATH_LITERAL("bad");

// Differentiates file loading between origin thread and passed
// (aka file) thread.
Expand All @@ -36,7 +36,7 @@ class FileThreadDeserializer
origin_loop_proxy_(base::MessageLoopProxy::current()) {
}

void Start(const FilePath& path) {
void Start(const base::FilePath& path) {
DCHECK(origin_loop_proxy_->BelongsToCurrentThread());
sequenced_task_runner_->PostTask(
FROM_HERE,
Expand All @@ -45,7 +45,7 @@ class FileThreadDeserializer
}

// Deserializes JSON on the sequenced task runner.
void ReadFileAndReport(const FilePath& path) {
void ReadFileAndReport(const base::FilePath& path) {
DCHECK(sequenced_task_runner_->RunsTasksOnCurrentThread());

value_.reset(DoReading(path, &error_, &no_dir_));
Expand All @@ -61,7 +61,7 @@ class FileThreadDeserializer
delegate_->OnFileRead(value_.release(), error_, no_dir_);
}

static Value* DoReading(const FilePath& path,
static Value* DoReading(const base::FilePath& path,
PersistentPrefStore::PrefReadError* error,
bool* no_dir) {
int error_code;
Expand All @@ -74,7 +74,7 @@ class FileThreadDeserializer
}

static void HandleErrors(const Value* value,
const FilePath& path,
const base::FilePath& path,
int error_code,
const std::string& error_msg,
PersistentPrefStore::PrefReadError* error);
Expand All @@ -94,7 +94,7 @@ class FileThreadDeserializer
// static
void FileThreadDeserializer::HandleErrors(
const Value* value,
const FilePath& path,
const base::FilePath& path,
int error_code,
const std::string& error_msg,
PersistentPrefStore::PrefReadError* error) {
Expand Down Expand Up @@ -123,7 +123,7 @@ void FileThreadDeserializer::HandleErrors(
// We keep the old file for possible support and debugging assistance
// as well as to detect if they're seeing these errors repeatedly.
// TODO(erikkay) Instead, use the last known good file.
FilePath bad = path.ReplaceExtension(kBadExtension);
base::FilePath bad = path.ReplaceExtension(kBadExtension);

// If they've ever had a parse error before, put them in another bucket.
// TODO(erikkay) if we keep this error checking for very long, we may
Expand All @@ -141,7 +141,7 @@ void FileThreadDeserializer::HandleErrors(
} // namespace

scoped_refptr<base::SequencedTaskRunner> JsonPrefStore::GetTaskRunnerForFile(
const FilePath& filename,
const base::FilePath& filename,
base::SequencedWorkerPool* worker_pool) {
std::string token("json_pref_store-");
token.append(filename.AsUTF8Unsafe());
Expand All @@ -150,7 +150,7 @@ scoped_refptr<base::SequencedTaskRunner> JsonPrefStore::GetTaskRunnerForFile(
base::SequencedWorkerPool::BLOCK_SHUTDOWN);
}

JsonPrefStore::JsonPrefStore(const FilePath& filename,
JsonPrefStore::JsonPrefStore(const base::FilePath& filename,
base::SequencedTaskRunner* sequenced_task_runner)
: path_(filename),
sequenced_task_runner_(sequenced_task_runner),
Expand Down
30 changes: 15 additions & 15 deletions base/prefs/json_pref_store_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ class JsonPrefStoreTest : public testing::Test {
// The path to temporary directory used to contain the test operations.
base::ScopedTempDir temp_dir_;
// The path to the directory where the test data is stored.
FilePath data_dir_;
base::FilePath data_dir_;
// A message loop that we can use as the file thread message loop.
MessageLoop message_loop_;
};

// Test fallback behavior for a nonexistent file.
TEST_F(JsonPrefStoreTest, NonExistentFile) {
FilePath bogus_input_file = data_dir_.AppendASCII("read.txt");
base::FilePath bogus_input_file = data_dir_.AppendASCII("read.txt");
ASSERT_FALSE(file_util::PathExists(bogus_input_file));
scoped_refptr<JsonPrefStore> pref_store =
new JsonPrefStore(
Expand All @@ -74,8 +74,8 @@ TEST_F(JsonPrefStoreTest, NonExistentFile) {

// Test fallback behavior for an invalid file.
TEST_F(JsonPrefStoreTest, InvalidFile) {
FilePath invalid_file_original = data_dir_.AppendASCII("invalid.json");
FilePath invalid_file = temp_dir_.path().AppendASCII("invalid.json");
base::FilePath invalid_file_original = data_dir_.AppendASCII("invalid.json");
base::FilePath invalid_file = temp_dir_.path().AppendASCII("invalid.json");
ASSERT_TRUE(file_util::CopyFile(invalid_file_original, invalid_file));
scoped_refptr<JsonPrefStore> pref_store =
new JsonPrefStore(
Expand All @@ -86,7 +86,7 @@ TEST_F(JsonPrefStoreTest, InvalidFile) {

// The file should have been moved aside.
EXPECT_FALSE(file_util::PathExists(invalid_file));
FilePath moved_aside = temp_dir_.path().AppendASCII("invalid.bad");
base::FilePath moved_aside = temp_dir_.path().AppendASCII("invalid.bad");
EXPECT_TRUE(file_util::PathExists(moved_aside));
EXPECT_TRUE(file_util::TextContentsEqual(invalid_file_original,
moved_aside));
Expand All @@ -95,8 +95,8 @@ TEST_F(JsonPrefStoreTest, InvalidFile) {
// This function is used to avoid code duplication while testing synchronous and
// asynchronous version of the JsonPrefStore loading.
void RunBasicJsonPrefStoreTest(JsonPrefStore* pref_store,
const FilePath& output_file,
const FilePath& golden_output_file) {
const base::FilePath& output_file,
const base::FilePath& golden_output_file) {
const char kNewWindowsInTabs[] = "tabs.new_windows_in_tabs";
const char kMaxTabs[] = "tabs.max_tabs";
const char kLongIntPref[] = "long_int.pref";
Expand All @@ -112,10 +112,10 @@ void RunBasicJsonPrefStoreTest(JsonPrefStore* pref_store,
const char kSomeDirectory[] = "some_directory";

EXPECT_TRUE(pref_store->GetValue(kSomeDirectory, &actual));
FilePath::StringType path;
base::FilePath::StringType path;
EXPECT_TRUE(actual->GetAsString(&path));
EXPECT_EQ(FilePath::StringType(FILE_PATH_LITERAL("/usr/local/")), path);
FilePath some_path(FILE_PATH_LITERAL("/usr/sbin/"));
EXPECT_EQ(base::FilePath::StringType(FILE_PATH_LITERAL("/usr/local/")), path);
base::FilePath some_path(FILE_PATH_LITERAL("/usr/sbin/"));

pref_store->SetValue(kSomeDirectory, new StringValue(some_path.value()));
EXPECT_TRUE(pref_store->GetValue(kSomeDirectory, &actual));
Expand Down Expand Up @@ -163,7 +163,7 @@ TEST_F(JsonPrefStoreTest, Basic) {
temp_dir_.path().AppendASCII("write.json")));

// Test that the persistent value can be loaded.
FilePath input_file = temp_dir_.path().AppendASCII("write.json");
base::FilePath input_file = temp_dir_.path().AppendASCII("write.json");
ASSERT_TRUE(file_util::PathExists(input_file));
scoped_refptr<JsonPrefStore> pref_store =
new JsonPrefStore(
Expand Down Expand Up @@ -191,7 +191,7 @@ TEST_F(JsonPrefStoreTest, BasicAsync) {
temp_dir_.path().AppendASCII("write.json")));

// Test that the persistent value can be loaded.
FilePath input_file = temp_dir_.path().AppendASCII("write.json");
base::FilePath input_file = temp_dir_.path().AppendASCII("write.json");
ASSERT_TRUE(file_util::PathExists(input_file));
scoped_refptr<JsonPrefStore> pref_store =
new JsonPrefStore(
Expand Down Expand Up @@ -230,7 +230,7 @@ TEST_F(JsonPrefStoreTest, BasicAsync) {

// Tests asynchronous reading of the file when there is no file.
TEST_F(JsonPrefStoreTest, AsyncNonExistingFile) {
FilePath bogus_input_file = data_dir_.AppendASCII("read.txt");
base::FilePath bogus_input_file = data_dir_.AppendASCII("read.txt");
ASSERT_FALSE(file_util::PathExists(bogus_input_file));
scoped_refptr<JsonPrefStore> pref_store =
new JsonPrefStore(
Expand All @@ -251,7 +251,7 @@ TEST_F(JsonPrefStoreTest, AsyncNonExistingFile) {
}

TEST_F(JsonPrefStoreTest, NeedsEmptyValue) {
FilePath pref_file = temp_dir_.path().AppendASCII("write.json");
base::FilePath pref_file = temp_dir_.path().AppendASCII("write.json");

ASSERT_TRUE(file_util::CopyFile(
data_dir_.AppendASCII("read.need_empty_value.json"),
Expand Down Expand Up @@ -292,7 +292,7 @@ TEST_F(JsonPrefStoreTest, NeedsEmptyValue) {
RunLoop().RunUntilIdle();

// Compare to expected output.
FilePath golden_output_file =
base::FilePath golden_output_file =
data_dir_.AppendASCII("write.golden.need_empty_value.json");
ASSERT_TRUE(file_util::PathExists(golden_output_file));
EXPECT_TRUE(file_util::TextContentsEqual(golden_output_file, pref_file));
Expand Down
Loading

0 comments on commit 023ad6a

Please sign in to comment.