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

Side by Side Diff: base/test_file_util_win.cc

Issue 159658: Remove duplication of DieFileDie, and move it to proper location. (Closed)
Patch Set: Created 11 years, 4 months 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 | « base/test_file_util_posix.cc ('k') | chrome/browser/download/save_page_uitest.cc » ('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) 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_path.h" 11 #include "base/file_path.h"
12 #include "base/file_util.h" 12 #include "base/file_util.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/platform_thread.h"
14 #include "base/scoped_handle.h" 15 #include "base/scoped_handle.h"
15 16
16 namespace file_util { 17 namespace file_util {
17 18
18 // We could use GetSystemInfo to get the page size, but this serves 19 // We could use GetSystemInfo to get the page size, but this serves
19 // our purpose fine since 4K is the page size on x86 as well as x64. 20 // our purpose fine since 4K is the page size on x86 as well as x64.
20 static const ptrdiff_t kPageSize = 4096; 21 static const ptrdiff_t kPageSize = 4096;
21 22
23 bool DieFileDie(const FilePath& file, bool recurse) {
24 // It turns out that to not induce flakiness a long timeout is needed.
25 const int kTimeoutMs = 10000;
26
27 if (!file_util::PathExists(file))
28 return true;
29
30 // Sometimes Delete fails, so try a few more times. Divide the timeout
31 // into short chunks, so that if a try succeeds, we won't delay the test
32 // for too long.
33 for (int i = 0; i < 25; ++i) {
34 if (file_util::Delete(file, recurse))
35 return true;
36 PlatformThread::Sleep(kTimeoutMs / 25);
37 }
38 return false;
39 }
40
22 bool EvictFileFromSystemCache(const FilePath& file) { 41 bool EvictFileFromSystemCache(const FilePath& file) {
23 // Request exclusive access to the file and overwrite it with no buffering. 42 // Request exclusive access to the file and overwrite it with no buffering.
24 ScopedHandle file_handle( 43 ScopedHandle file_handle(
25 CreateFile(file.value().c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, 44 CreateFile(file.value().c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL,
26 OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, NULL)); 45 OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, NULL));
27 if (!file_handle) 46 if (!file_handle)
28 return false; 47 return false;
29 48
30 // Get some attributes to restore later. 49 // Get some attributes to restore later.
31 BY_HANDLE_FILE_INFORMATION bhi = {0}; 50 BY_HANDLE_FILE_INFORMATION bhi = {0};
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 // matter anyway. 170 // matter anyway.
152 EvictFileFromSystemCache(FilePath::FromWStringHack(cur_dest_path)); 171 EvictFileFromSystemCache(FilePath::FromWStringHack(cur_dest_path));
153 } 172 }
154 } while (FindNextFile(fh, &fd)); 173 } while (FindNextFile(fh, &fd));
155 174
156 FindClose(fh); 175 FindClose(fh);
157 return true; 176 return true;
158 } 177 }
159 178
160 } // namespace file_util 179 } // namespace file_util
OLDNEW
« no previous file with comments | « base/test_file_util_posix.cc ('k') | chrome/browser/download/save_page_uitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698