[go: nahoru, domu]

[TaskScheduler]: Add ScopedBlockingCall in ReadFileToStringWithMaxSize.

While OpenFile/CloseFile are already covered by ScopedBlockingCall,
this function does file reading operations (fread), which may block.
ScopedBlockingCall serves as a precise annotation of the scope that may/will
block for the scheduler. Since it supports nesting, there is no problem calling
CloseFile() in the same scope.

Bug: 874080
Change-Id: Id65de018cc20a2788d42d408c1c49052eed813c0
Reviewed-on: https://chromium-review.googlesource.com/1236393
Commit-Queue: Etienne Pierre-Doray <etiennep@chromium.org>
Reviewed-by: Nico Weber <thakis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#593180}
diff --git a/base/files/file_util.cc b/base/files/file_util.cc
index 109cb229c..73cee5b 100644
--- a/base/files/file_util.cc
+++ b/base/files/file_util.cc
@@ -19,6 +19,7 @@
 #include "base/strings/string_util.h"
 #include "base/strings/stringprintf.h"
 #include "base/strings/utf_string_conversions.h"
+#include "base/threading/scoped_blocking_call.h"
 #include "build/build_config.h"
 
 namespace base {
@@ -156,6 +157,7 @@
   std::string local_contents;
   local_contents.resize(chunk_size);
 
+  ScopedBlockingCall scoped_blocking_call(BlockingType::MAY_BLOCK);
   while ((bytes_read_this_pass = fread(&local_contents[bytes_read_so_far], 1,
                                        chunk_size, file)) > 0) {
     if ((max_size - bytes_read_so_far) < bytes_read_this_pass) {