| 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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 global_error_bubble_accept_label->assign(l10n_util::GetStringUTF16( | 125 global_error_bubble_accept_label->assign(l10n_util::GetStringUTF16( |
| 126 IDS_SYNC_SIGN_IN_ERROR_BUBBLE_VIEW_ACCEPT)); | 126 IDS_SYNC_SIGN_IN_ERROR_BUBBLE_VIEW_ACCEPT)); |
| 127 } | 127 } |
| 128 break; | 128 break; |
| 129 } | 129 } |
| 130 } | 130 } |
| 131 | 131 |
| 132 // Returns the message that should be displayed when the user is authenticated | 132 // Returns the message that should be displayed when the user is authenticated |
| 133 // and can connect to the sync server. If the user hasn't yet authenticated, an | 133 // and can connect to the sync server. If the user hasn't yet authenticated, an |
| 134 // empty string is returned. | 134 // empty string is returned. |
| 135 string16 GetSyncedStateStatusLabel(ProfileSyncService* service) { | 135 string16 GetSyncedStateStatusLabel(ProfileSyncService* service, |
| 136 StatusLabelStyle style) { |
| 136 string16 label; | 137 string16 label; |
| 137 string16 user_name(service->GetAuthenticatedUsername()); | 138 string16 user_name(service->GetAuthenticatedUsername()); |
| 138 if (user_name.empty()) | 139 if (user_name.empty()) |
| 139 return label; | 140 return label; |
| 140 | 141 |
| 141 return l10n_util::GetStringFUTF16( | 142 // Message may also carry additional advice with an HTML link, if acceptable. |
| 142 IDS_SYNC_ACCOUNT_SYNCING_TO_USER, | 143 switch (style) { |
| 143 user_name, | 144 case PLAIN_TEXT: |
| 144 ASCIIToUTF16(chrome::kSyncGoogleDashboardURL)); | 145 return l10n_util::GetStringFUTF16( |
| 146 IDS_SYNC_ACCOUNT_SYNCING_TO_USER, |
| 147 user_name); |
| 148 case WITH_HTML: |
| 149 return l10n_util::GetStringFUTF16( |
| 150 IDS_SYNC_ACCOUNT_SYNCING_TO_USER_WITH_MANAGE_LINK, |
| 151 user_name, |
| 152 ASCIIToUTF16(chrome::kSyncGoogleDashboardURL)); |
| 153 default: |
| 154 NOTREACHED(); |
| 155 return NULL; |
| 156 } |
| 145 } | 157 } |
| 146 | 158 |
| 147 void GetStatusForActionableError( | 159 void GetStatusForActionableError( |
| 148 const browser_sync::SyncProtocolError& error, | 160 const browser_sync::SyncProtocolError& error, |
| 149 string16* status_label) { | 161 string16* status_label) { |
| 150 DCHECK(status_label); | 162 DCHECK(status_label); |
| 151 switch (error.action) { | 163 switch (error.action) { |
| 152 case browser_sync::STOP_AND_RESTART_SYNC: | 164 case browser_sync::STOP_AND_RESTART_SYNC: |
| 153 status_label->assign( | 165 status_label->assign( |
| 154 l10n_util::GetStringUTF16(IDS_SYNC_STOP_AND_RESTART_SYNC)); | 166 l10n_util::GetStringUTF16(IDS_SYNC_STOP_AND_RESTART_SYNC)); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 168 break; | 180 break; |
| 169 default: | 181 default: |
| 170 NOTREACHED(); | 182 NOTREACHED(); |
| 171 } | 183 } |
| 172 } | 184 } |
| 173 | 185 |
| 174 // TODO(akalin): Write unit tests for these three functions below. | 186 // TODO(akalin): Write unit tests for these three functions below. |
| 175 | 187 |
| 176 // status_label and link_label must either be both NULL or both non-NULL. | 188 // status_label and link_label must either be both NULL or both non-NULL. |
| 177 MessageType GetStatusInfo(ProfileSyncService* service, | 189 MessageType GetStatusInfo(ProfileSyncService* service, |
| 190 StatusLabelStyle style, |
| 178 string16* status_label, | 191 string16* status_label, |
| 179 string16* link_label) { | 192 string16* link_label) { |
| 180 DCHECK_EQ(status_label == NULL, link_label == NULL); | 193 DCHECK_EQ(status_label == NULL, link_label == NULL); |
| 181 | 194 |
| 182 MessageType result_type(SYNCED); | 195 MessageType result_type(SYNCED); |
| 183 | 196 |
| 184 if (!service) { | 197 if (!service) { |
| 185 return PRE_SYNCED; | 198 return PRE_SYNCED; |
| 186 } | 199 } |
| 187 | 200 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 | 243 |
| 231 // Now finally passphrase error. | 244 // Now finally passphrase error. |
| 232 if (service->IsPassphraseRequired()) { | 245 if (service->IsPassphraseRequired()) { |
| 233 if (service->IsPassphraseRequiredForDecryption()) { | 246 if (service->IsPassphraseRequiredForDecryption()) { |
| 234 // TODO(lipalani) : Ask tim if this is still needed. | 247 // TODO(lipalani) : Ask tim if this is still needed. |
| 235 // NOT first machine. | 248 // NOT first machine. |
| 236 // Show a link ("needs attention"), but still indicate the | 249 // Show a link ("needs attention"), but still indicate the |
| 237 // current synced status. Return SYNC_PROMO so that | 250 // current synced status. Return SYNC_PROMO so that |
| 238 // the configure link will still be shown. | 251 // the configure link will still be shown. |
| 239 if (status_label && link_label) { | 252 if (status_label && link_label) { |
| 240 status_label->assign(GetSyncedStateStatusLabel(service)); | 253 status_label->assign(GetSyncedStateStatusLabel(service, style)); |
| 241 link_label->assign( | 254 link_label->assign( |
| 242 l10n_util::GetStringUTF16(IDS_SYNC_PASSWORD_SYNC_ATTENTION)); | 255 l10n_util::GetStringUTF16(IDS_SYNC_PASSWORD_SYNC_ATTENTION)); |
| 243 } | 256 } |
| 244 return SYNC_PROMO; | 257 return SYNC_PROMO; |
| 245 } | 258 } |
| 246 } | 259 } |
| 247 | 260 |
| 248 // There is no error. Display "Last synced..." message. | 261 // There is no error. Display "Last synced..." message. |
| 249 if (status_label) | 262 if (status_label) |
| 250 status_label->assign(GetSyncedStateStatusLabel(service)); | 263 status_label->assign(GetSyncedStateStatusLabel(service, style)); |
| 251 return SYNCED; | 264 return SYNCED; |
| 252 } else { | 265 } else { |
| 253 // Either show auth error information with a link to re-login, auth in prog, | 266 // Either show auth error information with a link to re-login, auth in prog, |
| 254 // or provide a link to continue with setup. | 267 // or provide a link to continue with setup. |
| 255 result_type = PRE_SYNCED; | 268 result_type = PRE_SYNCED; |
| 256 if (service->SetupInProgress()) { | 269 if (service->SetupInProgress()) { |
| 257 ProfileSyncService::Status status(service->QueryDetailedSyncStatus()); | 270 ProfileSyncService::Status status(service->QueryDetailedSyncStatus()); |
| 258 const AuthError& auth_error = service->GetAuthError(); | 271 const AuthError& auth_error = service->GetAuthError(); |
| 259 if (status_label) { | 272 if (status_label) { |
| 260 status_label->assign( | 273 status_label->assign( |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 if (status_label && link_label) { | 335 if (status_label && link_label) { |
| 323 status_label->assign(string16()); | 336 status_label->assign(string16()); |
| 324 link_label->assign( | 337 link_label->assign( |
| 325 l10n_util::GetStringUTF16(IDS_SYNC_CONFIGURE_ENCRYPTION)); | 338 l10n_util::GetStringUTF16(IDS_SYNC_CONFIGURE_ENCRYPTION)); |
| 326 } | 339 } |
| 327 return SYNC_ERROR; | 340 return SYNC_ERROR; |
| 328 } | 341 } |
| 329 } | 342 } |
| 330 | 343 |
| 331 // Fallback to default. | 344 // Fallback to default. |
| 332 return GetStatusInfo(service, status_label, link_label); | 345 return GetStatusInfo(service, WITH_HTML, status_label, link_label); |
| 333 } | 346 } |
| 334 | 347 |
| 335 } // namespace | 348 } // namespace |
| 336 | 349 |
| 337 MessageType GetStatusLabels(ProfileSyncService* service, | 350 MessageType GetStatusLabels(ProfileSyncService* service, |
| 351 StatusLabelStyle style, |
| 338 string16* status_label, | 352 string16* status_label, |
| 339 string16* link_label) { | 353 string16* link_label) { |
| 340 DCHECK(status_label); | 354 DCHECK(status_label); |
| 341 DCHECK(link_label); | 355 DCHECK(link_label); |
| 342 return sync_ui_util::GetStatusInfo(service, status_label, link_label); | 356 return sync_ui_util::GetStatusInfo(service, style, status_label, link_label); |
| 343 } | 357 } |
| 344 | 358 |
| 345 MessageType GetStatusLabelsForNewTabPage(ProfileSyncService* service, | 359 MessageType GetStatusLabelsForNewTabPage(ProfileSyncService* service, |
| 346 string16* status_label, | 360 string16* status_label, |
| 347 string16* link_label) { | 361 string16* link_label) { |
| 348 DCHECK(status_label); | 362 DCHECK(status_label); |
| 349 DCHECK(link_label); | 363 DCHECK(link_label); |
| 350 return sync_ui_util::GetStatusInfoForNewTabPage( | 364 return sync_ui_util::GetStatusInfoForNewTabPage( |
| 351 service, status_label, link_label); | 365 service, status_label, link_label); |
| 352 } | 366 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 383 return; | 397 return; |
| 384 | 398 |
| 385 const AuthError& auth_error = service->GetAuthError(); | 399 const AuthError& auth_error = service->GetAuthError(); |
| 386 if (auth_error.state() != AuthError::NONE) { | 400 if (auth_error.state() != AuthError::NONE) { |
| 387 GetStatusLabelsForAuthError(auth_error, *service, NULL, NULL, | 401 GetStatusLabelsForAuthError(auth_error, *service, NULL, NULL, |
| 388 menu_label, bubble_message, bubble_accept_label); | 402 menu_label, bubble_message, bubble_accept_label); |
| 389 } | 403 } |
| 390 } | 404 } |
| 391 | 405 |
| 392 MessageType GetStatus(ProfileSyncService* service) { | 406 MessageType GetStatus(ProfileSyncService* service) { |
| 393 return sync_ui_util::GetStatusInfo(service, NULL, NULL); | 407 return sync_ui_util::GetStatusInfo(service, WITH_HTML, NULL, NULL); |
| 394 } | 408 } |
| 395 | 409 |
| 396 string16 GetSyncMenuLabel(ProfileSyncService* service) { | 410 string16 GetSyncMenuLabel(ProfileSyncService* service) { |
| 397 MessageType type = GetStatus(service); | 411 MessageType type = GetStatus(service); |
| 398 | 412 |
| 399 if (type == sync_ui_util::SYNCED) | 413 if (type == sync_ui_util::SYNCED) |
| 400 return l10n_util::GetStringUTF16(IDS_SYNC_MENU_SYNCED_LABEL); | 414 return l10n_util::GetStringUTF16(IDS_SYNC_MENU_SYNCED_LABEL); |
| 401 else if (type == sync_ui_util::SYNC_ERROR) | 415 else if (type == sync_ui_util::SYNC_ERROR) |
| 402 return l10n_util::GetStringUTF16(IDS_SYNC_MENU_SYNC_ERROR_LABEL); | 416 return l10n_util::GetStringUTF16(IDS_SYNC_MENU_SYNC_ERROR_LABEL); |
| 403 else | 417 else |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 687 } | 701 } |
| 688 } else { | 702 } else { |
| 689 version_modifier = " " + version_modifier; | 703 version_modifier = " " + version_modifier; |
| 690 } | 704 } |
| 691 return chrome_version.Name() + " " + chrome_version.OSType() + " " + | 705 return chrome_version.Name() + " " + chrome_version.OSType() + " " + |
| 692 chrome_version.Version() + " (" + chrome_version.LastChange() + ")" + | 706 chrome_version.Version() + " (" + chrome_version.LastChange() + ")" + |
| 693 version_modifier; | 707 version_modifier; |
| 694 } | 708 } |
| 695 | 709 |
| 696 } // namespace sync_ui_util | 710 } // namespace sync_ui_util |
| OLD | NEW |