| OLD | NEW |
| 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2008 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_file_util.h" | 5 #include "base/test_file_util.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/scoped_handle.h" |
| 12 | 13 |
| 13 namespace file_util { | 14 namespace file_util { |
| 14 | 15 |
| 15 bool EvictFileFromSystemCache(const wchar_t* file) { | 16 bool EvictFileFromSystemCache(const wchar_t* file) { |
| 16 // Request exclusive access to the file and overwrite it with no buffering. | 17 // Request exclusive access to the file and overwrite it with no buffering. |
| 17 win_util::ScopedHandle hfile( | 18 ScopedHandle hfile( |
| 18 CreateFile(file, GENERIC_READ | GENERIC_WRITE, 0, NULL, | 19 CreateFile(file, GENERIC_READ | GENERIC_WRITE, 0, NULL, |
| 19 OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, | 20 OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, |
| 20 NULL)); | 21 NULL)); |
| 21 if (!hfile) | 22 if (!hfile) |
| 22 return false; | 23 return false; |
| 23 | 24 |
| 24 // Execute in chunks. It could be optimized. We want to do few of these since | 25 // Execute in chunks. It could be optimized. We want to do few of these since |
| 25 // these opterations will be slow without the cache. | 26 // these opterations will be slow without the cache. |
| 26 char buffer[4096]; | 27 char buffer[4096]; |
| 27 int total_bytes = 0; | 28 int total_bytes = 0; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 EvictFileFromSystemCache(cur_dest_path.c_str()); | 92 EvictFileFromSystemCache(cur_dest_path.c_str()); |
| 92 } | 93 } |
| 93 } while (FindNextFile(fh, &fd)); | 94 } while (FindNextFile(fh, &fd)); |
| 94 | 95 |
| 95 FindClose(fh); | 96 FindClose(fh); |
| 96 return true; | 97 return true; |
| 97 } | 98 } |
| 98 | 99 |
| 99 } // namespace file_util | 100 } // namespace file_util |
| 100 | 101 |
| OLD | NEW |