summaryrefslogtreecommitdiffstats
path: root/chromium/base/files/file_util.h
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2020-01-20 13:40:20 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2020-01-22 12:41:23 +0000
commit7961cea6d1041e3e454dae6a1da660b453efd238 (patch)
treec0eeb4a9ff9ba32986289c1653d9608e53ccb444 /chromium/base/files/file_util.h
parentb7034d0803538058e5c9d904ef03cf5eab34f6ef (diff)
BASELINE: Update Chromium to 78.0.3904.130
Change-Id: If185e0c0061b3437531c97c9c8c78f239352a68b Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/base/files/file_util.h')
-rw-r--r--chromium/base/files/file_util.h58
1 files changed, 45 insertions, 13 deletions
diff --git a/chromium/base/files/file_util.h b/chromium/base/files/file_util.h
index a40289e33a5..59fbf44e6e0 100644
--- a/chromium/base/files/file_util.h
+++ b/chromium/base/files/file_util.h
@@ -12,6 +12,7 @@
#include <stdint.h>
#include <stdio.h>
+#include <limits>
#include <set>
#include <string>
#include <vector>
@@ -186,12 +187,11 @@ BASE_EXPORT bool ReadFileToStringWithMaxSize(const FilePath& path,
BASE_EXPORT bool ReadFromFD(int fd, char* buffer, size_t bytes);
// Performs the same function as CreateAndOpenTemporaryFileInDir(), but returns
-// the file-descriptor directly, rather than wrapping it into a FILE. Returns
-// -1 on failure.
-BASE_EXPORT int CreateAndOpenFdForTemporaryFileInDir(const FilePath& dir,
- FilePath* path);
+// the file-descriptor wrapped in a ScopedFD, rather than wrapped in a FILE.
+BASE_EXPORT ScopedFD CreateAndOpenFdForTemporaryFileInDir(const FilePath& dir,
+ FilePath* path);
-#endif // OS_POSIX || OS_FUCHSIA
+#endif // defined(OS_POSIX) || defined(OS_FUCHSIA)
#if defined(OS_POSIX)
@@ -398,15 +398,19 @@ BASE_EXPORT bool GetCurrentDirectory(FilePath* path);
// Sets the current working directory for the process.
BASE_EXPORT bool SetCurrentDirectory(const FilePath& path);
-// Attempts to find a number that can be appended to the |path| to make it
-// unique. If |path| does not exist, 0 is returned. If it fails to find such
-// a number, -1 is returned. If |suffix| is not empty, also checks the
-// existence of it with the given suffix.
-BASE_EXPORT int GetUniquePathNumber(const FilePath& path,
- const FilePath::StringType& suffix);
+// The largest value attempted by GetUniquePath{Number,}.
+enum { kMaxUniqueFiles = 100 };
+
+// Returns the number N that makes |path| unique when formatted as " (N)" in a
+// suffix to its basename before any file extension, where N is a number between
+// 1 and 100 (inclusive). Returns 0 if |path| does not exist (meaning that it is
+// unique as-is), or -1 if no such number can be found.
+BASE_EXPORT int GetUniquePathNumber(const FilePath& path);
-// If file at |path| already exists, modifies filename portion of |path| to
-// return unique path.
+// Returns |path| if it does not exist. Otherwise, returns |path| with the
+// suffix " (N)" appended to its basename before any file extension, where N is
+// a number between 1 and 100 (inclusive). Returns an empty path if no such
+// number can be found.
BASE_EXPORT FilePath GetUniquePath(const FilePath& path);
// Sets the given |fd| to non-blocking mode.
@@ -414,6 +418,31 @@ BASE_EXPORT FilePath GetUniquePath(const FilePath& path);
// false.
BASE_EXPORT bool SetNonBlocking(int fd);
+// Hints the OS to prefetch the first |max_bytes| of |file_path| into its cache.
+//
+// If called at the appropriate time, this can reduce the latency incurred by
+// feature code that needs to read the file.
+//
+// |max_bytes| specifies how many bytes should be pre-fetched. It may exceed the
+// file's size. Passing in std::numeric_limits<int64_t>::max() is a convenient
+// way to get the entire file pre-fetched.
+//
+// |is_executable| specifies whether the file is to be prefetched as
+// executable code or as data. Windows treats the file backed pages in RAM
+// differently, and specifying the wrong value results in two copies in RAM.
+//
+// Returns false if prefetching definitely failed. A return value of true does
+// not guarantee that the entire desired range was prefetched.
+//
+// Calling this before using ::LoadLibrary() on Windows is more efficient memory
+// wise, but we must be sure no other threads try to LoadLibrary() the file
+// while we are doing the mapping and prefetching, or the process will get a
+// private copy of the DLL via COW.
+BASE_EXPORT bool PreReadFile(
+ const FilePath& file_path,
+ bool is_executable,
+ int64_t max_bytes = std::numeric_limits<int64_t>::max());
+
#if defined(OS_POSIX) || defined(OS_FUCHSIA)
// Creates a pipe. Returns true on success, otherwise false.
@@ -515,6 +544,9 @@ BASE_EXPORT bool CopyAndDeleteDirectory(const FilePath& from_path,
const FilePath& to_path);
#endif // defined(OS_WIN)
+// Used by PreReadFile() when no kernel support for prefetching is available.
+bool PreReadFileSlow(const FilePath& file_path, int64_t max_bytes);
+
} // namespace internal
} // namespace base