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

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

Issue 16392011: Move FileEnumerator to its own file, do some refactoring. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix incorrect includes Created 7 years, 6 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"
19 #include "base/win/registry.h" 20 #include "base/win/registry.h"
20 #include "base/string_util.h" 21 #include "base/string_util.h"
21 22
22 // The moves-pending-reboot is a MULTISZ registry key in the HKLM part of the 23 // The moves-pending-reboot is a MULTISZ registry key in the HKLM part of the
23 // registry. 24 // registry.
24 const wchar_t kSessionManagerKey[] = 25 const wchar_t kSessionManagerKey[] =
25 L"SYSTEM\\CurrentControlSet\\Control\\Session Manager"; 26 L"SYSTEM\\CurrentControlSet\\Control\\Session Manager";
26 const wchar_t kPendingFileRenameOps[] = L"PendingFileRenameOperations"; 27 const wchar_t kPendingFileRenameOps[] = L"PendingFileRenameOperations";
27 28
28 namespace { 29 namespace {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 } 110 }
110 // Confirm it is a directory 111 // Confirm it is a directory
111 if (!(dir_attributes & FILE_ATTRIBUTE_DIRECTORY)) { 112 if (!(dir_attributes & FILE_ATTRIBUTE_DIRECTORY)) {
112 LOG(ERROR) << "Scheduled directory is not a directory: " << dir_name; 113 LOG(ERROR) << "Scheduled directory is not a directory: " << dir_name;
113 return false; 114 return false;
114 } 115 }
115 116
116 // First schedule all the normal files for deletion. 117 // First schedule all the normal files for deletion.
117 { 118 {
118 bool success = true; 119 bool success = true;
119 file_util::FileEnumerator file_enum(base::FilePath(dir_name), false, 120 base::FileEnumerator file_enum(base::FilePath(dir_name), false,
120 file_util::FileEnumerator::FILES); 121 base::FileEnumerator::FILES);
121 for (base::FilePath file = file_enum.Next(); !file.empty(); 122 for (base::FilePath file = file_enum.Next(); !file.empty();
122 file = file_enum.Next()) { 123 file = file_enum.Next()) {
123 success = ScheduleFileSystemEntityForDeletion(file.value().c_str()); 124 success = ScheduleFileSystemEntityForDeletion(file.value().c_str());
124 if (!success) { 125 if (!success) {
125 LOG(ERROR) << "Failed to schedule file for deletion: " << file.value(); 126 LOG(ERROR) << "Failed to schedule file for deletion: " << file.value();
126 return false; 127 return false;
127 } 128 }
128 } 129 }
129 } 130 }
130 131
131 // Then recurse to all the subdirectories. 132 // Then recurse to all the subdirectories.
132 { 133 {
133 bool success = true; 134 bool success = true;
134 file_util::FileEnumerator dir_enum(base::FilePath(dir_name), false, 135 base::FileEnumerator dir_enum(base::FilePath(dir_name), false,
135 file_util::FileEnumerator::DIRECTORIES); 136 base::FileEnumerator::DIRECTORIES);
136 for (base::FilePath sub_dir = dir_enum.Next(); !sub_dir.empty(); 137 for (base::FilePath sub_dir = dir_enum.Next(); !sub_dir.empty();
137 sub_dir = dir_enum.Next()) { 138 sub_dir = dir_enum.Next()) {
138 success = ScheduleDirectoryForDeletion(sub_dir.value().c_str()); 139 success = ScheduleDirectoryForDeletion(sub_dir.value().c_str());
139 if (!success) { 140 if (!success) {
140 LOG(ERROR) << "Failed to schedule subdirectory for deletion: " 141 LOG(ERROR) << "Failed to schedule subdirectory for deletion: "
141 << sub_dir.value(); 142 << sub_dir.value();
142 return false; 143 return false;
143 } 144 }
144 } 145 }
145 } 146 }
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 ERROR_SUCCESS); 384 ERROR_SUCCESS);
384 } 385 }
385 std::vector<char> buffer; 386 std::vector<char> buffer;
386 StringArrayToMultiSZBytes(strings_to_keep, &buffer); 387 StringArrayToMultiSZBytes(strings_to_keep, &buffer);
387 DCHECK_GT(buffer.size(), 0U); 388 DCHECK_GT(buffer.size(), 0U);
388 if (buffer.empty()) 389 if (buffer.empty())
389 return false; 390 return false;
390 return (session_manager_key.WriteValue(kPendingFileRenameOps, &buffer[0], 391 return (session_manager_key.WriteValue(kPendingFileRenameOps, &buffer[0],
391 buffer.size(), REG_MULTI_SZ) == ERROR_SUCCESS); 392 buffer.size(), REG_MULTI_SZ) == ERROR_SUCCESS);
392 } 393 }
OLDNEW
« no previous file with comments | « chrome/installer/test/alternate_version_generator.cc ('k') | chrome/installer/util/duplicate_tree_detector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698