Base: Make FileProxy automaticaly close the file on a worker thread.

This CL removes the restriction that callers should call Close before
deleting the object if they want to make sure the file is not closed
on the current thread.

BUG=322664
TEST=base_unittests

Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=263675

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

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


CrOS-Libchrome-Original-Commit: 2741d240bc6e677fd319b5145125a5e5942bbda7
diff --git a/base/files/file_proxy_unittest.cc b/base/files/file_proxy_unittest.cc
index bb7e6c3..7748923 100644
--- a/base/files/file_proxy_unittest.cc
+++ b/base/files/file_proxy_unittest.cc
@@ -14,6 +14,7 @@
 #include "base/memory/weak_ptr.h"
 #include "base/message_loop/message_loop.h"
 #include "base/threading/thread.h"
+#include "base/threading/thread_restrictions.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
 namespace base {
@@ -143,6 +144,21 @@
   EXPECT_FALSE(PathExists(test_path()));
 }
 
+TEST_F(FileProxyTest, CreateOrOpen_AbandonedCreate) {
+  bool prev = ThreadRestrictions::SetIOAllowed(false);
+  {
+    FileProxy proxy(file_task_runner());
+    proxy.CreateOrOpen(
+        test_path(),
+        File::FLAG_CREATE | File::FLAG_READ,
+        Bind(&FileProxyTest::DidCreateOrOpen, weak_factory_.GetWeakPtr()));
+  }
+  MessageLoop::current()->Run();
+  ThreadRestrictions::SetIOAllowed(prev);
+
+  EXPECT_TRUE(PathExists(test_path()));
+}
+
 TEST_F(FileProxyTest, Close) {
   // Creates a file.
   FileProxy proxy(file_task_runner());