Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: components/sync/driver/about_sync_util.cc

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

Powered by Google App Engine
This is Rietveld 408576698