Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(386)

Unified Diff: base/file_util.cc

Issue 16805: Move Contains() method to file_utils, stop relying on in extensions_protocol (Closed)
Patch Set: Review feedback Created 11 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/file_util.cc
diff --git a/base/file_util.cc b/base/file_util.cc
index fe7b6947167655a52feda98c25f6883d3867c883..078e3afa2e5ac6c2271fb9436c18ec16d2e2db75 100644
--- a/base/file_util.cc
+++ b/base/file_util.cc
@@ -276,6 +276,33 @@ bool CloseFile(FILE* file) {
return fclose(file) == 0;
}
+bool ContainsPath(const FilePath &parent, const FilePath& child) {
+ FilePath abs_parent = FilePath(parent);
+ FilePath abs_child = FilePath(child);
+
+ if (!file_util::AbsolutePath(&abs_parent) ||
+ !file_util::AbsolutePath(&abs_child))
+ return false;
+
+#if defined(OS_WIN)
+ // file_util::AbsolutePath() does not flatten case on Windows, so we must do
+ // a case-insensitive compare.
+ if (!StartsWith(abs_child.value(), abs_parent.value(), false))
+#else
Erik does not do reviews 2009/01/12 17:14:05 #else if defined(OS_POSIX)
+ if (!StartsWithASCII(abs_child.value(), abs_parent.value(), true))
Erik does not do reviews 2009/01/12 17:14:05 Put a comment / TODO / bug in here to reference th
+#endif
+ return false;
+
+ // file_util::AbsolutePath() normalizes '/' to '\' on Windows, so we only need
+ // to check kSeparators[0].
+ if (abs_child.value().length() <= abs_parent.value().length() ||
+ abs_child.value()[abs_parent.value().length()] !=
+ FilePath::kSeparators[0])
+ return false;
+
+ return true;
+}
+
///////////////////////////////////////////////
// MemoryMappedFile

Powered by Google App Engine
This is Rietveld 408576698