base: CrOS: Don't use blocking file read operations on procfs files

When reading procfs files we shouldn't use the base file operations as
they are annotated as MAY_BLOCK. This CL introduces an equivalent to
base::ReadFileToString which doesn't have any blocking annotations.

Bug: 1090623
Change-Id: I159f239caf1fe0613de9fdb92cd5fca687cb955b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2229153
Commit-Queue: Brian Geffon <[email protected]>
Reviewed-by: François Doray <[email protected]>
Cr-Commit-Position: refs/heads/master@{#780490}
diff --git a/base/files/file_util.h b/base/files/file_util.h
index 0d3a6511..08845c3e 100644
--- a/base/files/file_util.h
+++ b/base/files/file_util.h
@@ -245,6 +245,15 @@
 
 #if defined(OS_POSIX)
 
+// ReadFileToStringNonBlocking is identical to ReadFileToString except it
+// guarantees that it will not block. This guarantee is provided on POSIX by
+// opening the file as O_NONBLOCK. This variant should only be used on files
+// which are guaranteed not to block (such as kernel files). Or in situations
+// where a partial read would be acceptable because the backing store returned
+// EWOULDBLOCK.
+BASE_EXPORT bool ReadFileToStringNonBlocking(const base::FilePath& file,
+                                             std::string* ret);
+
 // Creates a symbolic link at |symlink| pointing to |target|.  Returns
 // false on failure.
 BASE_EXPORT bool CreateSymbolicLink(const FilePath& target,