Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1230)

Side by Side Diff: net/disk_cache/simple/simple_util_win.cc

Issue 651063002: Deflake Simple Cache backend on Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remediate Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/disk_cache/simple/simple_util_posix.cc ('k') | net/net.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "net/disk_cache/simple/simple_util.h"
6
7 #include <windows.h>
8
9 #include "base/files/file_util.h"
10 #include "base/format_macros.h"
11 #include "base/rand_util.h"
12 #include "base/strings/stringprintf.h"
13 #include "net/disk_cache/cache_util.h"
14
15 namespace disk_cache {
16 namespace simple_util {
17
18 bool SimpleCacheDeleteFile(const base::FilePath& path) {
19 // Even if a file was opened with FLAG_SHARE_DELETE, it is not possible to
20 // create a new file with the same name until the original file is actually
21 // deleted. To allow new files to be created with the new name right away, we
22 // 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.
23
24 // Why a random name? Because if the name was derived from our original name,
25 // 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
26
27 // 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.
28 // directory sweeps.
29 const base::FilePath rename_target =
30 path.DirName().AppendASCII(base::StringPrintf("todelete_%016" PRIx64,
31 base::RandUint64()));
32
33 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
34 rename_target.value().c_str());
35 if (rename_succeeded)
36 return DeleteCacheFile(rename_target);
37
38 // The rename did not succeed, so we will fall back to deleting the file in
39 // 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.
40 return DeleteCacheFile(path);
41 }
42
43 } // namespace simple_util
44 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/simple/simple_util_posix.cc ('k') | net/net.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698