OLD | NEW |
---|---|
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/browser/ui/webui/help/version_updater_mac.h" | 5 #include "chrome/browser/ui/webui/help/version_updater_mac.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/logging.h" | |
10 #include "base/strings/stringprintf.h" | |
11 #include "base/strings/utf_string_conversions.h" | |
9 #include "chrome/browser/lifetime/application_lifetime.h" | 12 #include "chrome/browser/lifetime/application_lifetime.h" |
10 #import "chrome/browser/mac/keystone_glue.h" | 13 #import "chrome/browser/mac/keystone_glue.h" |
11 #include "chrome/browser/obsolete_system/obsolete_system.h" | 14 #include "chrome/browser/obsolete_system/obsolete_system.h" |
12 #include "chrome/grit/chromium_strings.h" | 15 #include "chrome/grit/chromium_strings.h" |
13 #include "chrome/grit/generated_resources.h" | 16 #include "chrome/grit/generated_resources.h" |
17 #include "net/base/escape.h" | |
14 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
15 | 19 |
16 // KeystoneObserver is a simple notification observer for Keystone status | 20 // KeystoneObserver is a simple notification observer for Keystone status |
17 // updates. It will be created and managed by VersionUpdaterMac. | 21 // updates. It will be created and managed by VersionUpdaterMac. |
18 @interface KeystoneObserver : NSObject { | 22 @interface KeystoneObserver : NSObject { |
19 @private | 23 @private |
20 VersionUpdaterMac* versionUpdater_; // Weak. | 24 VersionUpdaterMac* versionUpdater_; // Weak. |
21 } | 25 } |
22 | 26 |
23 // Initialize an observer with an updater. The updater owns this object. | 27 // Initialize an observer with an updater. The updater owns this object. |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
125 } | 129 } |
126 | 130 |
127 void VersionUpdaterMac::RelaunchBrowser() const { | 131 void VersionUpdaterMac::RelaunchBrowser() const { |
128 // Tell the Broweser to restart if possible. | 132 // Tell the Broweser to restart if possible. |
129 chrome::AttemptRestart(); | 133 chrome::AttemptRestart(); |
130 } | 134 } |
131 | 135 |
132 void VersionUpdaterMac::UpdateStatus(NSDictionary* dictionary) { | 136 void VersionUpdaterMac::UpdateStatus(NSDictionary* dictionary) { |
133 AutoupdateStatus keystone_status = static_cast<AutoupdateStatus>( | 137 AutoupdateStatus keystone_status = static_cast<AutoupdateStatus>( |
134 [[dictionary objectForKey:kAutoupdateStatusStatus] intValue]); | 138 [[dictionary objectForKey:kAutoupdateStatusStatus] intValue]); |
139 const char* keystone_errors_utf8 = | |
140 [[dictionary objectForKey:kAutoupdateStatusErrorMessages] UTF8String]; | |
Mark Mentovai
2016/03/23 15:52:04
Use base::SysNSStringToUTF8 instead, to get a std:
Ryan Myers (chromium)
2016/03/23 22:29:38
Done.
| |
135 | 141 |
136 bool enable_promote_button = true; | 142 bool enable_promote_button = true; |
137 base::string16 message; | 143 base::string16 message; |
138 | 144 |
139 Status status; | 145 Status status; |
140 switch (keystone_status) { | 146 switch (keystone_status) { |
141 case kAutoupdateRegistering: | 147 case kAutoupdateRegistering: |
142 case kAutoupdateChecking: | 148 case kAutoupdateChecking: |
143 status = CHECKING; | 149 status = CHECKING; |
144 enable_promote_button = false; | 150 enable_promote_button = false; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
204 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); | 210 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); |
205 message = l10n_util::GetStringFUTF16(IDS_PROMOTE_INFOBAR_TEXT, | 211 message = l10n_util::GetStringFUTF16(IDS_PROMOTE_INFOBAR_TEXT, |
206 product_name); | 212 product_name); |
207 } | 213 } |
208 break; | 214 break; |
209 | 215 |
210 default: | 216 default: |
211 NOTREACHED(); | 217 NOTREACHED(); |
212 return; | 218 return; |
213 } | 219 } |
220 | |
221 // If there are any specific error messages being passed along by Keystone, | |
222 // log them, and include them in a <pre> block if we're showing an error. | |
223 if (keystone_errors_utf8 && strlen(keystone_errors_utf8)) { | |
224 VLOG(1) << "Keystone stderr: " << keystone_errors_utf8; | |
225 | |
226 if (!message.empty()) { | |
227 // TODO: Should we localize the "Error details" string? If so, get the | |
Mark Mentovai
2016/03/23 15:52:04
Yes. All of these strings should be localized.
Ev
Ryan Myers (chromium)
2016/03/23 22:29:38
Done.
| |
228 // string translated and into GRD, then replace this StringPrintf call | |
229 // with a call to l10n_util::GetStringFUTF16(IDS_KEYSTONE_ERROR_DETAILS). | |
230 std::string escaped_keystone_errors_utf8 = | |
231 net::EscapeForHTML(keystone_errors_utf8); | |
232 std::string formatted_errors = | |
233 base::StringPrintf("<br/><br/>Error details:<br/><pre>%s</pre>", | |
Mark Mentovai
2016/03/23 15:52:04
You can build this up with string +ing, probably n
Ryan Myers (chromium)
2016/03/23 22:29:38
Done.
| |
234 escaped_keystone_errors_utf8.c_str()); | |
235 message += base::UTF8ToUTF16(formatted_errors.c_str()); | |
236 } | |
237 } | |
238 | |
214 if (!status_callback_.is_null()) | 239 if (!status_callback_.is_null()) |
215 status_callback_.Run(status, 0, message); | 240 status_callback_.Run(status, 0, message); |
216 | 241 |
217 if (!promote_callback_.is_null()) { | 242 if (!promote_callback_.is_null()) { |
218 PromotionState promotion_state = PROMOTE_HIDDEN; | 243 PromotionState promotion_state = PROMOTE_HIDDEN; |
219 if (show_promote_button_) | 244 if (show_promote_button_) |
220 promotion_state = enable_promote_button ? PROMOTE_ENABLED | 245 promotion_state = enable_promote_button ? PROMOTE_ENABLED |
221 : PROMOTE_DISABLED; | 246 : PROMOTE_DISABLED; |
222 promote_callback_.Run(promotion_state); | 247 promote_callback_.Run(promotion_state); |
223 } | 248 } |
(...skipping 16 matching lines...) Expand all Loading... | |
240 } else if (recent_status == kAutoupdatePromoting || | 265 } else if (recent_status == kAutoupdatePromoting || |
241 recent_status == kAutoupdatePromoteFailed) { | 266 recent_status == kAutoupdatePromoteFailed) { |
242 // Show promotion UI because the user either just clicked that button or | 267 // Show promotion UI because the user either just clicked that button or |
243 // because the user should be able to click it again. | 268 // because the user should be able to click it again. |
244 show_promote_button_ = true; | 269 show_promote_button_ = true; |
245 } else { | 270 } else { |
246 // Show the promote button if promotion is a possibility. | 271 // Show the promote button if promotion is a possibility. |
247 show_promote_button_ = [keystone_glue wantsPromotion]; | 272 show_promote_button_ = [keystone_glue wantsPromotion]; |
248 } | 273 } |
249 } | 274 } |
OLD | NEW |