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

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

Issue 1976443005: Revert of Add best-effort/allow rollback flags on WorkItem. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@simple_list_tests
Patch Set: Created 4 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/installer/util/delete_reg_value_work_item.h" 5 #include "chrome/installer/util/delete_reg_value_work_item.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/win/registry.h" 9 #include "base/win/registry.h"
10 #include "chrome/installer/util/logging_installer.h" 10 #include "chrome/installer/util/logging_installer.h"
(...skipping 11 matching lines...) Expand all
22 status_(DELETE_VALUE), 22 status_(DELETE_VALUE),
23 previous_type_(0) { 23 previous_type_(0) {
24 DCHECK(wow64_access == 0 || 24 DCHECK(wow64_access == 0 ||
25 wow64_access == KEY_WOW64_32KEY || 25 wow64_access == KEY_WOW64_32KEY ||
26 wow64_access == KEY_WOW64_64KEY); 26 wow64_access == KEY_WOW64_64KEY);
27 } 27 }
28 28
29 DeleteRegValueWorkItem::~DeleteRegValueWorkItem() { 29 DeleteRegValueWorkItem::~DeleteRegValueWorkItem() {
30 } 30 }
31 31
32 bool DeleteRegValueWorkItem::DoImpl() { 32 bool DeleteRegValueWorkItem::Do() {
33 DCHECK_EQ(DELETE_VALUE, status_); 33 if (status_ != DELETE_VALUE) {
34 // we already did something.
35 LOG(ERROR) << "multiple calls to Do()";
36 return false;
37 }
34 38
35 status_ = VALUE_UNCHANGED; 39 status_ = VALUE_UNCHANGED;
36 40
37 RegKey key; 41 RegKey key;
38 DWORD type = 0; 42 DWORD type = 0;
39 DWORD size = 0; 43 DWORD size = 0;
40 LONG result = key.Open(predefined_root_, 44 LONG result = key.Open(predefined_root_,
41 key_path_.c_str(), 45 key_path_.c_str(),
42 KEY_READ | KEY_WRITE | wow64_access_); 46 KEY_READ | KEY_WRITE | wow64_access_);
43 if (result == ERROR_SUCCESS) 47 if (result == ERROR_SUCCESS)
44 result = key.ReadValue(value_name_.c_str(), NULL, &size, &type); 48 result = key.ReadValue(value_name_.c_str(), NULL, &size, &type);
45 49
46 if (result == ERROR_FILE_NOT_FOUND) { 50 if (result == ERROR_FILE_NOT_FOUND) {
47 VLOG(1) << "(delete value) Key: " << key_path_ 51 LOG(INFO) << "(delete value) Key: " << key_path_ << " or Value: "
48 << " or Value: " << value_name_ << " does not exist."; 52 << value_name_ << " does not exist.";
49 status_ = VALUE_NOT_FOUND; 53 status_ = VALUE_NOT_FOUND;
50 return true; 54 return true;
51 } 55 }
52 56
53 if (result == ERROR_SUCCESS) { 57 if (result == ERROR_SUCCESS) {
54 if (!size) { 58 if (!size) {
55 previous_type_ = type; 59 previous_type_ = type;
56 } else { 60 } else {
57 previous_value_.resize(size); 61 previous_value_.resize(size);
58 result = key.ReadValue(value_name_.c_str(), &previous_value_[0], &size, 62 result = key.ReadValue(value_name_.c_str(), &previous_value_[0], &size,
59 &previous_type_); 63 &previous_type_);
60 if (result != ERROR_SUCCESS) { 64 if (result != ERROR_SUCCESS) {
61 previous_value_.erase(); 65 previous_value_.erase();
62 VLOG(1) << "Failed to save original value. Error: " << result; 66 VLOG(1) << "Failed to save original value. Error: " << result;
63 } 67 }
64 } 68 }
65 } 69 }
66 70
67 result = key.DeleteValue(value_name_.c_str()); 71 result = key.DeleteValue(value_name_.c_str());
68 if (result != ERROR_SUCCESS) { 72 if (result != ERROR_SUCCESS) {
69 VLOG(1) << "Failed to delete value " << value_name_ << " error: " << result; 73 VLOG(1) << "Failed to delete value " << value_name_ << " error: " << result;
70 return false; 74 return false;
71 } 75 }
72 76
73 status_ = VALUE_DELETED; 77 status_ = VALUE_DELETED;
74 return true; 78 return true;
75 } 79 }
76 80
77 void DeleteRegValueWorkItem::RollbackImpl() { 81 void DeleteRegValueWorkItem::Rollback() {
78 DCHECK_NE(DELETE_VALUE, status_); 82 if (status_ == DELETE_VALUE || status_ == VALUE_ROLLED_BACK)
79 DCHECK_NE(VALUE_ROLLED_BACK, status_); 83 return;
80
81 if (status_ == VALUE_UNCHANGED || status_ == VALUE_NOT_FOUND) { 84 if (status_ == VALUE_UNCHANGED || status_ == VALUE_NOT_FOUND) {
82 status_ = VALUE_ROLLED_BACK; 85 status_ = VALUE_ROLLED_BACK;
83 VLOG(1) << "rollback: setting unchanged, nothing to do"; 86 VLOG(1) << "rollback: setting unchanged, nothing to do";
84 return; 87 return;
85 } 88 }
86 89
87 // At this point only possible state is VALUE_DELETED. 90 // At this point only possible state is VALUE_DELETED.
88 DCHECK_EQ(VALUE_DELETED, status_);
89
90 RegKey key; 91 RegKey key;
91 LONG result = key.Open(predefined_root_, 92 LONG result = key.Open(predefined_root_,
92 key_path_.c_str(), 93 key_path_.c_str(),
93 KEY_READ | KEY_WRITE | wow64_access_); 94 KEY_READ | KEY_WRITE | wow64_access_);
94 if (result == ERROR_SUCCESS) { 95 if (result == ERROR_SUCCESS) {
95 // try to restore the previous value 96 // try to restore the previous value
96 DWORD previous_size = static_cast<DWORD>(previous_value_.size()); 97 DWORD previous_size = static_cast<DWORD>(previous_value_.size());
97 const char* previous_value = 98 const char* previous_value =
98 previous_size ? &previous_value_[0] : NULL; 99 previous_size ? &previous_value_[0] : NULL;
99 result = key.WriteValue(value_name_.c_str(), previous_value, 100 result = key.WriteValue(value_name_.c_str(), previous_value,
100 previous_size, previous_type_); 101 previous_size, previous_type_);
101 VLOG_IF(1, result != ERROR_SUCCESS) << "rollback: restoring " 102 VLOG_IF(1, result != ERROR_SUCCESS) << "rollback: restoring "
102 << value_name_ << " error: " << result; 103 << value_name_ << " error: " << result;
103 } else { 104 } else {
104 VLOG(1) << "can not open " << key_path_ << " error: " << result; 105 VLOG(1) << "can not open " << key_path_ << " error: " << result;
105 } 106 }
106 } 107 }
OLDNEW
« no previous file with comments | « chrome/installer/util/delete_reg_value_work_item.h ('k') | chrome/installer/util/delete_tree_work_item.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698