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

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

Issue 2388673002: Revert of [Sync] Move //components/sync to the syncer namespace. (patchset #5 id:40001 of https://co (Closed)
Patch Set: 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 syncer { 26 namespace sync_driver {
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 = GetTimeDebugString(time); 208 time_str = syncer::GetTimeDebugString(time);
209 return time_str; 209 return time_str;
210 } 210 }
211 211
212 std::string GetConnectionStatus(const SyncService::SyncTokenStatus& status) { 212 std::string GetConnectionStatus(
213 const sync_driver::SyncService::SyncTokenStatus& status) {
213 std::string message; 214 std::string message;
214 switch (status.connection_status) { 215 switch (status.connection_status) {
215 case CONNECTION_NOT_ATTEMPTED: 216 case syncer::CONNECTION_NOT_ATTEMPTED:
216 base::StringAppendF(&message, "not attempted"); 217 base::StringAppendF(&message, "not attempted");
217 break; 218 break;
218 case CONNECTION_OK: 219 case syncer::CONNECTION_OK:
219 base::StringAppendF( 220 base::StringAppendF(
220 &message, "OK since %s", 221 &message, "OK since %s",
221 GetTimeStr(status.connection_status_update_time, "n/a").c_str()); 222 GetTimeStr(status.connection_status_update_time, "n/a").c_str());
222 break; 223 break;
223 case CONNECTION_AUTH_ERROR: 224 case syncer::CONNECTION_AUTH_ERROR:
224 base::StringAppendF( 225 base::StringAppendF(
225 &message, "auth error since %s", 226 &message, "auth error since %s",
226 GetTimeStr(status.connection_status_update_time, "n/a").c_str()); 227 GetTimeStr(status.connection_status_update_time, "n/a").c_str());
227 break; 228 break;
228 case CONNECTION_SERVER_ERROR: 229 case syncer::CONNECTION_SERVER_ERROR:
229 base::StringAppendF( 230 base::StringAppendF(
230 &message, "server error since %s", 231 &message, "server error since %s",
231 GetTimeStr(status.connection_status_update_time, "n/a").c_str()); 232 GetTimeStr(status.connection_status_update_time, "n/a").c_str());
232 break; 233 break;
233 default: 234 default:
234 NOTREACHED(); 235 NOTREACHED();
235 } 236 }
236 return message; 237 return message;
237 } 238 }
238 239
239 } // namespace 240 } // namespace
240 241
241 // 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
242 // 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
243 // 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
244 // classes defined above. 245 // classes defined above.
245 std::unique_ptr<base::DictionaryValue> ConstructAboutInformation( 246 std::unique_ptr<base::DictionaryValue> ConstructAboutInformation(
246 SyncService* service, 247 sync_driver::SyncService* service,
247 SigninManagerBase* signin, 248 SigninManagerBase* signin,
248 version_info::Channel channel) { 249 version_info::Channel channel) {
249 std::unique_ptr<base::DictionaryValue> about_info( 250 std::unique_ptr<base::DictionaryValue> about_info(
250 new base::DictionaryValue()); 251 new base::DictionaryValue());
251 252
252 // 'details': A list of sections. 253 // 'details': A list of sections.
253 base::ListValue* stats_list = new base::ListValue(); 254 base::ListValue* stats_list = new base::ListValue();
254 255
255 // 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,
256 // 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
350 about_info->Set(kDetailsKey, stats_list); 351 about_info->Set(kDetailsKey, stats_list);
351 352
352 // Populate all the fields we declared above. 353 // Populate all the fields we declared above.
353 client_version.SetValue(GetVersionString(channel)); 354 client_version.SetValue(GetVersionString(channel));
354 355
355 if (!service) { 356 if (!service) {
356 summary_string.SetValue("Sync service does not exist"); 357 summary_string.SetValue("Sync service does not exist");
357 return about_info; 358 return about_info;
358 } 359 }
359 360
360 SyncStatus full_status; 361 syncer::SyncStatus full_status;
361 bool is_status_valid = service->QueryDetailedSyncStatus(&full_status); 362 bool is_status_valid = service->QueryDetailedSyncStatus(&full_status);
362 bool sync_active = service->IsSyncActive(); 363 bool sync_active = service->IsSyncActive();
363 const SyncCycleSnapshot& snapshot = service->GetLastCycleSnapshot(); 364 const syncer::SyncCycleSnapshot& snapshot = service->GetLastCycleSnapshot();
364 365
365 if (is_status_valid) 366 if (is_status_valid)
366 summary_string.SetValue(service->QuerySyncStatusSummaryString()); 367 summary_string.SetValue(service->QuerySyncStatusSummaryString());
367 368
368 server_url.SetValue(service->sync_service_url().spec()); 369 server_url.SetValue(service->sync_service_url().spec());
369 370
370 if (is_status_valid && !full_status.sync_id.empty()) 371 if (is_status_valid && !full_status.sync_id.empty())
371 sync_id.SetValue(full_status.sync_id); 372 sync_id.SetValue(full_status.sync_id);
372 if (is_status_valid && !full_status.invalidator_client_id.empty()) 373 if (is_status_valid && !full_status.invalidator_client_id.empty())
373 invalidator_id.SetValue(full_status.invalidator_client_id); 374 invalidator_id.SetValue(full_status.invalidator_client_id);
374 if (signin) 375 if (signin)
375 username.SetValue(signin->GetAuthenticatedAccountInfo().email); 376 username.SetValue(signin->GetAuthenticatedAccountInfo().email);
376 377
377 const SyncService::SyncTokenStatus& token_status = 378 const sync_driver::SyncService::SyncTokenStatus& token_status =
378 service->GetSyncTokenStatus(); 379 service->GetSyncTokenStatus();
379 server_connection.SetValue(GetConnectionStatus(token_status)); 380 server_connection.SetValue(GetConnectionStatus(token_status));
380 request_token_time.SetValue( 381 request_token_time.SetValue(
381 GetTimeStr(token_status.token_request_time, "n/a")); 382 GetTimeStr(token_status.token_request_time, "n/a"));
382 receive_token_time.SetValue( 383 receive_token_time.SetValue(
383 GetTimeStr(token_status.token_receive_time, "n/a")); 384 GetTimeStr(token_status.token_receive_time, "n/a"));
384 std::string err = token_status.last_get_token_error.error_message(); 385 std::string err = token_status.last_get_token_error.error_message();
385 token_request_status.SetValue(err.empty() ? "OK" : err); 386 token_request_status.SetValue(err.empty() ? "OK" : err);
386 next_token_request.SetValue( 387 next_token_request.SetValue(
387 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
417 keystore_migration_time.SetValue( 418 keystore_migration_time.SetValue(
418 GetTimeStr(full_status.keystore_migration_time, "Not Migrated")); 419 GetTimeStr(full_status.keystore_migration_time, "Not Migrated"));
419 passphrase_type.SetValue( 420 passphrase_type.SetValue(
420 PassphraseTypeToString(full_status.passphrase_type)); 421 PassphraseTypeToString(full_status.passphrase_type));
421 } 422 }
422 423
423 if (snapshot.is_initialized()) { 424 if (snapshot.is_initialized()) {
424 if (snapshot.legacy_updates_source() != 425 if (snapshot.legacy_updates_source() !=
425 sync_pb::GetUpdatesCallerInfo::UNKNOWN) { 426 sync_pb::GetUpdatesCallerInfo::UNKNOWN) {
426 session_source.SetValue( 427 session_source.SetValue(
427 GetUpdatesSourceString(snapshot.legacy_updates_source())); 428 syncer::GetUpdatesSourceString(snapshot.legacy_updates_source()));
428 } 429 }
429 get_key_result.SetValue(GetSyncerErrorString( 430 get_key_result.SetValue(GetSyncerErrorString(
430 snapshot.model_neutral_state().last_get_key_result)); 431 snapshot.model_neutral_state().last_get_key_result));
431 download_result.SetValue(GetSyncerErrorString( 432 download_result.SetValue(GetSyncerErrorString(
432 snapshot.model_neutral_state().last_download_updates_result)); 433 snapshot.model_neutral_state().last_download_updates_result));
433 commit_result.SetValue( 434 commit_result.SetValue(
434 GetSyncerErrorString(snapshot.model_neutral_state().commit_result)); 435 GetSyncerErrorString(snapshot.model_neutral_state().commit_result));
435 } 436 }
436 437
437 if (is_status_valid) { 438 if (is_status_valid) {
(...skipping 29 matching lines...) Expand all
467 entries.SetValue(snapshot.num_entries()); 468 entries.SetValue(snapshot.num_entries());
468 } 469 }
469 470
470 // 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
471 // details list. 472 // details list.
472 473
473 // We don't need to check is_status_valid here. 474 // We don't need to check is_status_valid here.
474 // full_status.sync_protocol_error is exported directly from the 475 // full_status.sync_protocol_error is exported directly from the
475 // ProfileSyncService, even if the backend doesn't exist. 476 // ProfileSyncService, even if the backend doesn't exist.
476 const bool actionable_error_detected = 477 const bool actionable_error_detected =
477 full_status.sync_protocol_error.error_type != UNKNOWN_ERROR && 478 full_status.sync_protocol_error.error_type != syncer::UNKNOWN_ERROR &&
478 full_status.sync_protocol_error.error_type != SYNC_SUCCESS; 479 full_status.sync_protocol_error.error_type != syncer::SYNC_SUCCESS;
479 480
480 about_info->SetBoolean("actionable_error_detected", 481 about_info->SetBoolean("actionable_error_detected",
481 actionable_error_detected); 482 actionable_error_detected);
482 483
483 // 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
484 // actionable_error_detected is set. 485 // actionable_error_detected is set.
485 486
486 base::ListValue* actionable_error = new base::ListValue(); 487 base::ListValue* actionable_error = new base::ListValue();
487 about_info->Set("actionable_error", actionable_error); 488 about_info->Set("actionable_error", actionable_error);
488 489
489 StringSyncStat error_type(actionable_error, "Error Type"); 490 StringSyncStat error_type(actionable_error, "Error Type");
490 StringSyncStat action(actionable_error, "Action"); 491 StringSyncStat action(actionable_error, "Action");
491 StringSyncStat url(actionable_error, "URL"); 492 StringSyncStat url(actionable_error, "URL");
492 StringSyncStat description(actionable_error, "Error Description"); 493 StringSyncStat description(actionable_error, "Error Description");
493 494
494 if (actionable_error_detected) { 495 if (actionable_error_detected) {
495 error_type.SetValue( 496 error_type.SetValue(syncer::GetSyncErrorTypeString(
496 GetSyncErrorTypeString(full_status.sync_protocol_error.error_type)); 497 full_status.sync_protocol_error.error_type));
497 action.SetValue( 498 action.SetValue(
498 GetClientActionString(full_status.sync_protocol_error.action)); 499 syncer::GetClientActionString(full_status.sync_protocol_error.action));
499 url.SetValue(full_status.sync_protocol_error.url); 500 url.SetValue(full_status.sync_protocol_error.url);
500 description.SetValue(full_status.sync_protocol_error.error_description); 501 description.SetValue(full_status.sync_protocol_error.error_description);
501 } 502 }
502 503
503 about_info->SetBoolean("unrecoverable_error_detected", 504 about_info->SetBoolean("unrecoverable_error_detected",
504 service->HasUnrecoverableError()); 505 service->HasUnrecoverableError());
505 506
506 if (service->HasUnrecoverableError()) { 507 if (service->HasUnrecoverableError()) {
507 tracked_objects::Location loc(service->unrecoverable_error_location()); 508 tracked_objects::Location loc(service->unrecoverable_error_location());
508 std::string location_str; 509 std::string location_str;
509 loc.Write(true, true, &location_str); 510 loc.Write(true, true, &location_str);
510 std::string unrecoverable_error_message = 511 std::string unrecoverable_error_message =
511 "Unrecoverable error detected at " + location_str + ": " + 512 "Unrecoverable error detected at " + location_str + ": " +
512 service->unrecoverable_error_message(); 513 service->unrecoverable_error_message();
513 about_info->SetString("unrecoverable_error_message", 514 about_info->SetString("unrecoverable_error_message",
514 unrecoverable_error_message); 515 unrecoverable_error_message);
515 } 516 }
516 517
517 about_info->Set("type_status", service->GetTypeStatusMap()); 518 about_info->Set("type_status", service->GetTypeStatusMap());
518 519
519 return about_info; 520 return about_info;
520 } 521 }
521 522
522 } // namespace sync_ui_util 523 } // namespace sync_ui_util
523 524
524 } // namespace syncer 525 } // namespace sync_driver
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