| OLD | NEW | 
|---|
| 1 // Copyright (c) 2008 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 <shlwapi.h> | 7 #include <shlwapi.h> | 
| 8 #include <windows.h> | 8 #include <windows.h> | 
| 9 | 9 | 
| 10 #include <vector> | 10 #include <vector> | 
| 11 | 11 | 
| 12 #include "base/file_path.h" | 12 #include "base/file_path.h" | 
| 13 #include "base/file_util.h" | 13 #include "base/file_util.h" | 
| 14 #include "base/logging.h" | 14 #include "base/logging.h" | 
| 15 #include "base/scoped_handle.h" | 15 #include "base/win/scoped_handle.h" | 
| 16 #include "base/threading/platform_thread.h" | 16 #include "base/threading/platform_thread.h" | 
| 17 | 17 | 
| 18 namespace file_util { | 18 namespace file_util { | 
| 19 | 19 | 
| 20 static const ptrdiff_t kOneMB = 1024 * 1024; | 20 static const ptrdiff_t kOneMB = 1024 * 1024; | 
| 21 | 21 | 
| 22 bool DieFileDie(const FilePath& file, bool recurse) { | 22 bool DieFileDie(const FilePath& file, bool recurse) { | 
| 23   // It turns out that to not induce flakiness a long timeout is needed. | 23   // It turns out that to not induce flakiness a long timeout is needed. | 
| 24   const int kTimeoutMs = 10000; | 24   const int kTimeoutMs = 10000; | 
| 25 | 25 | 
| 26   if (!file_util::PathExists(file)) | 26   if (!file_util::PathExists(file)) | 
| 27     return true; | 27     return true; | 
| 28 | 28 | 
| 29   // Sometimes Delete fails, so try a few more times. Divide the timeout | 29   // Sometimes Delete fails, so try a few more times. Divide the timeout | 
| 30   // into short chunks, so that if a try succeeds, we won't delay the test | 30   // into short chunks, so that if a try succeeds, we won't delay the test | 
| 31   // for too long. | 31   // for too long. | 
| 32   for (int i = 0; i < 25; ++i) { | 32   for (int i = 0; i < 25; ++i) { | 
| 33     if (file_util::Delete(file, recurse)) | 33     if (file_util::Delete(file, recurse)) | 
| 34       return true; | 34       return true; | 
| 35     base::PlatformThread::Sleep(kTimeoutMs / 25); | 35     base::PlatformThread::Sleep(kTimeoutMs / 25); | 
| 36   } | 36   } | 
| 37   return false; | 37   return false; | 
| 38 } | 38 } | 
| 39 | 39 | 
| 40 bool EvictFileFromSystemCache(const FilePath& file) { | 40 bool EvictFileFromSystemCache(const FilePath& file) { | 
| 41   // Request exclusive access to the file and overwrite it with no buffering. | 41   // Request exclusive access to the file and overwrite it with no buffering. | 
| 42   ScopedHandle file_handle( | 42   base::win::ScopedHandle file_handle( | 
| 43       CreateFile(file.value().c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, | 43       CreateFile(file.value().c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, | 
| 44                  OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, NULL)); | 44                  OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, NULL)); | 
| 45   if (!file_handle) | 45   if (!file_handle) | 
| 46     return false; | 46     return false; | 
| 47 | 47 | 
| 48   // Get some attributes to restore later. | 48   // Get some attributes to restore later. | 
| 49   BY_HANDLE_FILE_INFORMATION bhi = {0}; | 49   BY_HANDLE_FILE_INFORMATION bhi = {0}; | 
| 50   CHECK(::GetFileInformationByHandle(file_handle, &bhi)); | 50   CHECK(::GetFileInformationByHandle(file_handle, &bhi)); | 
| 51 | 51 | 
| 52   // Execute in chunks. It could be optimized. We want to do few of these since | 52   // Execute in chunks. It could be optimized. We want to do few of these since | 
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 225     if (read != arraysize(kIdentifier)) | 225     if (read != arraysize(kIdentifier)) | 
| 226       continue; | 226       continue; | 
| 227 | 227 | 
| 228     if (strcmp(kIdentifier, buffer) == 0) | 228     if (strcmp(kIdentifier, buffer) == 0) | 
| 229       return true; | 229       return true; | 
| 230   } | 230   } | 
| 231   return false; | 231   return false; | 
| 232 } | 232 } | 
| 233 | 233 | 
| 234 }  // namespace file_util | 234 }  // namespace file_util | 
| OLD | NEW | 
|---|