This source file includes following definitions.
- path_
- Do
- Rollback
#include "chrome/installer/util/delete_reg_key_work_item.h"
#include <shlwapi.h>
#include "base/logging.h"
#include "base/win/registry.h"
using base::win::RegKey;
DeleteRegKeyWorkItem::~DeleteRegKeyWorkItem() {
}
DeleteRegKeyWorkItem::DeleteRegKeyWorkItem(HKEY predefined_root,
const std::wstring& path)
: predefined_root_(predefined_root),
path_(path) {
DCHECK(predefined_root);
DCHECK(!path.empty());
}
bool DeleteRegKeyWorkItem::Do() {
if (path_.empty())
return false;
RegistryKeyBackup backup;
if (!ignore_failure_) {
if (!backup.Initialize(predefined_root_, path_.c_str())) {
LOG(ERROR) << "Failed to backup destination for registry key copy.";
return false;
}
}
LONG result = SHDeleteKey(predefined_root_, path_.c_str());
if (result != ERROR_SUCCESS && result != ERROR_FILE_NOT_FOUND) {
LOG(ERROR) << "Failed to delete key at " << path_ << ", result: "
<< result;
return ignore_failure_;
}
backup_.swap(backup);
return true;
}
void DeleteRegKeyWorkItem::Rollback() {
if (ignore_failure_)
return;
LONG result = SHDeleteKey(predefined_root_, path_.c_str());
if (result != ERROR_SUCCESS && result != ERROR_FILE_NOT_FOUND) {
LOG(ERROR) << "Failed to delete key at " << path_ << " in rollback, "
"result: " << result;
}
if (!backup_.WriteTo(predefined_root_, path_.c_str()))
LOG(ERROR) << "Failed to restore key in rollback.";
}