| 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 "components/sync/driver/about_sync_util.h" | 5 #include "components/sync/driver/about_sync_util.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
| 13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "components/signin/core/browser/signin_manager_base.h" | 15 #include "components/signin/core/browser/signin_manager_base.h" |
| 16 #include "components/sync/api/time.h" | 16 #include "components/sync/api/time.h" |
| 17 #include "components/sync/driver/sync_service.h" | 17 #include "components/sync/driver/sync_service.h" |
| 18 #include "components/sync/engine/cycle/sync_cycle_snapshot.h" | 18 #include "components/sync/engine/cycle/sync_cycle_snapshot.h" |
| 19 #include "components/sync/engine/sync_status.h" | 19 #include "components/sync/engine/sync_status.h" |
| 20 #include "components/sync/engine/sync_string_conversions.h" | 20 #include "components/sync/engine/sync_string_conversions.h" |
| 21 #include "components/sync/protocol/proto_enum_conversions.h" | 21 #include "components/sync/protocol/proto_enum_conversions.h" |
| 22 #include "components/version_info/version_info.h" | 22 #include "components/version_info/version_info.h" |
| 23 | 23 |
| 24 using base::DictionaryValue; | 24 using base::DictionaryValue; |
| 25 using base::ListValue; | 25 using base::ListValue; |
| 26 | 26 |
| 27 namespace sync_driver { | 27 namespace syncer { |
| 28 | 28 |
| 29 namespace sync_ui_util { | 29 namespace sync_ui_util { |
| 30 | 30 |
| 31 const char kIdentityTitle[] = "Identity"; | 31 const char kIdentityTitle[] = "Identity"; |
| 32 const char kDetailsKey[] = "details"; | 32 const char kDetailsKey[] = "details"; |
| 33 | 33 |
| 34 // Resource paths. | 34 // Resource paths. |
| 35 const char kAboutJS[] = "about.js"; | 35 const char kAboutJS[] = "about.js"; |
| 36 const char kChromeSyncJS[] = "chrome_sync.js"; | 36 const char kChromeSyncJS[] = "chrome_sync.js"; |
| 37 const char kDataJS[] = "data.js"; | 37 const char kDataJS[] = "data.js"; |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 return version_info::GetProductName() + " " + version_info::GetOSType() + | 199 return version_info::GetProductName() + " " + version_info::GetOSType() + |
| 200 " " + version_info::GetVersionNumber() + " (" + | 200 " " + version_info::GetVersionNumber() + " (" + |
| 201 version_info::GetLastChange() + ")" + version_modifier; | 201 version_info::GetLastChange() + ")" + version_modifier; |
| 202 } | 202 } |
| 203 | 203 |
| 204 std::string GetTimeStr(base::Time time, const std::string& default_msg) { | 204 std::string GetTimeStr(base::Time time, const std::string& default_msg) { |
| 205 std::string time_str; | 205 std::string time_str; |
| 206 if (time.is_null()) | 206 if (time.is_null()) |
| 207 time_str = default_msg; | 207 time_str = default_msg; |
| 208 else | 208 else |
| 209 time_str = syncer::GetTimeDebugString(time); | 209 time_str = GetTimeDebugString(time); |
| 210 return time_str; | 210 return time_str; |
| 211 } | 211 } |
| 212 | 212 |
| 213 std::string GetConnectionStatus( | 213 std::string GetConnectionStatus(const SyncService::SyncTokenStatus& status) { |
| 214 const sync_driver::SyncService::SyncTokenStatus& status) { | |
| 215 std::string message; | 214 std::string message; |
| 216 switch (status.connection_status) { | 215 switch (status.connection_status) { |
| 217 case syncer::CONNECTION_NOT_ATTEMPTED: | 216 case CONNECTION_NOT_ATTEMPTED: |
| 218 base::StringAppendF(&message, "not attempted"); | 217 base::StringAppendF(&message, "not attempted"); |
| 219 break; | 218 break; |
| 220 case syncer::CONNECTION_OK: | 219 case CONNECTION_OK: |
| 221 base::StringAppendF( | 220 base::StringAppendF( |
| 222 &message, "OK since %s", | 221 &message, "OK since %s", |
| 223 GetTimeStr(status.connection_status_update_time, "n/a").c_str()); | 222 GetTimeStr(status.connection_status_update_time, "n/a").c_str()); |
| 224 break; | 223 break; |
| 225 case syncer::CONNECTION_AUTH_ERROR: | 224 case CONNECTION_AUTH_ERROR: |
| 226 base::StringAppendF( | 225 base::StringAppendF( |
| 227 &message, "auth error since %s", | 226 &message, "auth error since %s", |
| 228 GetTimeStr(status.connection_status_update_time, "n/a").c_str()); | 227 GetTimeStr(status.connection_status_update_time, "n/a").c_str()); |
| 229 break; | 228 break; |
| 230 case syncer::CONNECTION_SERVER_ERROR: | 229 case CONNECTION_SERVER_ERROR: |
| 231 base::StringAppendF( | 230 base::StringAppendF( |
| 232 &message, "server error since %s", | 231 &message, "server error since %s", |
| 233 GetTimeStr(status.connection_status_update_time, "n/a").c_str()); | 232 GetTimeStr(status.connection_status_update_time, "n/a").c_str()); |
| 234 break; | 233 break; |
| 235 default: | 234 default: |
| 236 NOTREACHED(); | 235 NOTREACHED(); |
| 237 } | 236 } |
| 238 return message; | 237 return message; |
| 239 } | 238 } |
| 240 | 239 |
| 241 } // namespace | 240 } // namespace |
| 242 | 241 |
| 243 // This function both defines the structure of the message to be returned and | 242 // This function both defines the structure of the message to be returned and |
| 244 // its contents. Most of the message consists of simple fields in about:sync | 243 // its contents. Most of the message consists of simple fields in about:sync |
| 245 // which are grouped into sections and populated with the help of the SyncStat | 244 // which are grouped into sections and populated with the help of the SyncStat |
| 246 // classes defined above. | 245 // classes defined above. |
| 247 std::unique_ptr<base::DictionaryValue> ConstructAboutInformation( | 246 std::unique_ptr<base::DictionaryValue> ConstructAboutInformation( |
| 248 sync_driver::SyncService* service, | 247 SyncService* service, |
| 249 SigninManagerBase* signin, | 248 SigninManagerBase* signin, |
| 250 version_info::Channel channel) { | 249 version_info::Channel channel) { |
| 251 std::unique_ptr<base::DictionaryValue> about_info( | 250 std::unique_ptr<base::DictionaryValue> about_info( |
| 252 new base::DictionaryValue()); | 251 new base::DictionaryValue()); |
| 253 | 252 |
| 254 // 'details': A list of sections. | 253 // 'details': A list of sections. |
| 255 base::ListValue* stats_list = new base::ListValue(); | 254 base::ListValue* stats_list = new base::ListValue(); |
| 256 | 255 |
| 257 // The following lines define the sections and their fields. For each field, | 256 // The following lines define the sections and their fields. For each field, |
| 258 // a class is instantiated, which allows us to reference the fields in | 257 // a class is instantiated, which allows us to reference the fields in |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 about_info->Set(kDetailsKey, stats_list); | 351 about_info->Set(kDetailsKey, stats_list); |
| 353 | 352 |
| 354 // Populate all the fields we declared above. | 353 // Populate all the fields we declared above. |
| 355 client_version.SetValue(GetVersionString(channel)); | 354 client_version.SetValue(GetVersionString(channel)); |
| 356 | 355 |
| 357 if (!service) { | 356 if (!service) { |
| 358 summary_string.SetValue("Sync service does not exist"); | 357 summary_string.SetValue("Sync service does not exist"); |
| 359 return about_info; | 358 return about_info; |
| 360 } | 359 } |
| 361 | 360 |
| 362 syncer::SyncStatus full_status; | 361 SyncStatus full_status; |
| 363 bool is_status_valid = service->QueryDetailedSyncStatus(&full_status); | 362 bool is_status_valid = service->QueryDetailedSyncStatus(&full_status); |
| 364 bool sync_active = service->IsSyncActive(); | 363 bool sync_active = service->IsSyncActive(); |
| 365 const syncer::SyncCycleSnapshot& snapshot = service->GetLastCycleSnapshot(); | 364 const SyncCycleSnapshot& snapshot = service->GetLastCycleSnapshot(); |
| 366 | 365 |
| 367 if (is_status_valid) | 366 if (is_status_valid) |
| 368 summary_string.SetValue(service->QuerySyncStatusSummaryString()); | 367 summary_string.SetValue(service->QuerySyncStatusSummaryString()); |
| 369 | 368 |
| 370 server_url.SetValue(service->sync_service_url().spec()); | 369 server_url.SetValue(service->sync_service_url().spec()); |
| 371 | 370 |
| 372 if (is_status_valid && !full_status.sync_id.empty()) | 371 if (is_status_valid && !full_status.sync_id.empty()) |
| 373 sync_id.SetValue(full_status.sync_id); | 372 sync_id.SetValue(full_status.sync_id); |
| 374 if (is_status_valid && !full_status.invalidator_client_id.empty()) | 373 if (is_status_valid && !full_status.invalidator_client_id.empty()) |
| 375 invalidator_id.SetValue(full_status.invalidator_client_id); | 374 invalidator_id.SetValue(full_status.invalidator_client_id); |
| 376 if (signin) | 375 if (signin) |
| 377 username.SetValue(signin->GetAuthenticatedAccountInfo().email); | 376 username.SetValue(signin->GetAuthenticatedAccountInfo().email); |
| 378 | 377 |
| 379 const sync_driver::SyncService::SyncTokenStatus& token_status = | 378 const SyncService::SyncTokenStatus& token_status = |
| 380 service->GetSyncTokenStatus(); | 379 service->GetSyncTokenStatus(); |
| 381 server_connection.SetValue(GetConnectionStatus(token_status)); | 380 server_connection.SetValue(GetConnectionStatus(token_status)); |
| 382 request_token_time.SetValue( | 381 request_token_time.SetValue( |
| 383 GetTimeStr(token_status.token_request_time, "n/a")); | 382 GetTimeStr(token_status.token_request_time, "n/a")); |
| 384 receive_token_time.SetValue( | 383 receive_token_time.SetValue( |
| 385 GetTimeStr(token_status.token_receive_time, "n/a")); | 384 GetTimeStr(token_status.token_receive_time, "n/a")); |
| 386 std::string err = token_status.last_get_token_error.error_message(); | 385 std::string err = token_status.last_get_token_error.error_message(); |
| 387 token_request_status.SetValue(err.empty() ? "OK" : err); | 386 token_request_status.SetValue(err.empty() ? "OK" : err); |
| 388 next_token_request.SetValue( | 387 next_token_request.SetValue( |
| 389 GetTimeStr(token_status.next_token_request_time, "not scheduled")); | 388 GetTimeStr(token_status.next_token_request_time, "not scheduled")); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 419 keystore_migration_time.SetValue( | 418 keystore_migration_time.SetValue( |
| 420 GetTimeStr(full_status.keystore_migration_time, "Not Migrated")); | 419 GetTimeStr(full_status.keystore_migration_time, "Not Migrated")); |
| 421 passphrase_type.SetValue( | 420 passphrase_type.SetValue( |
| 422 PassphraseTypeToString(full_status.passphrase_type)); | 421 PassphraseTypeToString(full_status.passphrase_type)); |
| 423 } | 422 } |
| 424 | 423 |
| 425 if (snapshot.is_initialized()) { | 424 if (snapshot.is_initialized()) { |
| 426 if (snapshot.legacy_updates_source() != | 425 if (snapshot.legacy_updates_source() != |
| 427 sync_pb::GetUpdatesCallerInfo::UNKNOWN) { | 426 sync_pb::GetUpdatesCallerInfo::UNKNOWN) { |
| 428 session_source.SetValue( | 427 session_source.SetValue( |
| 429 syncer::GetUpdatesSourceString(snapshot.legacy_updates_source())); | 428 GetUpdatesSourceString(snapshot.legacy_updates_source())); |
| 430 } | 429 } |
| 431 get_key_result.SetValue(GetSyncerErrorString( | 430 get_key_result.SetValue(GetSyncerErrorString( |
| 432 snapshot.model_neutral_state().last_get_key_result)); | 431 snapshot.model_neutral_state().last_get_key_result)); |
| 433 download_result.SetValue(GetSyncerErrorString( | 432 download_result.SetValue(GetSyncerErrorString( |
| 434 snapshot.model_neutral_state().last_download_updates_result)); | 433 snapshot.model_neutral_state().last_download_updates_result)); |
| 435 commit_result.SetValue( | 434 commit_result.SetValue( |
| 436 GetSyncerErrorString(snapshot.model_neutral_state().commit_result)); | 435 GetSyncerErrorString(snapshot.model_neutral_state().commit_result)); |
| 437 } | 436 } |
| 438 | 437 |
| 439 if (is_status_valid) { | 438 if (is_status_valid) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 469 entries.SetValue(snapshot.num_entries()); | 468 entries.SetValue(snapshot.num_entries()); |
| 470 } | 469 } |
| 471 | 470 |
| 472 // The values set from this point onwards do not belong in the | 471 // The values set from this point onwards do not belong in the |
| 473 // details list. | 472 // details list. |
| 474 | 473 |
| 475 // We don't need to check is_status_valid here. | 474 // We don't need to check is_status_valid here. |
| 476 // full_status.sync_protocol_error is exported directly from the | 475 // full_status.sync_protocol_error is exported directly from the |
| 477 // ProfileSyncService, even if the backend doesn't exist. | 476 // ProfileSyncService, even if the backend doesn't exist. |
| 478 const bool actionable_error_detected = | 477 const bool actionable_error_detected = |
| 479 full_status.sync_protocol_error.error_type != syncer::UNKNOWN_ERROR && | 478 full_status.sync_protocol_error.error_type != UNKNOWN_ERROR && |
| 480 full_status.sync_protocol_error.error_type != syncer::SYNC_SUCCESS; | 479 full_status.sync_protocol_error.error_type != SYNC_SUCCESS; |
| 481 | 480 |
| 482 about_info->SetBoolean("actionable_error_detected", | 481 about_info->SetBoolean("actionable_error_detected", |
| 483 actionable_error_detected); | 482 actionable_error_detected); |
| 484 | 483 |
| 485 // NOTE: We won't bother showing any of the following values unless | 484 // NOTE: We won't bother showing any of the following values unless |
| 486 // actionable_error_detected is set. | 485 // actionable_error_detected is set. |
| 487 | 486 |
| 488 base::ListValue* actionable_error = new base::ListValue(); | 487 base::ListValue* actionable_error = new base::ListValue(); |
| 489 about_info->Set("actionable_error", actionable_error); | 488 about_info->Set("actionable_error", actionable_error); |
| 490 | 489 |
| 491 StringSyncStat error_type(actionable_error, "Error Type"); | 490 StringSyncStat error_type(actionable_error, "Error Type"); |
| 492 StringSyncStat action(actionable_error, "Action"); | 491 StringSyncStat action(actionable_error, "Action"); |
| 493 StringSyncStat url(actionable_error, "URL"); | 492 StringSyncStat url(actionable_error, "URL"); |
| 494 StringSyncStat description(actionable_error, "Error Description"); | 493 StringSyncStat description(actionable_error, "Error Description"); |
| 495 | 494 |
| 496 if (actionable_error_detected) { | 495 if (actionable_error_detected) { |
| 497 error_type.SetValue(syncer::GetSyncErrorTypeString( | 496 error_type.SetValue( |
| 498 full_status.sync_protocol_error.error_type)); | 497 GetSyncErrorTypeString(full_status.sync_protocol_error.error_type)); |
| 499 action.SetValue( | 498 action.SetValue( |
| 500 syncer::GetClientActionString(full_status.sync_protocol_error.action)); | 499 GetClientActionString(full_status.sync_protocol_error.action)); |
| 501 url.SetValue(full_status.sync_protocol_error.url); | 500 url.SetValue(full_status.sync_protocol_error.url); |
| 502 description.SetValue(full_status.sync_protocol_error.error_description); | 501 description.SetValue(full_status.sync_protocol_error.error_description); |
| 503 } | 502 } |
| 504 | 503 |
| 505 about_info->SetBoolean("unrecoverable_error_detected", | 504 about_info->SetBoolean("unrecoverable_error_detected", |
| 506 service->HasUnrecoverableError()); | 505 service->HasUnrecoverableError()); |
| 507 | 506 |
| 508 if (service->HasUnrecoverableError()) { | 507 if (service->HasUnrecoverableError()) { |
| 509 tracked_objects::Location loc(service->unrecoverable_error_location()); | 508 tracked_objects::Location loc(service->unrecoverable_error_location()); |
| 510 std::string location_str; | 509 std::string location_str; |
| 511 loc.Write(true, true, &location_str); | 510 loc.Write(true, true, &location_str); |
| 512 std::string unrecoverable_error_message = | 511 std::string unrecoverable_error_message = |
| 513 "Unrecoverable error detected at " + location_str + ": " + | 512 "Unrecoverable error detected at " + location_str + ": " + |
| 514 service->unrecoverable_error_message(); | 513 service->unrecoverable_error_message(); |
| 515 about_info->SetString("unrecoverable_error_message", | 514 about_info->SetString("unrecoverable_error_message", |
| 516 unrecoverable_error_message); | 515 unrecoverable_error_message); |
| 517 } | 516 } |
| 518 | 517 |
| 519 about_info->Set("type_status", service->GetTypeStatusMap()); | 518 about_info->Set("type_status", service->GetTypeStatusMap()); |
| 520 | 519 |
| 521 return about_info; | 520 return about_info; |
| 522 } | 521 } |
| 523 | 522 |
| 524 } // namespace sync_ui_util | 523 } // namespace sync_ui_util |
| 525 | 524 |
| 526 } // namespace sync_driver | 525 } // namespace syncer |
| OLD | NEW |