diff options
author | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-10 02:04:40 +0000 |
---|---|---|
committer | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-10 02:04:40 +0000 |
commit | d9034ed2e96d3910c1f4d4d0f9ad3c7ce048679a (patch) | |
tree | cb4454406c639bc0aa5c5a520e5967619ac50109 /webkit | |
parent | 554efaa8b3220e675ad3743eca7f699ad52e2c82 (diff) | |
download | chromium_src-d9034ed2e96d3910c1f4d4d0f9ad3c7ce048679a.zip chromium_src-d9034ed2e96d3910c1f4d4d0f9ad3c7ce048679a.tar.gz chromium_src-d9034ed2e96d3910c1f4d4d0f9ad3c7ce048679a.tar.bz2 |
Define FilePath::NormalizePathSeparators on all platforms
I assume the method FilePath::NormalizeWindowsPathSeparators() is intentionally defined only on Windows, but recently I found myself trying to add a static method (named NormalizePathSeparators()) which calls NormalizeWindowsPathSeparators() or does nothing with platform ifdefs, and then found that there's another place defining the same static method.
Maybe we could just add the common method in FilePath then? It'd at least make the code cleaner at several callsites. I don't think this has visible negative performance impact with optimization build.
BUG=none
TEST=FilePathTest.NormalizePathSeparators and all other existing tests
Review URL: https://chromiumcodereview.appspot.com/9320059
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@121380 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/fileapi/file_system_util.cc | 8 | ||||
-rw-r--r-- | webkit/fileapi/isolated_context.cc | 6 | ||||
-rw-r--r-- | webkit/fileapi/isolated_context_unittest.cc | 16 | ||||
-rw-r--r-- | webkit/fileapi/obfuscated_file_util_unittest.cc | 4 |
4 files changed, 9 insertions, 25 deletions
diff --git a/webkit/fileapi/file_system_util.cc b/webkit/fileapi/file_system_util.cc index 434c15e..e0c16a5 100644 --- a/webkit/fileapi/file_system_util.cc +++ b/webkit/fileapi/file_system_util.cc @@ -86,12 +86,8 @@ bool CrackFileSystemURL(const GURL& url, GURL* origin_url, FileSystemType* type, if (type) *type = file_system_type; if (file_path) -#if defined(OS_WIN) - *file_path = FilePath(base::SysUTF8ToWide(path)). - NormalizeWindowsPathSeparators().StripTrailingSeparators(); -#elif defined(OS_POSIX) - *file_path = FilePath(path).StripTrailingSeparators(); -#endif + *file_path = FilePath::FromUTF8Unsafe(path). + NormalizePathSeparators().StripTrailingSeparators(); return true; } diff --git a/webkit/fileapi/isolated_context.cc b/webkit/fileapi/isolated_context.cc index 11b5eb7..64a3a02 100644 --- a/webkit/fileapi/isolated_context.cc +++ b/webkit/fileapi/isolated_context.cc @@ -36,11 +36,7 @@ std::string IsolatedContext::RegisterIsolatedFileSystem( // Register the basename -> fullpath map. (We only expose the basename // part to the user scripts) -#if defined(FILE_PATH_USES_WIN_SEPARATORS) - FilePath fullpath = iter->NormalizeWindowsPathSeparators(); -#else - FilePath fullpath = *iter; -#endif + FilePath fullpath = iter->NormalizePathSeparators(); FilePath basename = iter->BaseName(); // TODO(kinuko): Append a suffix or something if we have multiple pathnames // with the same basename. For now we only register the first one. diff --git a/webkit/fileapi/isolated_context_unittest.cc b/webkit/fileapi/isolated_context_unittest.cc index f367292..e32adef 100644 --- a/webkit/fileapi/isolated_context_unittest.cc +++ b/webkit/fileapi/isolated_context_unittest.cc @@ -31,21 +31,13 @@ const FilePath kTestPaths[] = { #endif }; -static FilePath NormalizePath(const FilePath& path) { -#if defined(FILE_PATH_USES_WIN_SEPARATORS) - return path.NormalizeWindowsPathSeparators(); -#else - return path; -#endif -} - } // namespace class IsolatedContextTest : public testing::Test { public: IsolatedContextTest() { for (size_t i = 0; i < arraysize(kTestPaths); ++i) - fileset_.insert(NormalizePath(kTestPaths[i])); + fileset_.insert(kTestPaths[i].NormalizePathSeparators()); } void SetUp() { @@ -88,7 +80,8 @@ TEST_F(IsolatedContextTest, RegisterAndRevokeTest) { FilePath cracked_path; ASSERT_TRUE(isolated_context()->CrackIsolatedPath( virtual_path, &cracked_id, &cracked_path)); - ASSERT_EQ(NormalizePath(kTestPaths[i]).value(), cracked_path.value()); + ASSERT_EQ(kTestPaths[i].NormalizePathSeparators().value(), + cracked_path.value()); ASSERT_EQ(id_, cracked_id); } @@ -138,7 +131,8 @@ TEST_F(IsolatedContextTest, CrackWithRelativePaths) { } ASSERT_TRUE(isolated_context()->CrackIsolatedPath( virtual_path, &cracked_id, &cracked_path)); - ASSERT_EQ(NormalizePath(kTestPaths[i].Append(relatives[j].path)).value(), + ASSERT_EQ(kTestPaths[i].Append(relatives[j].path) + .NormalizePathSeparators().value(), cracked_path.value()); ASSERT_EQ(id_, cracked_id); } diff --git a/webkit/fileapi/obfuscated_file_util_unittest.cc b/webkit/fileapi/obfuscated_file_util_unittest.cc index 51e30f6..cc21024 100644 --- a/webkit/fileapi/obfuscated_file_util_unittest.cc +++ b/webkit/fileapi/obfuscated_file_util_unittest.cc @@ -1200,9 +1200,7 @@ TEST_F(ObfuscatedFileUtilTest, TestMigration) { SCOPED_TRACE(testing::Message() << "Validating kMigrationTestPath " << i); const test::TestCaseRecord& test_case = test::kRegularTestCases[i]; FilePath local_data_path = new_root.Append(test_case.path); -#if defined(OS_WIN) - local_data_path = local_data_path.NormalizeWindowsPathSeparators(); -#endif + local_data_path = local_data_path.NormalizePathSeparators(); scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); base::PlatformFileInfo ofu_file_info; FilePath data_path; |