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

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

Issue 6090006: Regkey functions return error code instead of bool (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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 #include "chrome/installer/util/set_reg_value_work_item.h" 5 #include "chrome/installer/util/set_reg_value_work_item.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/win/registry.h" 8 #include "base/win/registry.h"
9 #include "chrome/installer/util/logging_installer.h" 9 #include "chrome/installer/util/logging_installer.h"
10 10
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 } 43 }
44 44
45 bool SetRegValueWorkItem::Do() { 45 bool SetRegValueWorkItem::Do() {
46 if (status_ != SET_VALUE) { 46 if (status_ != SET_VALUE) {
47 // we already did something. 47 // we already did something.
48 LOG(ERROR) << "multiple calls to Do()"; 48 LOG(ERROR) << "multiple calls to Do()";
49 return false; 49 return false;
50 } 50 }
51 51
52 base::win::RegKey key; 52 base::win::RegKey key;
53 if (!key.Open(predefined_root_, key_path_.c_str(), 53 LONG result = key.Open(predefined_root_, key_path_.c_str(),
54 KEY_READ | KEY_SET_VALUE)) { 54 KEY_READ | KEY_SET_VALUE);
55 LOG(ERROR) << "can not open " << key_path_; 55 if (result != ERROR_SUCCESS) {
56 LOG(ERROR) << "can not open " << key_path_ << " error: " << result;
grt (UTC plus 2) 2011/01/11 03:51:30 com::LogWe here and everywhere
56 status_ = VALUE_UNCHANGED; 57 status_ = VALUE_UNCHANGED;
57 return false; 58 return false;
58 } 59 }
59 60
60 bool result = false;
61 if (key.ValueExists(value_name_.c_str())) { 61 if (key.ValueExists(value_name_.c_str())) {
62 if (overwrite_) { 62 if (overwrite_) {
63 bool success = true;
64 // Read previous value for rollback and write new value 63 // Read previous value for rollback and write new value
65 if (is_str_type_) { 64 if (is_str_type_) {
66 std::wstring data; 65 key.ReadValue(value_name_.c_str(), &previous_value_str_);
67 if (key.ReadValue(value_name_.c_str(), &data)) { 66 result = key.WriteValue(value_name_.c_str(), value_data_str_.c_str());
68 previous_value_str_.assign(data);
69 }
70 success = key.WriteValue(value_name_.c_str(), value_data_str_.c_str());
71 } else { 67 } else {
72 DWORD data; 68 key.ReadValueDW(value_name_.c_str(), &previous_value_dword_);
73 if (key.ReadValueDW(value_name_.c_str(), &data)) { 69 result = key.WriteValue(value_name_.c_str(), value_data_dword_);
74 previous_value_dword_ = data;
75 }
76 success = key.WriteValue(value_name_.c_str(), value_data_dword_);
77 } 70 }
78 if (success) { 71 if (result == ERROR_SUCCESS) {
79 VLOG(1) << "overwritten value for " << value_name_; 72 VLOG(1) << "overwritten value for " << value_name_;
80 status_ = VALUE_OVERWRITTEN; 73 status_ = VALUE_OVERWRITTEN;
81 result = true;
82 } else { 74 } else {
83 LOG(ERROR) << "failed to overwrite value for " << value_name_; 75 LOG(ERROR) << "failed to overwrite value for " << value_name_
76 << " error: " << result;
84 status_ = VALUE_UNCHANGED; 77 status_ = VALUE_UNCHANGED;
85 result = false;
86 } 78 }
87 } else { 79 } else {
88 VLOG(1) << value_name_ << " exists. not changed "; 80 VLOG(1) << value_name_ << " exists. not changed ";
89 status_ = VALUE_UNCHANGED; 81 status_ = VALUE_UNCHANGED;
90 result = true;
91 } 82 }
92 } else { 83 } else {
93 bool success = true;
94 if (is_str_type_) { 84 if (is_str_type_) {
95 success = key.WriteValue(value_name_.c_str(), value_data_str_.c_str()); 85 result = key.WriteValue(value_name_.c_str(), value_data_str_.c_str());
96 } else { 86 } else {
97 success = key.WriteValue(value_name_.c_str(), value_data_dword_); 87 result = key.WriteValue(value_name_.c_str(), value_data_dword_);
98 } 88 }
99 if (success) { 89 if (result == ERROR_SUCCESS) {
100 VLOG(1) << "created value for " << value_name_; 90 VLOG(1) << "created value for " << value_name_;
101 status_ = NEW_VALUE_CREATED; 91 status_ = NEW_VALUE_CREATED;
102 result = true;
103 } else { 92 } else {
104 LOG(ERROR) << "failed to create value for " << value_name_; 93 LOG(ERROR) << "failed to create value for " << value_name_
94 << " error: " << result;
105 status_ = VALUE_UNCHANGED; 95 status_ = VALUE_UNCHANGED;
106 result = false;
107 } 96 }
108 } 97 }
109 98
110 key.Close(); 99 key.Close();
111 return result; 100 return result == ERROR_SUCCESS;
112 } 101 }
113 102
114 void SetRegValueWorkItem::Rollback() { 103 void SetRegValueWorkItem::Rollback() {
115 if (status_ == SET_VALUE || status_ == VALUE_ROLL_BACK) 104 if (status_ == SET_VALUE || status_ == VALUE_ROLL_BACK)
116 return; 105 return;
117 106
118 if (status_ == VALUE_UNCHANGED) { 107 if (status_ == VALUE_UNCHANGED) {
119 status_ = VALUE_ROLL_BACK; 108 status_ = VALUE_ROLL_BACK;
120 VLOG(1) << "rollback: setting unchanged, nothing to do"; 109 VLOG(1) << "rollback: setting unchanged, nothing to do";
121 return; 110 return;
122 } 111 }
123 112
124 base::win::RegKey key; 113 base::win::RegKey key;
125 if (!key.Open(predefined_root_, key_path_.c_str(), 114 LONG result = key.Open(predefined_root_, key_path_.c_str(),
126 KEY_READ | KEY_SET_VALUE)) { 115 KEY_READ | KEY_SET_VALUE);
116 if (result != ERROR_SUCCESS) {
127 status_ = VALUE_ROLL_BACK; 117 status_ = VALUE_ROLL_BACK;
128 VLOG(1) << "rollback: can not open " << key_path_; 118 VLOG(1) << "rollback: can not open " << key_path_ << " error: " << result;
129 return; 119 return;
130 } 120 }
131 121
132 std::wstring result_str(L" failed");
133 if (status_ == NEW_VALUE_CREATED) { 122 if (status_ == NEW_VALUE_CREATED) {
134 if (key.DeleteValue(value_name_.c_str())) 123 result = key.DeleteValue(value_name_.c_str());
135 result_str.assign(L" succeeded"); 124 VLOG(1) << "rollback: deleting " << value_name_ << " error: " << result;
136 VLOG(1) << "rollback: deleting " << value_name_ << result_str;
137 } else if (status_ == VALUE_OVERWRITTEN) { 125 } else if (status_ == VALUE_OVERWRITTEN) {
138 // try restore the previous value 126 // try restore the previous value
139 bool success = true;
140 if (is_str_type_) { 127 if (is_str_type_) {
141 success = key.WriteValue(value_name_.c_str(), 128 result = key.WriteValue(value_name_.c_str(), previous_value_str_.c_str());
142 previous_value_str_.c_str());
143 } else { 129 } else {
144 success = key.WriteValue(value_name_.c_str(), previous_value_dword_); 130 result = key.WriteValue(value_name_.c_str(), previous_value_dword_);
145 } 131 }
146 if (success) 132 VLOG(1) << "rollback: restoring " << value_name_ << " error: " << result;
147 result_str.assign(L" succeeded");
148 VLOG(1) << "rollback: restoring " << value_name_ << result_str;
149 } else { 133 } else {
150 // Not reached. 134 // Not reached.
135 NOTREACHED();
151 } 136 }
152 137
153 status_ = VALUE_ROLL_BACK; 138 status_ = VALUE_ROLL_BACK;
154 key.Close(); 139 key.Close();
155 return; 140 return;
156 } 141 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698