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

Side by Side Diff: trunk/src/chrome/installer/util/delete_after_reboot_helper.cc

Issue 14824006: Revert 198820 "Move FileEnumerator to its own file, do some refa..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 // This file defines helper methods used to schedule files for deletion 5 // This file defines helper methods used to schedule files for deletion
6 // on next reboot. The code here is heavily borrowed and simplified from 6 // on next reboot. The code here is heavily borrowed and simplified from
7 // http://code.google.com/p/omaha/source/browse/trunk/common/file.cc and 7 // http://code.google.com/p/omaha/source/browse/trunk/common/file.cc and
8 // http://code.google.com/p/omaha/source/browse/trunk/common/utils.cc 8 // http://code.google.com/p/omaha/source/browse/trunk/common/utils.cc
9 // 9 //
10 // This implementation really is not fast, so do not use it where that will 10 // This implementation really is not fast, so do not use it where that will
11 // matter. 11 // matter.
12 12
13 #include "chrome/installer/util/delete_after_reboot_helper.h" 13 #include "chrome/installer/util/delete_after_reboot_helper.h"
14 14
15 #include <string> 15 #include <string>
16 #include <vector> 16 #include <vector>
17 17
18 #include "base/file_util.h" 18 #include "base/file_util.h"
19 #include "base/files/file_enumerator.h"
20 #include "base/win/registry.h" 19 #include "base/win/registry.h"
21 #include "base/string_util.h" 20 #include "base/string_util.h"
22 21
23 // The moves-pending-reboot is a MULTISZ registry key in the HKLM part of the 22 // The moves-pending-reboot is a MULTISZ registry key in the HKLM part of the
24 // registry. 23 // registry.
25 const wchar_t kSessionManagerKey[] = 24 const wchar_t kSessionManagerKey[] =
26 L"SYSTEM\\CurrentControlSet\\Control\\Session Manager"; 25 L"SYSTEM\\CurrentControlSet\\Control\\Session Manager";
27 const wchar_t kPendingFileRenameOps[] = L"PendingFileRenameOperations"; 26 const wchar_t kPendingFileRenameOps[] = L"PendingFileRenameOperations";
28 27
29 namespace { 28 namespace {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 } 109 }
111 // Confirm it is a directory 110 // Confirm it is a directory
112 if (!(dir_attributes & FILE_ATTRIBUTE_DIRECTORY)) { 111 if (!(dir_attributes & FILE_ATTRIBUTE_DIRECTORY)) {
113 LOG(ERROR) << "Scheduled directory is not a directory: " << dir_name; 112 LOG(ERROR) << "Scheduled directory is not a directory: " << dir_name;
114 return false; 113 return false;
115 } 114 }
116 115
117 // First schedule all the normal files for deletion. 116 // First schedule all the normal files for deletion.
118 { 117 {
119 bool success = true; 118 bool success = true;
120 base::FileEnumerator file_enum(base::FilePath(dir_name), false, 119 file_util::FileEnumerator file_enum(base::FilePath(dir_name), false,
121 base::FileEnumerator::FILES); 120 file_util::FileEnumerator::FILES);
122 for (base::FilePath file = file_enum.Next(); !file.empty(); 121 for (base::FilePath file = file_enum.Next(); !file.empty();
123 file = file_enum.Next()) { 122 file = file_enum.Next()) {
124 success = ScheduleFileSystemEntityForDeletion(file.value().c_str()); 123 success = ScheduleFileSystemEntityForDeletion(file.value().c_str());
125 if (!success) { 124 if (!success) {
126 LOG(ERROR) << "Failed to schedule file for deletion: " << file.value(); 125 LOG(ERROR) << "Failed to schedule file for deletion: " << file.value();
127 return false; 126 return false;
128 } 127 }
129 } 128 }
130 } 129 }
131 130
132 // Then recurse to all the subdirectories. 131 // Then recurse to all the subdirectories.
133 { 132 {
134 bool success = true; 133 bool success = true;
135 base::FileEnumerator dir_enum(base::FilePath(dir_name), false, 134 file_util::FileEnumerator dir_enum(base::FilePath(dir_name), false,
136 base::FileEnumerator::DIRECTORIES); 135 file_util::FileEnumerator::DIRECTORIES);
137 for (base::FilePath sub_dir = dir_enum.Next(); !sub_dir.empty(); 136 for (base::FilePath sub_dir = dir_enum.Next(); !sub_dir.empty();
138 sub_dir = dir_enum.Next()) { 137 sub_dir = dir_enum.Next()) {
139 success = ScheduleDirectoryForDeletion(sub_dir.value().c_str()); 138 success = ScheduleDirectoryForDeletion(sub_dir.value().c_str());
140 if (!success) { 139 if (!success) {
141 LOG(ERROR) << "Failed to schedule subdirectory for deletion: " 140 LOG(ERROR) << "Failed to schedule subdirectory for deletion: "
142 << sub_dir.value(); 141 << sub_dir.value();
143 return false; 142 return false;
144 } 143 }
145 } 144 }
146 } 145 }
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 ERROR_SUCCESS); 383 ERROR_SUCCESS);
385 } 384 }
386 std::vector<char> buffer; 385 std::vector<char> buffer;
387 StringArrayToMultiSZBytes(strings_to_keep, &buffer); 386 StringArrayToMultiSZBytes(strings_to_keep, &buffer);
388 DCHECK_GT(buffer.size(), 0U); 387 DCHECK_GT(buffer.size(), 0U);
389 if (buffer.empty()) 388 if (buffer.empty())
390 return false; 389 return false;
391 return (session_manager_key.WriteValue(kPendingFileRenameOps, &buffer[0], 390 return (session_manager_key.WriteValue(kPendingFileRenameOps, &buffer[0],
392 buffer.size(), REG_MULTI_SZ) == ERROR_SUCCESS); 391 buffer.size(), REG_MULTI_SZ) == ERROR_SUCCESS);
393 } 392 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698