OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/sync/sync_ui_util.h" | 5 #include "chrome/browser/sync/sync_ui_util.h" |
6 | 6 |
7 #include "base/i18n/number_formatting.h" | 7 #include "base/i18n/number_formatting.h" |
8 #include "base/i18n/time_formatting.h" | 8 #include "base/i18n/time_formatting.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 global_error_bubble_accept_label->assign(l10n_util::GetStringUTF16( | 124 global_error_bubble_accept_label->assign(l10n_util::GetStringUTF16( |
125 IDS_SYNC_SIGN_IN_ERROR_BUBBLE_VIEW_ACCEPT)); | 125 IDS_SYNC_SIGN_IN_ERROR_BUBBLE_VIEW_ACCEPT)); |
126 } | 126 } |
127 break; | 127 break; |
128 } | 128 } |
129 } | 129 } |
130 | 130 |
131 // Returns the message that should be displayed when the user is authenticated | 131 // Returns the message that should be displayed when the user is authenticated |
132 // and can connect to the sync server. If the user hasn't yet authenticated, an | 132 // and can connect to the sync server. If the user hasn't yet authenticated, an |
133 // empty string is returned. | 133 // empty string is returned. |
134 string16 GetSyncedStateStatusLabel(ProfileSyncService* service) { | 134 string16 GetSyncedStateStatusLabel(ProfileSyncService* service, |
| 135 StatusLabelStyle style) { |
135 string16 label; | 136 string16 label; |
136 string16 user_name(service->GetAuthenticatedUsername()); | 137 string16 user_name(service->GetAuthenticatedUsername()); |
137 if (user_name.empty()) | 138 if (user_name.empty()) |
138 return label; | 139 return label; |
139 | 140 |
140 return l10n_util::GetStringFUTF16( | 141 // Message may also carry additional advice with an HTML link, if acceptable. |
141 IDS_SYNC_ACCOUNT_SYNCING_TO_USER, | 142 switch (style) { |
142 user_name, | 143 case PLAIN_TEXT: |
143 ASCIIToUTF16(chrome::kSyncGoogleDashboardURL)); | 144 return l10n_util::GetStringFUTF16( |
| 145 IDS_SYNC_ACCOUNT_SYNCING_TO_USER, |
| 146 user_name); |
| 147 case WITH_HTML: |
| 148 return l10n_util::GetStringFUTF16( |
| 149 IDS_SYNC_ACCOUNT_SYNCING_TO_USER_WITH_MANAGE_LINK, |
| 150 user_name, |
| 151 ASCIIToUTF16(chrome::kSyncGoogleDashboardURL)); |
| 152 default: |
| 153 NOTREACHED(); |
| 154 } |
144 } | 155 } |
145 | 156 |
146 void GetStatusForActionableError( | 157 void GetStatusForActionableError( |
147 const browser_sync::SyncProtocolError& error, | 158 const browser_sync::SyncProtocolError& error, |
148 string16* status_label) { | 159 string16* status_label) { |
149 DCHECK(status_label); | 160 DCHECK(status_label); |
150 switch (error.action) { | 161 switch (error.action) { |
151 case browser_sync::STOP_AND_RESTART_SYNC: | 162 case browser_sync::STOP_AND_RESTART_SYNC: |
152 status_label->assign( | 163 status_label->assign( |
153 l10n_util::GetStringUTF16(IDS_SYNC_STOP_AND_RESTART_SYNC)); | 164 l10n_util::GetStringUTF16(IDS_SYNC_STOP_AND_RESTART_SYNC)); |
(...skipping 13 matching lines...) Expand all Loading... |
167 break; | 178 break; |
168 default: | 179 default: |
169 NOTREACHED(); | 180 NOTREACHED(); |
170 } | 181 } |
171 } | 182 } |
172 | 183 |
173 // TODO(akalin): Write unit tests for these three functions below. | 184 // TODO(akalin): Write unit tests for these three functions below. |
174 | 185 |
175 // status_label and link_label must either be both NULL or both non-NULL. | 186 // status_label and link_label must either be both NULL or both non-NULL. |
176 MessageType GetStatusInfo(ProfileSyncService* service, | 187 MessageType GetStatusInfo(ProfileSyncService* service, |
| 188 StatusLabelStyle style, |
177 string16* status_label, | 189 string16* status_label, |
178 string16* link_label) { | 190 string16* link_label) { |
179 DCHECK_EQ(status_label == NULL, link_label == NULL); | 191 DCHECK_EQ(status_label == NULL, link_label == NULL); |
180 | 192 |
181 MessageType result_type(SYNCED); | 193 MessageType result_type(SYNCED); |
182 | 194 |
183 if (!service) { | 195 if (!service) { |
184 return PRE_SYNCED; | 196 return PRE_SYNCED; |
185 } | 197 } |
186 | 198 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 | 241 |
230 // Now finally passphrase error. | 242 // Now finally passphrase error. |
231 if (service->IsPassphraseRequired()) { | 243 if (service->IsPassphraseRequired()) { |
232 if (service->IsPassphraseRequiredForDecryption()) { | 244 if (service->IsPassphraseRequiredForDecryption()) { |
233 // TODO(lipalani) : Ask tim if this is still needed. | 245 // TODO(lipalani) : Ask tim if this is still needed. |
234 // NOT first machine. | 246 // NOT first machine. |
235 // Show a link ("needs attention"), but still indicate the | 247 // Show a link ("needs attention"), but still indicate the |
236 // current synced status. Return SYNC_PROMO so that | 248 // current synced status. Return SYNC_PROMO so that |
237 // the configure link will still be shown. | 249 // the configure link will still be shown. |
238 if (status_label && link_label) { | 250 if (status_label && link_label) { |
239 status_label->assign(GetSyncedStateStatusLabel(service)); | 251 status_label->assign(GetSyncedStateStatusLabel(service, style)); |
240 link_label->assign( | 252 link_label->assign( |
241 l10n_util::GetStringUTF16(IDS_SYNC_PASSWORD_SYNC_ATTENTION)); | 253 l10n_util::GetStringUTF16(IDS_SYNC_PASSWORD_SYNC_ATTENTION)); |
242 } | 254 } |
243 return SYNC_PROMO; | 255 return SYNC_PROMO; |
244 } | 256 } |
245 } | 257 } |
246 | 258 |
247 // There is no error. Display "Last synced..." message. | 259 // There is no error. Display "Last synced..." message. |
248 if (status_label) | 260 if (status_label) |
249 status_label->assign(GetSyncedStateStatusLabel(service)); | 261 status_label->assign(GetSyncedStateStatusLabel(service, style)); |
250 return SYNCED; | 262 return SYNCED; |
251 } else { | 263 } else { |
252 // Either show auth error information with a link to re-login, auth in prog, | 264 // Either show auth error information with a link to re-login, auth in prog, |
253 // or provide a link to continue with setup. | 265 // or provide a link to continue with setup. |
254 result_type = PRE_SYNCED; | 266 result_type = PRE_SYNCED; |
255 if (service->SetupInProgress()) { | 267 if (service->SetupInProgress()) { |
256 ProfileSyncService::Status status(service->QueryDetailedSyncStatus()); | 268 ProfileSyncService::Status status(service->QueryDetailedSyncStatus()); |
257 const AuthError& auth_error = service->GetAuthError(); | 269 const AuthError& auth_error = service->GetAuthError(); |
258 if (status_label) { | 270 if (status_label) { |
259 status_label->assign( | 271 status_label->assign( |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 if (status_label && link_label) { | 333 if (status_label && link_label) { |
322 status_label->assign(string16()); | 334 status_label->assign(string16()); |
323 link_label->assign( | 335 link_label->assign( |
324 l10n_util::GetStringUTF16(IDS_SYNC_CONFIGURE_ENCRYPTION)); | 336 l10n_util::GetStringUTF16(IDS_SYNC_CONFIGURE_ENCRYPTION)); |
325 } | 337 } |
326 return SYNC_ERROR; | 338 return SYNC_ERROR; |
327 } | 339 } |
328 } | 340 } |
329 | 341 |
330 // Fallback to default. | 342 // Fallback to default. |
331 return GetStatusInfo(service, status_label, link_label); | 343 return GetStatusInfo(service, WITH_HTML, status_label, link_label); |
332 } | 344 } |
333 | 345 |
334 } // namespace | 346 } // namespace |
335 | 347 |
336 MessageType GetStatusLabels(ProfileSyncService* service, | 348 MessageType GetStatusLabels(ProfileSyncService* service, |
| 349 StatusLabelStyle style, |
337 string16* status_label, | 350 string16* status_label, |
338 string16* link_label) { | 351 string16* link_label) { |
339 DCHECK(status_label); | 352 DCHECK(status_label); |
340 DCHECK(link_label); | 353 DCHECK(link_label); |
341 return sync_ui_util::GetStatusInfo(service, status_label, link_label); | 354 return sync_ui_util::GetStatusInfo(service, style, status_label, link_label); |
342 } | 355 } |
343 | 356 |
344 MessageType GetStatusLabelsForNewTabPage(ProfileSyncService* service, | 357 MessageType GetStatusLabelsForNewTabPage(ProfileSyncService* service, |
345 string16* status_label, | 358 string16* status_label, |
346 string16* link_label) { | 359 string16* link_label) { |
347 DCHECK(status_label); | 360 DCHECK(status_label); |
348 DCHECK(link_label); | 361 DCHECK(link_label); |
349 return sync_ui_util::GetStatusInfoForNewTabPage( | 362 return sync_ui_util::GetStatusInfoForNewTabPage( |
350 service, status_label, link_label); | 363 service, status_label, link_label); |
351 } | 364 } |
(...skipping 30 matching lines...) Expand all Loading... |
382 return; | 395 return; |
383 | 396 |
384 const AuthError& auth_error = service->GetAuthError(); | 397 const AuthError& auth_error = service->GetAuthError(); |
385 if (auth_error.state() != AuthError::NONE) { | 398 if (auth_error.state() != AuthError::NONE) { |
386 GetStatusLabelsForAuthError(auth_error, *service, NULL, NULL, | 399 GetStatusLabelsForAuthError(auth_error, *service, NULL, NULL, |
387 menu_label, bubble_message, bubble_accept_label); | 400 menu_label, bubble_message, bubble_accept_label); |
388 } | 401 } |
389 } | 402 } |
390 | 403 |
391 MessageType GetStatus(ProfileSyncService* service) { | 404 MessageType GetStatus(ProfileSyncService* service) { |
392 return sync_ui_util::GetStatusInfo(service, NULL, NULL); | 405 return sync_ui_util::GetStatusInfo(service, WITH_HTML, NULL, NULL); |
393 } | 406 } |
394 | 407 |
395 string16 GetSyncMenuLabel(ProfileSyncService* service) { | 408 string16 GetSyncMenuLabel(ProfileSyncService* service) { |
396 MessageType type = GetStatus(service); | 409 MessageType type = GetStatus(service); |
397 | 410 |
398 if (type == sync_ui_util::SYNCED) | 411 if (type == sync_ui_util::SYNCED) |
399 return l10n_util::GetStringUTF16(IDS_SYNC_MENU_SYNCED_LABEL); | 412 return l10n_util::GetStringUTF16(IDS_SYNC_MENU_SYNCED_LABEL); |
400 else if (type == sync_ui_util::SYNC_ERROR) | 413 else if (type == sync_ui_util::SYNC_ERROR) |
401 return l10n_util::GetStringUTF16(IDS_SYNC_MENU_SYNC_ERROR_LABEL); | 414 return l10n_util::GetStringUTF16(IDS_SYNC_MENU_SYNC_ERROR_LABEL); |
402 else | 415 else |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
657 DictionaryValue* val = new DictionaryValue; | 670 DictionaryValue* val = new DictionaryValue; |
658 val->SetString("model_type", ModelTypeToString(it->first)); | 671 val->SetString("model_type", ModelTypeToString(it->first)); |
659 val->SetString("group", ModelSafeGroupToString(it->second)); | 672 val->SetString("group", ModelSafeGroupToString(it->second)); |
660 routing_info->Append(val); | 673 routing_info->Append(val); |
661 } | 674 } |
662 } | 675 } |
663 } | 676 } |
664 } | 677 } |
665 | 678 |
666 } // namespace sync_ui_util | 679 } // namespace sync_ui_util |
OLD | NEW |