Chromium Code Reviews| 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/sync/sync_ui_util.h" | 5 #include "chrome/browser/sync/sync_ui_util.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 #include "chrome/common/url_constants.h" | 26 #include "chrome/common/url_constants.h" |
| 27 #include "chrome/grit/chromium_strings.h" | 27 #include "chrome/grit/chromium_strings.h" |
| 28 #include "chrome/grit/generated_resources.h" | 28 #include "chrome/grit/generated_resources.h" |
| 29 #include "chrome/grit/locale_settings.h" | 29 #include "chrome/grit/locale_settings.h" |
| 30 #include "components/browser_sync/profile_sync_service.h" | 30 #include "components/browser_sync/profile_sync_service.h" |
| 31 #include "components/prefs/pref_service.h" | 31 #include "components/prefs/pref_service.h" |
| 32 #include "components/signin/core/browser/signin_error_controller.h" | 32 #include "components/signin/core/browser/signin_error_controller.h" |
| 33 #include "components/signin/core/browser/signin_manager_base.h" | 33 #include "components/signin/core/browser/signin_manager_base.h" |
| 34 #include "components/strings/grit/components_strings.h" | 34 #include "components/strings/grit/components_strings.h" |
| 35 #include "components/sync/base/model_type.h" | 35 #include "components/sync/base/model_type.h" |
| 36 #include "components/sync/base/sync_prefs.h" | |
| 36 #include "components/sync/engine/cycle/sync_cycle_snapshot.h" | 37 #include "components/sync/engine/cycle/sync_cycle_snapshot.h" |
| 37 #include "components/sync/protocol/proto_enum_conversions.h" | 38 #include "components/sync/protocol/proto_enum_conversions.h" |
| 38 #include "components/sync/protocol/sync_protocol_error.h" | 39 #include "components/sync/protocol/sync_protocol_error.h" |
| 39 #include "google_apis/gaia/google_service_auth_error.h" | 40 #include "google_apis/gaia/google_service_auth_error.h" |
| 40 #include "ui/base/l10n/l10n_util.h" | 41 #include "ui/base/l10n/l10n_util.h" |
| 41 | 42 |
| 42 #if defined(OS_CHROMEOS) | 43 #if defined(OS_CHROMEOS) |
| 43 #include "components/signin/core/account_id/account_id.h" | 44 #include "components/signin/core/account_id/account_id.h" |
| 44 #include "components/user_manager/user_manager.h" | 45 #include "components/user_manager/user_manager.h" |
| 45 #else | 46 #else |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 59 const std::string group_name = | 60 const std::string group_name = |
| 60 base::FieldTrialList::FindFullName("ChromeDashboard"); | 61 base::FieldTrialList::FindFullName("ChromeDashboard"); |
| 61 return group_name == "Enabled"; | 62 return group_name == "Enabled"; |
| 62 } | 63 } |
| 63 | 64 |
| 64 // Returns the message that should be displayed when the user is authenticated | 65 // Returns the message that should be displayed when the user is authenticated |
| 65 // and can connect to the sync server. If the user hasn't yet authenticated, an | 66 // and can connect to the sync server. If the user hasn't yet authenticated, an |
| 66 // empty string is returned. | 67 // empty string is returned. |
| 67 base::string16 GetSyncedStateStatusLabel(ProfileSyncService* service, | 68 base::string16 GetSyncedStateStatusLabel(ProfileSyncService* service, |
| 68 const SigninManagerBase& signin, | 69 const SigninManagerBase& signin, |
| 69 StatusLabelStyle style) { | 70 StatusLabelStyle style, |
| 71 bool all_data_types_synced) { | |
|
Nicolas Zea
2017/01/18 01:15:45
nit: for consistency sake, maybe rename to sync_ev
tommycli
2017/01/18 16:36:09
Done.
| |
| 70 if (!service || service->IsManaged()) { | 72 if (!service || service->IsManaged()) { |
| 71 // User is signed in, but sync is disabled. | 73 // User is signed in, but sync is disabled. |
| 72 return l10n_util::GetStringUTF16(IDS_SIGNED_IN_WITH_SYNC_DISABLED); | 74 return l10n_util::GetStringUTF16(IDS_SIGNED_IN_WITH_SYNC_DISABLED); |
| 73 } else if (!service->IsSyncRequested()) { | 75 } else if (!service->IsSyncRequested()) { |
| 74 // User is signed in, but sync has been stopped. | 76 // User is signed in, but sync has been stopped. |
| 75 return l10n_util::GetStringUTF16(IDS_SIGNED_IN_WITH_SYNC_SUPPRESSED); | 77 return l10n_util::GetStringUTF16(IDS_SIGNED_IN_WITH_SYNC_SUPPRESSED); |
| 76 } else if (!service->IsSyncActive()) { | 78 } else if (!service->IsSyncActive()) { |
| 77 // User is not signed in, or sync is still initializing. | 79 // User is not signed in, or sync is still initializing. |
| 78 return base::string16(); | 80 return base::string16(); |
| 79 } | 81 } |
| 80 | 82 |
| 81 // Message may also carry additional advice with an HTML link, if acceptable. | 83 // Message may also carry additional advice with an HTML link, if acceptable. |
| 82 switch (style) { | 84 switch (style) { |
| 83 case PLAIN_TEXT: | 85 case PLAIN_TEXT: |
| 84 return l10n_util::GetStringUTF16(IDS_SYNC_ACCOUNT_SYNCING); | 86 return l10n_util::GetStringUTF16( |
| 87 all_data_types_synced ? IDS_SYNC_ACCOUNT_SYNCING | |
| 88 : IDS_SYNC_ACCOUNT_SYNCING_CUSTOM_DATA_TYPES); | |
| 85 case WITH_HTML: | 89 case WITH_HTML: |
| 86 if (IsChromeDashboardEnabled()) { | 90 if (IsChromeDashboardEnabled()) { |
| 87 return l10n_util::GetStringFUTF16( | 91 return l10n_util::GetStringFUTF16( |
| 88 IDS_SYNC_ACCOUNT_SYNCING_WITH_MANAGE_LINK_NEW, | 92 IDS_SYNC_ACCOUNT_SYNCING_WITH_MANAGE_LINK_NEW, |
| 89 base::ASCIIToUTF16(chrome::kSyncGoogleDashboardURL)); | 93 base::ASCIIToUTF16(chrome::kSyncGoogleDashboardURL)); |
| 90 } | 94 } |
| 91 return l10n_util::GetStringFUTF16( | 95 return l10n_util::GetStringFUTF16( |
| 92 IDS_SYNC_ACCOUNT_SYNCING_WITH_MANAGE_LINK, | 96 IDS_SYNC_ACCOUNT_SYNCING_WITH_MANAGE_LINK, |
| 93 base::ASCIIToUTF16(chrome::kSyncGoogleDashboardURL)); | 97 base::ASCIIToUTF16(chrome::kSyncGoogleDashboardURL)); |
| 94 default: | 98 default: |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 221 | 225 |
| 222 // For auth errors first check if an auth is in progress. | 226 // For auth errors first check if an auth is in progress. |
| 223 if (signin.AuthInProgress()) { | 227 if (signin.AuthInProgress()) { |
| 224 if (status_label) { | 228 if (status_label) { |
| 225 status_label->assign( | 229 status_label->assign( |
| 226 l10n_util::GetStringUTF16(IDS_SYNC_AUTHENTICATING_LABEL)); | 230 l10n_util::GetStringUTF16(IDS_SYNC_AUTHENTICATING_LABEL)); |
| 227 } | 231 } |
| 228 return PRE_SYNCED; | 232 return PRE_SYNCED; |
| 229 } | 233 } |
| 230 | 234 |
| 235 PrefService* pref_service = profile->GetPrefs(); | |
| 236 syncer::SyncPrefs sync_prefs(pref_service); | |
| 237 bool all_data_types_synced = sync_prefs.HasKeepEverythingSynced(); | |
| 238 | |
| 231 // Check for sync errors if the sync service is enabled. | 239 // Check for sync errors if the sync service is enabled. |
| 232 if (service) { | 240 if (service) { |
| 233 // Since there is no auth in progress, check for an auth error first. | 241 // Since there is no auth in progress, check for an auth error first. |
| 234 AuthError auth_error = | 242 AuthError auth_error = |
| 235 SigninErrorControllerFactory::GetForProfile(profile)->auth_error(); | 243 SigninErrorControllerFactory::GetForProfile(profile)->auth_error(); |
| 236 if (auth_error.state() != AuthError::NONE) { | 244 if (auth_error.state() != AuthError::NONE) { |
| 237 if (status_label && link_label) { | 245 if (status_label && link_label) { |
| 238 GetStatusForAuthError(profile, signin, status_label, link_label, | 246 GetStatusForAuthError(profile, signin, status_label, link_label, |
| 239 action_type); | 247 action_type); |
| 240 } | 248 } |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 263 *action_type = ENTER_PASSPHRASE; | 271 *action_type = ENTER_PASSPHRASE; |
| 264 } | 272 } |
| 265 return SYNC_ERROR; | 273 return SYNC_ERROR; |
| 266 } | 274 } |
| 267 | 275 |
| 268 // Check to see if sync has been disabled via the dasboard and needs to be | 276 // Check to see if sync has been disabled via the dasboard and needs to be |
| 269 // set up once again. | 277 // set up once again. |
| 270 if (!service->IsSyncRequested() && | 278 if (!service->IsSyncRequested() && |
| 271 status.sync_protocol_error.error_type == syncer::NOT_MY_BIRTHDAY) { | 279 status.sync_protocol_error.error_type == syncer::NOT_MY_BIRTHDAY) { |
| 272 if (status_label) { | 280 if (status_label) { |
| 273 status_label->assign(GetSyncedStateStatusLabel(service, | 281 status_label->assign(GetSyncedStateStatusLabel( |
| 274 signin, | 282 service, signin, style, all_data_types_synced)); |
| 275 style)); | |
| 276 } | 283 } |
| 277 return PRE_SYNCED; | 284 return PRE_SYNCED; |
| 278 } | 285 } |
| 279 } | 286 } |
| 280 | 287 |
| 281 // There is no error. Display "Last synced..." message. | 288 // There is no error. Display "Last synced..." message. |
| 282 if (status_label) | 289 if (status_label) { |
| 283 status_label->assign(GetSyncedStateStatusLabel(service, signin, style)); | 290 status_label->assign(GetSyncedStateStatusLabel(service, signin, style, |
| 291 all_data_types_synced)); | |
| 292 } | |
| 284 return SYNCED; | 293 return SYNCED; |
| 285 } else { | 294 } else { |
| 286 // Either show auth error information with a link to re-login, auth in prog, | 295 // Either show auth error information with a link to re-login, auth in prog, |
| 287 // or provide a link to continue with setup. | 296 // or provide a link to continue with setup. |
| 288 if (service->IsFirstSetupInProgress()) { | 297 if (service->IsFirstSetupInProgress()) { |
| 289 result_type = PRE_SYNCED; | 298 result_type = PRE_SYNCED; |
| 290 ProfileSyncService::Status status; | 299 ProfileSyncService::Status status; |
| 291 service->QueryDetailedSyncStatus(&status); | 300 service->QueryDetailedSyncStatus(&status); |
| 292 AuthError auth_error = | 301 AuthError auth_error = |
| 293 SigninErrorControllerFactory::GetForProfile(profile)->auth_error(); | 302 SigninErrorControllerFactory::GetForProfile(profile)->auth_error(); |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 508 base::string16 ConstructTime(int64_t time_in_int) { | 517 base::string16 ConstructTime(int64_t time_in_int) { |
| 509 base::Time time = base::Time::FromInternalValue(time_in_int); | 518 base::Time time = base::Time::FromInternalValue(time_in_int); |
| 510 | 519 |
| 511 // If time is null the format function returns a time in 1969. | 520 // If time is null the format function returns a time in 1969. |
| 512 if (time.is_null()) | 521 if (time.is_null()) |
| 513 return base::string16(); | 522 return base::string16(); |
| 514 return base::TimeFormatFriendlyDateAndTime(time); | 523 return base::TimeFormatFriendlyDateAndTime(time); |
| 515 } | 524 } |
| 516 | 525 |
| 517 } // namespace sync_ui_util | 526 } // namespace sync_ui_util |
| OLD | NEW |