Index: net/disk_cache/simple/simple_util_win.cc |
diff --git a/net/disk_cache/simple/simple_util_win.cc b/net/disk_cache/simple/simple_util_win.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a99b8c1f0025fcc64c31f85a79fc2c358b9289fa |
--- /dev/null |
+++ b/net/disk_cache/simple/simple_util_win.cc |
@@ -0,0 +1,44 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "net/disk_cache/simple/simple_util.h" |
+ |
+#include <windows.h> |
+ |
+#include "base/files/file_util.h" |
+#include "base/format_macros.h" |
+#include "base/rand_util.h" |
+#include "base/strings/stringprintf.h" |
+#include "net/disk_cache/cache_util.h" |
+ |
+namespace disk_cache { |
+namespace simple_util { |
+ |
+bool SimpleCacheDeleteFile(const base::FilePath& path) { |
+ // Even if a file was opened with FLAG_SHARE_DELETE, it is not possible to |
+ // create a new file with the same name until the original file is actually |
+ // deleted. To allow new files to be created with the new name right away, we |
+ // rename the file to a random name before deleting it. |
mmenke
2014/10/28 23:58:36
nit: Don't use we in comments.
gavinp
2014/10/29 03:12:25
Done.
|
+ |
+ // Why a random name? Because if the name was derived from our original name, |
+ // then churn on a particular cache entry could cause flakey behaviour. |
mmenke
2014/10/28 23:58:36
Hrm...I'm not sure if I should whine about valid b
gavinp
2014/10/29 03:12:25
In the library in the Cambridge office, there's a
|
+ |
+ // TODO(gaivnp): Ensure we clean up these "todelete_" files on periodic |
mmenke
2014/10/28 23:58:36
nit: Don't use we.
gavinp
2014/10/29 03:12:25
Done.
|
+ // directory sweeps. |
+ const base::FilePath rename_target = |
+ path.DirName().AppendASCII(base::StringPrintf("todelete_%016" PRIx64, |
+ base::RandUint64())); |
+ |
+ const bool rename_succeeded = MoveFile(path.value().c_str(), |
mmenke
2014/10/28 23:58:36
Or if I should whine about the bonus consts, which
gavinp
2014/10/29 03:12:25
This is a challenging call. The rule in our coding
|
+ rename_target.value().c_str()); |
+ if (rename_succeeded) |
+ return DeleteCacheFile(rename_target); |
+ |
+ // The rename did not succeed, so we will fall back to deleting the file in |
+ // place, which might cause some flake. |
mmenke
2014/10/28 23:58:36
nit: Don't use we in comments.
gavinp
2014/10/29 03:12:25
Done.
|
+ return DeleteCacheFile(path); |
+} |
+ |
+} // namespace simple_util |
+} // namespace disk_cache |