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

Side by Side Diff: base/file_util_win.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 | « base/file_util_mac.mm ('k') | chrome/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 "base/file_util.h" 5 #include "base/file_util.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <shellapi.h> 8 #include <shellapi.h>
9 #include <shlobj.h> 9 #include <shlobj.h>
10 #include <time.h> 10 #include <time.h>
(...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 // If |cur_file| is a directory, and we are doing recursive searching, add 685 // If |cur_file| is a directory, and we are doing recursive searching, add
686 // it to pending_paths_ so we scan it after we finish scanning this 686 // it to pending_paths_ so we scan it after we finish scanning this
687 // directory. 687 // directory.
688 pending_paths_.push(cur_file); 688 pending_paths_.push(cur_file);
689 } 689 }
690 return (file_type_ & FileEnumerator::DIRECTORIES) ? cur_file : Next(); 690 return (file_type_ & FileEnumerator::DIRECTORIES) ? cur_file : Next();
691 } 691 }
692 return (file_type_ & FileEnumerator::FILES) ? cur_file : Next(); 692 return (file_type_ & FileEnumerator::FILES) ? cur_file : Next();
693 } 693 }
694 694
695 bool EvictFileFromSystemCache(const FilePath path) {
696 // Overwrite it with no buffering.
697 ScopedHandle file(CreateFile(path.value().c_str(),
698 GENERIC_READ | GENERIC_WRITE,
699 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
700 OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, NULL));
701 if (!file.IsValid())
702 return false;
703
704 // Execute in chunks. It could be optimized. We want to do few of these since
705 // these operations will be slow without the cache.
706 char buffer[128 * 1024];
707 int total_bytes = 0;
708 DWORD bytes_read;
709 for (;;) {
710 if (!ReadFile(file, buffer, sizeof(buffer), &bytes_read, NULL))
711 return false;
712 if (bytes_read == 0)
713 break;
714
715 bool final = false;
716 if (bytes_read < sizeof(buffer))
717 final = true;
718
719 DWORD to_write = final ? sizeof(buffer) : bytes_read;
720
721 DWORD actual;
722 SetFilePointer(file, total_bytes, 0, FILE_BEGIN);
723 if (!WriteFile(file, buffer, to_write, &actual, NULL))
724 return false;
725 total_bytes += bytes_read;
726
727 if (final) {
728 SetFilePointer(file, total_bytes, 0, FILE_BEGIN);
729 SetEndOfFile(file);
730 break;
731 }
732 }
733 return true;
734 }
735
736 } // namespace file_util 695 } // namespace file_util
OLDNEW
« no previous file with comments | « base/file_util_mac.mm ('k') | chrome/SConscript » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698