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/mac/foundation_util.h" | |
11 #include "base/strings/stringprintf.h" | |
12 #include "base/strings/sys_string_conversions.h" | |
13 #include "base/strings/utf_string_conversions.h" | |
9 #include "chrome/browser/lifetime/application_lifetime.h" | 14 #include "chrome/browser/lifetime/application_lifetime.h" |
10 #import "chrome/browser/mac/keystone_glue.h" | 15 #import "chrome/browser/mac/keystone_glue.h" |
11 #include "chrome/browser/obsolete_system/obsolete_system.h" | 16 #include "chrome/browser/obsolete_system/obsolete_system.h" |
12 #include "chrome/grit/chromium_strings.h" | 17 #include "chrome/grit/chromium_strings.h" |
13 #include "chrome/grit/generated_resources.h" | 18 #include "chrome/grit/generated_resources.h" |
19 #include "net/base/escape.h" | |
14 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
15 | 21 |
16 // KeystoneObserver is a simple notification observer for Keystone status | 22 // KeystoneObserver is a simple notification observer for Keystone status |
17 // updates. It will be created and managed by VersionUpdaterMac. | 23 // updates. It will be created and managed by VersionUpdaterMac. |
18 @interface KeystoneObserver : NSObject { | 24 @interface KeystoneObserver : NSObject { |
19 @private | 25 @private |
20 VersionUpdaterMac* versionUpdater_; // Weak. | 26 VersionUpdaterMac* versionUpdater_; // Weak. |
21 } | 27 } |
22 | 28 |
23 // Initialize an observer with an updater. The updater owns this object. | 29 // Initialize an observer with an updater. The updater owns this object. |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
124 // registration is in progress and subsequently that it has completed. | 130 // registration is in progress and subsequently that it has completed. |
125 } | 131 } |
126 | 132 |
127 void VersionUpdaterMac::RelaunchBrowser() const { | 133 void VersionUpdaterMac::RelaunchBrowser() const { |
128 // Tell the Broweser to restart if possible. | 134 // Tell the Broweser to restart if possible. |
129 chrome::AttemptRestart(); | 135 chrome::AttemptRestart(); |
130 } | 136 } |
131 | 137 |
132 void VersionUpdaterMac::UpdateStatus(NSDictionary* dictionary) { | 138 void VersionUpdaterMac::UpdateStatus(NSDictionary* dictionary) { |
133 AutoupdateStatus keystone_status = static_cast<AutoupdateStatus>( | 139 AutoupdateStatus keystone_status = static_cast<AutoupdateStatus>( |
134 [[dictionary objectForKey:kAutoupdateStatusStatus] intValue]); | 140 [base::mac::ObjCCastStrict<NSNumber>( |
141 [dictionary objectForKey:kAutoupdateStatusStatus]) intValue]); | |
142 std::string error_messages = base::SysNSStringToUTF8( | |
143 base::mac::ObjCCastStrict<NSString>( | |
144 [dictionary objectForKey:kAutoupdateStatusErrorMessages])); | |
135 | 145 |
136 bool enable_promote_button = true; | 146 bool enable_promote_button = true; |
137 base::string16 message; | 147 base::string16 message; |
138 | 148 |
139 Status status; | 149 Status status; |
140 switch (keystone_status) { | 150 switch (keystone_status) { |
141 case kAutoupdateRegistering: | 151 case kAutoupdateRegistering: |
142 case kAutoupdateChecking: | 152 case kAutoupdateChecking: |
143 status = CHECKING; | 153 status = CHECKING; |
144 enable_promote_button = false; | 154 enable_promote_button = false; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
204 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); | 214 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); |
205 message = l10n_util::GetStringFUTF16(IDS_PROMOTE_INFOBAR_TEXT, | 215 message = l10n_util::GetStringFUTF16(IDS_PROMOTE_INFOBAR_TEXT, |
206 product_name); | 216 product_name); |
207 } | 217 } |
208 break; | 218 break; |
209 | 219 |
210 default: | 220 default: |
211 NOTREACHED(); | 221 NOTREACHED(); |
212 return; | 222 return; |
213 } | 223 } |
224 | |
225 // If there are any detailed error messages being passed along by Keystone, | |
226 // log them. If we have an error to display, include the detail messages | |
227 // below the error in a <pre> block. Don't bother displaying detail messages | |
228 // on a success/in-progress/indeterminate status. | |
229 if (!error_messages.empty()) { | |
230 VLOG(1) << "Update error messages: " << error_messages; | |
231 | |
232 if (status == FAILED) { | |
233 if (!message.empty()) { | |
234 message += base::UTF8ToUTF16("<br/><br/>"); | |
235 } | |
236 | |
237 message += l10n_util::GetStringUTF16(IDS_UPGRADE_ERROR_DETAILS); | |
238 message += base::UTF8ToUTF16("<br/><pre>"); | |
239 message += base::UTF8ToUTF16(net::EscapeForHTML(error_messages)); | |
240 message += base::UTF8ToUTF16("</pre>"); | |
xiyuan
2016/03/24 22:14:15
nit: String cancat is not i18n friendly. We should
| |
241 } | |
242 } | |
243 | |
214 if (!status_callback_.is_null()) | 244 if (!status_callback_.is_null()) |
215 status_callback_.Run(status, 0, message); | 245 status_callback_.Run(status, 0, message); |
216 | 246 |
217 if (!promote_callback_.is_null()) { | 247 if (!promote_callback_.is_null()) { |
218 PromotionState promotion_state = PROMOTE_HIDDEN; | 248 PromotionState promotion_state = PROMOTE_HIDDEN; |
219 if (show_promote_button_) | 249 if (show_promote_button_) |
220 promotion_state = enable_promote_button ? PROMOTE_ENABLED | 250 promotion_state = enable_promote_button ? PROMOTE_ENABLED |
221 : PROMOTE_DISABLED; | 251 : PROMOTE_DISABLED; |
222 promote_callback_.Run(promotion_state); | 252 promote_callback_.Run(promotion_state); |
223 } | 253 } |
(...skipping 16 matching lines...) Expand all Loading... | |
240 } else if (recent_status == kAutoupdatePromoting || | 270 } else if (recent_status == kAutoupdatePromoting || |
241 recent_status == kAutoupdatePromoteFailed) { | 271 recent_status == kAutoupdatePromoteFailed) { |
242 // Show promotion UI because the user either just clicked that button or | 272 // Show promotion UI because the user either just clicked that button or |
243 // because the user should be able to click it again. | 273 // because the user should be able to click it again. |
244 show_promote_button_ = true; | 274 show_promote_button_ = true; |
245 } else { | 275 } else { |
246 // Show the promote button if promotion is a possibility. | 276 // Show the promote button if promotion is a possibility. |
247 show_promote_button_ = [keystone_glue wantsPromotion]; | 277 show_promote_button_ = [keystone_glue wantsPromotion]; |
248 } | 278 } |
249 } | 279 } |
OLD | NEW |