OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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/google_update_settings.h" | 5 #include "chrome/installer/util/google_update_settings.h" |
6 | 6 |
7 #include "base/registry.h" | 7 #include "base/registry.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/time.h" | 9 #include "base/time.h" |
10 #include "chrome/installer/util/browser_distribution.h" | 10 #include "chrome/installer/util/browser_distribution.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 } | 88 } |
89 | 89 |
90 bool GoogleUpdateSettings::SetEULAConsent(bool consented) { | 90 bool GoogleUpdateSettings::SetEULAConsent(bool consented) { |
91 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 91 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
92 std::wstring reg_path = dist->GetStateMediumKey(); | 92 std::wstring reg_path = dist->GetStateMediumKey(); |
93 RegKey key(HKEY_LOCAL_MACHINE, reg_path.c_str(), KEY_READ | KEY_SET_VALUE); | 93 RegKey key(HKEY_LOCAL_MACHINE, reg_path.c_str(), KEY_READ | KEY_SET_VALUE); |
94 return key.WriteValue(google_update::kRegEULAAceptedField, consented? 1 : 0); | 94 return key.WriteValue(google_update::kRegEULAAceptedField, consented? 1 : 0); |
95 } | 95 } |
96 | 96 |
97 int GoogleUpdateSettings::GetLastRunTime() { | 97 int GoogleUpdateSettings::GetLastRunTime() { |
98 std::wstring time_s; | 98 std::wstring time_s; |
99 if (!ReadGoogleUpdateStrKey(google_update::kRegLastRunTimeField, &time_s)) | 99 if (!ReadGoogleUpdateStrKey(google_update::kRegLastRunTimeField, &time_s)) |
100 return -1; | 100 return -1; |
101 int64 time_i; | 101 int64 time_i; |
102 if (!StringToInt64(time_s, &time_i)) | 102 if (!StringToInt64(time_s, &time_i)) |
103 return -1; | 103 return -1; |
104 base::TimeDelta td = | 104 base::TimeDelta td = |
105 base::Time::NowFromSystemTime() - base::Time::FromInternalValue(time_i); | 105 base::Time::NowFromSystemTime() - base::Time::FromInternalValue(time_i); |
106 return td.InDays(); | 106 return td.InDays(); |
107 } | 107 } |
108 | 108 |
109 bool GoogleUpdateSettings::SetLastRunTime() { | 109 bool GoogleUpdateSettings::SetLastRunTime() { |
110 int64 time = base::Time::NowFromSystemTime().ToInternalValue(); | 110 int64 time = base::Time::NowFromSystemTime().ToInternalValue(); |
111 return WriteGoogleUpdateStrKey(google_update::kRegLastRunTimeField, | 111 return WriteGoogleUpdateStrKey(google_update::kRegLastRunTimeField, |
112 Int64ToWString(time)); | 112 Int64ToWString(time)); |
113 } | 113 } |
114 | 114 |
115 bool GoogleUpdateSettings::RemoveLastRunTime() { | 115 bool GoogleUpdateSettings::RemoveLastRunTime() { |
116 return RemoveGoogleUpdateStrKey(google_update::kRegLastRunTimeField); | 116 return RemoveGoogleUpdateStrKey(google_update::kRegLastRunTimeField); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 *channel = L"beta"; | 168 *channel = L"beta"; |
169 else if (update_branch.find(L"-dev") != std::wstring::npos) | 169 else if (update_branch.find(L"-dev") != std::wstring::npos) |
170 *channel = L"dev"; | 170 *channel = L"dev"; |
171 else if (update_branch.empty()) | 171 else if (update_branch.empty()) |
172 *channel = L""; | 172 *channel = L""; |
173 else | 173 else |
174 *channel = L"unknown"; | 174 *channel = L"unknown"; |
175 | 175 |
176 return true; | 176 return true; |
177 } | 177 } |
178 | |
179 void GoogleUpdateSettings::UpdateDiffInstallStatus(bool system_install, | |
180 bool incremental_install, int install_return_code, | |
181 const std::wstring& product_guid) { | |
182 HKEY reg_root = (system_install) ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | |
183 | |
184 RegKey key; | |
185 std::wstring ap_key_value; | |
186 std::wstring reg_key(google_update::kRegPathClientState); | |
187 reg_key.append(L"\\"); | |
188 reg_key.append(product_guid); | |
189 if (!key.Open(reg_root, reg_key.c_str(), KEY_ALL_ACCESS) || | |
190 !key.ReadValue(google_update::kRegApField, &ap_key_value)) { | |
191 LOG(INFO) << "Application key not found."; | |
192 if (!incremental_install || !install_return_code) { | |
193 LOG(INFO) << "Returning without changing application key."; | |
194 key.Close(); | |
195 return; | |
196 } else if (!key.Valid()) { | |
197 reg_key.assign(google_update::kRegPathClientState); | |
198 if (!key.Open(reg_root, reg_key.c_str(), KEY_ALL_ACCESS) || | |
199 !key.CreateKey(product_guid.c_str(), KEY_ALL_ACCESS)) { | |
200 LOG(ERROR) << "Failed to create application key."; | |
201 key.Close(); | |
202 return; | |
203 } | |
204 } | |
205 } | |
206 | |
207 std::wstring new_value = GetNewGoogleUpdateApKey( | |
208 incremental_install, install_return_code, ap_key_value); | |
209 if ((new_value.compare(ap_key_value) != 0) && | |
210 !key.WriteValue(google_update::kRegApField, new_value.c_str())) { | |
211 LOG(ERROR) << "Failed to write value " << new_value | |
212 << " to the registry field " << google_update::kRegApField; | |
213 } | |
214 key.Close(); | |
215 } | |
216 | |
217 std::wstring GoogleUpdateSettings::GetNewGoogleUpdateApKey( | |
218 bool diff_install, int install_return_code, const std::wstring& value) { | |
219 // Magic suffix that we need to add or remove to "ap" key value. | |
220 const std::wstring kMagicSuffix = L"-full"; | |
221 | |
222 bool has_magic_string = false; | |
223 if ((value.length() >= kMagicSuffix.length()) && | |
224 (value.rfind(kMagicSuffix) == (value.length() - kMagicSuffix.length()))) { | |
225 LOG(INFO) << "Incremental installer failure key already set."; | |
226 has_magic_string = true; | |
227 } | |
228 | |
229 std::wstring new_value(value); | |
230 if ((!diff_install || !install_return_code) && has_magic_string) { | |
231 LOG(INFO) << "Removing failure key from value " << value; | |
232 new_value = value.substr(0, value.length() - kMagicSuffix.length()); | |
233 } else if ((diff_install && install_return_code) && | |
234 !has_magic_string) { | |
235 LOG(INFO) << "Incremental installer failed, setting failure key."; | |
236 new_value.append(kMagicSuffix); | |
237 } | |
238 | |
239 return new_value; | |
240 } | |
241 | |
OLD | NEW |