OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/test/test_file_util.h" | 5 #include "base/test/test_file_util.h" |
6 | 6 |
7 #include <aclapi.h> | 7 #include <aclapi.h> |
8 #include <shlwapi.h> | 8 #include <shlwapi.h> |
9 #include <windows.h> | 9 #include <windows.h> |
10 | 10 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 LocalFree(security_descriptor); | 56 LocalFree(security_descriptor); |
57 LocalFree(new_dacl); | 57 LocalFree(new_dacl); |
58 | 58 |
59 return rc == ERROR_SUCCESS; | 59 return rc == ERROR_SUCCESS; |
60 } | 60 } |
61 | 61 |
62 } // namespace | 62 } // namespace |
63 | 63 |
64 bool DieFileDie(const FilePath& file, bool recurse) { | 64 bool DieFileDie(const FilePath& file, bool recurse) { |
65 // It turns out that to not induce flakiness a long timeout is needed. | 65 // It turns out that to not induce flakiness a long timeout is needed. |
66 const int kTimeoutMs = 10000; | 66 const int kIterations = 25; |
| 67 const base::TimeDelta kTimeout = base::TimeDelta::FromSeconds(10) / |
| 68 kIterations; |
67 | 69 |
68 if (!file_util::PathExists(file)) | 70 if (!file_util::PathExists(file)) |
69 return true; | 71 return true; |
70 | 72 |
71 // Sometimes Delete fails, so try a few more times. Divide the timeout | 73 // Sometimes Delete fails, so try a few more times. Divide the timeout |
72 // into short chunks, so that if a try succeeds, we won't delay the test | 74 // into short chunks, so that if a try succeeds, we won't delay the test |
73 // for too long. | 75 // for too long. |
74 for (int i = 0; i < 25; ++i) { | 76 for (int i = 0; i < kIterations; ++i) { |
75 if (file_util::Delete(file, recurse)) | 77 if (file_util::Delete(file, recurse)) |
76 return true; | 78 return true; |
77 base::PlatformThread::Sleep(kTimeoutMs / 25); | 79 base::PlatformThread::Sleep(kTimeout); |
78 } | 80 } |
79 return false; | 81 return false; |
80 } | 82 } |
81 | 83 |
82 bool EvictFileFromSystemCache(const FilePath& file) { | 84 bool EvictFileFromSystemCache(const FilePath& file) { |
83 // Request exclusive access to the file and overwrite it with no buffering. | 85 // Request exclusive access to the file and overwrite it with no buffering. |
84 base::win::ScopedHandle file_handle( | 86 base::win::ScopedHandle file_handle( |
85 CreateFile(file.value().c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, | 87 CreateFile(file.value().c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, |
86 OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, NULL)); | 88 OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, NULL)); |
87 if (!file_handle) | 89 if (!file_handle) |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 | 272 |
271 bool MakeFileUnreadable(const FilePath& path) { | 273 bool MakeFileUnreadable(const FilePath& path) { |
272 return DenyFilePermission(path, GENERIC_READ); | 274 return DenyFilePermission(path, GENERIC_READ); |
273 } | 275 } |
274 | 276 |
275 bool MakeFileUnwritable(const FilePath& path) { | 277 bool MakeFileUnwritable(const FilePath& path) { |
276 return DenyFilePermission(path, GENERIC_WRITE); | 278 return DenyFilePermission(path, GENERIC_WRITE); |
277 } | 279 } |
278 | 280 |
279 } // namespace file_util | 281 } // namespace file_util |
OLD | NEW |