Chromium Code Reviews| 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 iters = 25; |
|
Paweł Hajdan Jr.
2012/01/03 08:06:46
nit: No abbreviations, also if this is a constant
| |
| 67 const base::TimeDelta kTimeout = base::TimeDelta::FromSeconds(10) / iters; | |
| 67 | 68 |
| 68 if (!file_util::PathExists(file)) | 69 if (!file_util::PathExists(file)) |
| 69 return true; | 70 return true; |
| 70 | 71 |
| 71 // Sometimes Delete fails, so try a few more times. Divide the timeout | 72 // 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 | 73 // into short chunks, so that if a try succeeds, we won't delay the test |
| 73 // for too long. | 74 // for too long. |
| 74 for (int i = 0; i < 25; ++i) { | 75 for (int i = 0; i < iters; ++i) { |
| 75 if (file_util::Delete(file, recurse)) | 76 if (file_util::Delete(file, recurse)) |
| 76 return true; | 77 return true; |
| 77 base::PlatformThread::Sleep(kTimeoutMs / 25); | 78 base::PlatformThread::Sleep(kTimeout); |
| 78 } | 79 } |
| 79 return false; | 80 return false; |
| 80 } | 81 } |
| 81 | 82 |
| 82 bool EvictFileFromSystemCache(const FilePath& file) { | 83 bool EvictFileFromSystemCache(const FilePath& file) { |
| 83 // Request exclusive access to the file and overwrite it with no buffering. | 84 // Request exclusive access to the file and overwrite it with no buffering. |
| 84 base::win::ScopedHandle file_handle( | 85 base::win::ScopedHandle file_handle( |
| 85 CreateFile(file.value().c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, | 86 CreateFile(file.value().c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, |
| 86 OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, NULL)); | 87 OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, NULL)); |
| 87 if (!file_handle) | 88 if (!file_handle) |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 270 | 271 |
| 271 bool MakeFileUnreadable(const FilePath& path) { | 272 bool MakeFileUnreadable(const FilePath& path) { |
| 272 return DenyFilePermission(path, GENERIC_READ); | 273 return DenyFilePermission(path, GENERIC_READ); |
| 273 } | 274 } |
| 274 | 275 |
| 275 bool MakeFileUnwritable(const FilePath& path) { | 276 bool MakeFileUnwritable(const FilePath& path) { |
| 276 return DenyFilePermission(path, GENERIC_WRITE); | 277 return DenyFilePermission(path, GENERIC_WRITE); |
| 277 } | 278 } |
| 278 | 279 |
| 279 } // namespace file_util | 280 } // namespace file_util |
| OLD | NEW |