Base: Don't check for thread restrictions when closing a file doesn't do IO.

Also, clarify the File API a little more.

BUG=322664
R=thakis@chromium.org

Review URL: https://codereview.chromium.org/172673002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@252585 0039d316-1c4b-4281-b951-d872f2087c98


CrOS-Libchrome-Original-Commit: 48abb285fb4cd2c8fab6d01f26bb78700404a01f
diff --git a/base/files/file.h b/base/files/file.h
index a8cb16c..8597473 100644
--- a/base/files/file.h
+++ b/base/files/file.h
@@ -171,7 +171,11 @@
   // FLAG_CREATE_ALWAYS), and false otherwise.
   bool created() const { return created_; }
 
-  // Returns the OS result of opening this file.
+  // Returns the OS result of opening this file. Note that the way to verify
+  // the success of the operation is to use IsValid(), not this method:
+  //   File file(name, flags);
+  //   if (!file.IsValid())
+  //     return;
   Error error_details() const { return error_details_; }
 
   PlatformFile GetPlatformFile() const { return file_; }
diff --git a/base/files/file_posix.cc b/base/files/file_posix.cc
index a37de53..a62ad98 100644
--- a/base/files/file_posix.cc
+++ b/base/files/file_posix.cc
@@ -217,10 +217,10 @@
 }
 
 void File::Close() {
-  base::ThreadRestrictions::AssertIOAllowed();
   if (!IsValid())
     return;
 
+  base::ThreadRestrictions::AssertIOAllowed();
   if (!IGNORE_EINTR(close(file_)))
     file_ = kInvalidPlatformFileValue;
 }