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

Side by Side Diff: chrome/test/test_file_util.cc

Issue 9774: * Revert "Por rt flush_cache tool." (Closed)
Patch Set: Created 12 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 | « chrome/test/test_file_util.h ('k') | chrome/tools/perf/flush_cache/SConscript » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-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 <vector> 5 #include <vector>
6 #include <windows.h> 6 #include <windows.h>
7 7
8 #include "chrome/test/test_file_util.h" 8 #include "chrome/test/test_file_util.h"
9 9
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "chrome/common/win_util.h" 11 #include "chrome/common/win_util.h"
12 12
13 namespace file_util { 13 namespace file_util {
14 14
15 bool EvictFileFromSystemCache(const wchar_t* file) {
16 // Request exclusive access to the file and overwrite it with no buffering.
17 win_util::ScopedHandle hfile(
18 CreateFile(file, GENERIC_READ | GENERIC_WRITE, 0, NULL,
19 OPEN_EXISTING, FILE_FLAG_NO_BUFFERING,
20 NULL));
21 if (!hfile)
22 return false;
23
24 // 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 char buffer[4096];
27 int total_bytes = 0;
28 DWORD bytes_read;
29 for (;;) {
30 bytes_read = 0;
31 ReadFile(hfile, buffer, sizeof(buffer), &bytes_read, NULL);
32 if (bytes_read == 0)
33 break;
34
35 SetFilePointer(hfile, total_bytes, 0, FILE_BEGIN);
36 if (!WriteFile(hfile, buffer, bytes_read, &bytes_read, NULL))
37 return false;
38 total_bytes += bytes_read;
39 }
40 return true;
41 }
42
15 // Like CopyFileNoCache but recursively copies all files and subdirectories 43 // Like CopyFileNoCache but recursively copies all files and subdirectories
16 // in the given input directory to the output directory. 44 // in the given input directory to the output directory.
17 bool CopyRecursiveDirNoCache(const std::wstring& source_dir, 45 bool CopyRecursiveDirNoCache(const std::wstring& source_dir,
18 const std::wstring& dest_dir) { 46 const std::wstring& dest_dir) {
19 // Try to create the directory if it doesn't already exist. 47 // Try to create the directory if it doesn't already exist.
20 if (!CreateDirectory(dest_dir)) { 48 if (!CreateDirectory(dest_dir)) {
21 if (GetLastError() != ERROR_ALREADY_EXISTS) 49 if (GetLastError() != ERROR_ALREADY_EXISTS)
22 return false; 50 return false;
23 } 51 }
24 52
(...skipping 28 matching lines...) Expand all
53 // Copy the file. 81 // Copy the file.
54 if (!::CopyFile(cur_source_path.c_str(), cur_dest_path.c_str(), false)) { 82 if (!::CopyFile(cur_source_path.c_str(), cur_dest_path.c_str(), false)) {
55 FindClose(fh); 83 FindClose(fh);
56 return false; 84 return false;
57 } 85 }
58 86
59 // We don't check for errors from this function, often, we are copying 87 // We don't check for errors from this function, often, we are copying
60 // files that are in the repository, and they will have read-only set. 88 // files that are in the repository, and they will have read-only set.
61 // This will prevent us from evicting from the cache, but these don't 89 // This will prevent us from evicting from the cache, but these don't
62 // matter anyway. 90 // matter anyway.
63 file_util::EvictFileFromSystemCache(cur_dest_path.c_str()); 91 EvictFileFromSystemCache(cur_dest_path.c_str());
64 } 92 }
65 } while (FindNextFile(fh, &fd)); 93 } while (FindNextFile(fh, &fd));
66 94
67 FindClose(fh); 95 FindClose(fh);
68 return true; 96 return true;
69 } 97 }
70 98
71 } // namespace file_util 99 } // namespace file_util
72 100
OLDNEW
« no previous file with comments | « chrome/test/test_file_util.h ('k') | chrome/tools/perf/flush_cache/SConscript » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698