Add a flag to open files in share delete mode

BUG=86928
TEST=base_unittests


Review URL: http://codereview.chromium.org/7233007

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


CrOS-Libchrome-Original-Commit: ad0f81dd10c2322df4bf4dcbbe4719ea6d097a6f
diff --git a/base/platform_file.h b/base/platform_file.h
index 5b29e07..afe909a 100644
--- a/base/platform_file.h
+++ b/base/platform_file.h
@@ -50,6 +50,8 @@
 
   PLATFORM_FILE_WRITE_ATTRIBUTES = 8192,  // Used on Windows only
   PLATFORM_FILE_ENUMERATE = 16384,  // May enumerate directory
+
+  PLATFORM_FILE_SHARE_DELETE = 32768,  // Used on Windows only
 };
 
 // PLATFORM_FILE_ERROR_ACCESS_DENIED is returned when a call fails because of
diff --git a/base/platform_file_unittest.cc b/base/platform_file_unittest.cc
index 0bd4fb3..039c7ef 100644
--- a/base/platform_file_unittest.cc
+++ b/base/platform_file_unittest.cc
@@ -127,6 +127,42 @@
   EXPECT_FALSE(file_util::PathExists(file_path));
 }
 
+TEST(PlatformFile, DeleteOpenFile) {
+  ScopedTempDir temp_dir;
+  ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
+  FilePath file_path = temp_dir.path().AppendASCII("create_file_1");
+
+  // Create a file.
+  bool created = false;
+  base::PlatformFileError error_code = base::PLATFORM_FILE_OK;
+  base::PlatformFile file = base::CreatePlatformFile(
+      file_path,
+      base::PLATFORM_FILE_OPEN_ALWAYS |
+      base::PLATFORM_FILE_READ |
+      base::PLATFORM_FILE_SHARE_DELETE,
+      &created, &error_code);
+  EXPECT_NE(base::kInvalidPlatformFileValue, file);
+  EXPECT_TRUE(created);
+  EXPECT_EQ(base::PLATFORM_FILE_OK, error_code);
+
+  // Open an existing file and mark it as delete on close.
+  created = false;
+  base::PlatformFile same_file = base::CreatePlatformFile(
+      file_path,
+      base::PLATFORM_FILE_OPEN |
+      base::PLATFORM_FILE_DELETE_ON_CLOSE |
+      base::PLATFORM_FILE_READ,
+      &created, &error_code);
+  EXPECT_NE(base::kInvalidPlatformFileValue, file);
+  EXPECT_FALSE(created);
+  EXPECT_EQ(base::PLATFORM_FILE_OK, error_code);
+
+  // Close both handles and check that the file is gone.
+  base::ClosePlatformFile(file);
+  base::ClosePlatformFile(same_file);
+  EXPECT_FALSE(file_util::PathExists(file_path));
+}
+
 TEST(PlatformFile, ReadWritePlatformFile) {
   ScopedTempDir temp_dir;
   ASSERT_TRUE(temp_dir.CreateUniqueTempDir());