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

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

Issue 2889163002: Remove raw DictionaryValue::Set in //components (Closed)
Patch Set: Created 3 years, 7 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"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 const char kTypes[] = "types"; 65 const char kTypes[] = "types";
66 const char kUpdate[] = "update"; 66 const char kUpdate[] = "update";
67 67
68 namespace { 68 namespace {
69 69
70 // Creates a 'section' for display on about:sync, consisting of a title and a 70 // Creates a 'section' for display on about:sync, consisting of a title and a
71 // list of fields. Returns a pointer to the new section. Note that 71 // list of fields. Returns a pointer to the new section. Note that
72 // |parent_list|, not the caller, owns the newly added section. 72 // |parent_list|, not the caller, owns the newly added section.
73 base::ListValue* AddSection(base::ListValue* parent_list, 73 base::ListValue* AddSection(base::ListValue* parent_list,
74 const std::string& title) { 74 const std::string& title) {
75 std::unique_ptr<base::DictionaryValue> section(new base::DictionaryValue()); 75 auto section = base::MakeUnique<base::DictionaryValue>();
76 base::ListValue* section_contents = new base::ListValue();
77 section->SetString("title", title); 76 section->SetString("title", title);
78 section->Set("data", section_contents); 77 base::ListValue* section_contents =
78 section->SetList("data", base::MakeUnique<base::ListValue>());
79 section->SetBoolean("is_sensitive", false); 79 section->SetBoolean("is_sensitive", false);
80 // If the following |Append| results in a reallocation, pointers to the 80 // If the following |Append| results in a reallocation, pointers to the
81 // members of |parent_list| will be invalidated. This would result in 81 // members of |parent_list| will be invalidated. This would result in
82 // use-after-free in |*SyncStat::SetValue|. This is why the following CHECK is 82 // use-after-free in |*SyncStat::SetValue|. This is why the following CHECK is
83 // necessary to ensure no reallocation takes place. 83 // necessary to ensure no reallocation takes place.
84 // TODO(crbug.com/702230): Remove the usages of raw pointers in this file. 84 // TODO(crbug.com/702230): Remove the usages of raw pointers in this file.
85 CHECK_LT(parent_list->GetSize(), parent_list->capacity()); 85 CHECK_LT(parent_list->GetSize(), parent_list->capacity());
86 parent_list->Append(std::move(section)); 86 parent_list->Append(std::move(section));
87 return section_contents; 87 return section_contents;
88 } 88 }
89 89
90 // Same as AddSection, but for data that should be elided when dumped into text 90 // Same as AddSection, but for data that should be elided when dumped into text
91 // form and posted in a public forum (e.g. unique identifiers). 91 // form and posted in a public forum (e.g. unique identifiers).
92 base::ListValue* AddSensitiveSection(base::ListValue* parent_list, 92 base::ListValue* AddSensitiveSection(base::ListValue* parent_list,
93 const std::string& title) { 93 const std::string& title) {
94 std::unique_ptr<base::DictionaryValue> section(new base::DictionaryValue()); 94 auto section = base::MakeUnique<base::DictionaryValue>();
95 base::ListValue* section_contents = new base::ListValue();
96 section->SetString("title", title); 95 section->SetString("title", title);
97 section->Set("data", section_contents); 96 base::ListValue* section_contents =
97 section->SetList("data", base::MakeUnique<base::ListValue>());
98 section->SetBoolean("is_sensitive", true); 98 section->SetBoolean("is_sensitive", true);
99 // If the following |Append| results in a reallocation, pointers to 99 // If the following |Append| results in a reallocation, pointers to
100 // |parent_list| and its members will be invalidated. This would result in 100 // |parent_list| and its members will be invalidated. This would result in
101 // use-after-free in |*SyncStat::SetValue|. This is why the following CHECK is 101 // use-after-free in |*SyncStat::SetValue|. This is why the following CHECK is
102 // necessary to ensure no reallocation takes place. 102 // necessary to ensure no reallocation takes place.
103 CHECK_LT(parent_list->GetSize(), parent_list->capacity()); 103 CHECK_LT(parent_list->GetSize(), parent_list->capacity());
104 // TODO(crbug.com/702230): Remove the usages of raw pointers in this file. 104 // TODO(crbug.com/702230): Remove the usages of raw pointers in this file.
105 parent_list->Append(std::move(section)); 105 parent_list->Append(std::move(section));
106 return section_contents; 106 return section_contents;
107 } 107 }
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 } // namespace 273 } // namespace
274 274
275 // This function both defines the structure of the message to be returned and 275 // This function both defines the structure of the message to be returned and
276 // its contents. Most of the message consists of simple fields in about:sync 276 // its contents. Most of the message consists of simple fields in about:sync
277 // which are grouped into sections and populated with the help of the SyncStat 277 // which are grouped into sections and populated with the help of the SyncStat
278 // classes defined above. 278 // classes defined above.
279 std::unique_ptr<base::DictionaryValue> ConstructAboutInformation( 279 std::unique_ptr<base::DictionaryValue> ConstructAboutInformation(
280 SyncService* service, 280 SyncService* service,
281 SigninManagerBase* signin, 281 SigninManagerBase* signin,
282 version_info::Channel channel) { 282 version_info::Channel channel) {
283 std::unique_ptr<base::DictionaryValue> about_info( 283 auto about_info = base::MakeUnique<base::DictionaryValue>();
284 new base::DictionaryValue());
285 284
286 // 'details': A list of sections. 285 // 'details': A list of sections.
287 base::ListValue* stats_list = new base::ListValue(); 286 auto stats_list = base::MakeUnique<base::ListValue>();
288 // TODO(crbug.com/702230): Remove the usages of raw pointers in this file. 287 // TODO(crbug.com/702230): Remove the usages of raw pointers in this file.
289 stats_list->Reserve(12); 288 stats_list->Reserve(12);
290 289
291 // The following lines define the sections and their fields. For each field, 290 // The following lines define the sections and their fields. For each field,
292 // a class is instantiated, which allows us to reference the fields in 291 // a class is instantiated, which allows us to reference the fields in
293 // 'setter' code later on in this function. 292 // 'setter' code later on in this function.
294 base::ListValue* section_summary = AddSection(stats_list, "Summary"); 293 base::ListValue* section_summary = AddSection(stats_list.get(), "Summary");
295 // TODO(crbug.com/702230): Remove the usages of raw pointers in this file. 294 // TODO(crbug.com/702230): Remove the usages of raw pointers in this file.
296 section_summary->Reserve(1); 295 section_summary->Reserve(1);
297 StringSyncStat summary_string(section_summary, "Summary"); 296 StringSyncStat summary_string(section_summary, "Summary");
298 297
299 base::ListValue* section_version = AddSection(stats_list, "Version Info"); 298 base::ListValue* section_version =
299 AddSection(stats_list.get(), "Version Info");
300 // TODO(crbug.com/702230): Remove the usages of raw pointers in this file. 300 // TODO(crbug.com/702230): Remove the usages of raw pointers in this file.
301 section_version->Reserve(2); 301 section_version->Reserve(2);
302 StringSyncStat client_version(section_version, "Client Version"); 302 StringSyncStat client_version(section_version, "Client Version");
303 StringSyncStat server_url(section_version, "Server URL"); 303 StringSyncStat server_url(section_version, "Server URL");
304 304
305 base::ListValue* section_identity = 305 base::ListValue* section_identity =
306 AddSensitiveSection(stats_list, kIdentityTitle); 306 AddSensitiveSection(stats_list.get(), kIdentityTitle);
307 // TODO(crbug.com/702230): Remove the usages of raw pointers in this file. 307 // TODO(crbug.com/702230): Remove the usages of raw pointers in this file.
308 section_identity->Reserve(3); 308 section_identity->Reserve(3);
309 StringSyncStat sync_id(section_identity, "Sync Client ID"); 309 StringSyncStat sync_id(section_identity, "Sync Client ID");
310 StringSyncStat invalidator_id(section_identity, "Invalidator Client ID"); 310 StringSyncStat invalidator_id(section_identity, "Invalidator Client ID");
311 StringSyncStat username(section_identity, "Username"); 311 StringSyncStat username(section_identity, "Username");
312 312
313 base::ListValue* section_credentials = AddSection(stats_list, "Credentials"); 313 base::ListValue* section_credentials =
314 AddSection(stats_list.get(), "Credentials");
314 // TODO(crbug.com/702230): Remove the usages of raw pointers in this file. 315 // TODO(crbug.com/702230): Remove the usages of raw pointers in this file.
315 section_credentials->Reserve(4); 316 section_credentials->Reserve(4);
316 StringSyncStat request_token_time(section_credentials, "Requested Token"); 317 StringSyncStat request_token_time(section_credentials, "Requested Token");
317 StringSyncStat receive_token_time(section_credentials, "Received Token"); 318 StringSyncStat receive_token_time(section_credentials, "Received Token");
318 StringSyncStat token_request_status(section_credentials, 319 StringSyncStat token_request_status(section_credentials,
319 "Token Request Status"); 320 "Token Request Status");
320 StringSyncStat next_token_request(section_credentials, "Next Token Request"); 321 StringSyncStat next_token_request(section_credentials, "Next Token Request");
321 322
322 base::ListValue* section_local = AddSection(stats_list, "Local State"); 323 base::ListValue* section_local = AddSection(stats_list.get(), "Local State");
323 // TODO(crbug.com/702230): Remove the usages of raw pointers in this file. 324 // TODO(crbug.com/702230): Remove the usages of raw pointers in this file.
324 section_local->Reserve(7); 325 section_local->Reserve(7);
325 StringSyncStat server_connection(section_local, "Server Connection"); 326 StringSyncStat server_connection(section_local, "Server Connection");
326 StringSyncStat last_synced(section_local, "Last Synced"); 327 StringSyncStat last_synced(section_local, "Last Synced");
327 BoolSyncStat is_setup_complete(section_local, 328 BoolSyncStat is_setup_complete(section_local,
328 "Sync First-Time Setup Complete"); 329 "Sync First-Time Setup Complete");
329 StringSyncStat backend_initialization(section_local, 330 StringSyncStat backend_initialization(section_local,
330 "Sync Backend Initialization"); 331 "Sync Backend Initialization");
331 BoolSyncStat is_syncing(section_local, "Syncing"); 332 BoolSyncStat is_syncing(section_local, "Syncing");
332 BoolSyncStat is_local_sync_enabled(section_local, 333 BoolSyncStat is_local_sync_enabled(section_local,
333 "Local sync backend enabled"); 334 "Local sync backend enabled");
334 StringSyncStat local_backend_path(section_local, "Local backend path"); 335 StringSyncStat local_backend_path(section_local, "Local backend path");
335 336
336 base::ListValue* section_network = AddSection(stats_list, "Network"); 337 base::ListValue* section_network = AddSection(stats_list.get(), "Network");
337 // TODO(crbug.com/702230): Remove the usages of raw pointers in this file. 338 // TODO(crbug.com/702230): Remove the usages of raw pointers in this file.
338 section_network->Reserve(3); 339 section_network->Reserve(3);
339 BoolSyncStat is_throttled(section_network, "Throttled"); 340 BoolSyncStat is_throttled(section_network, "Throttled");
340 StringSyncStat retry_time(section_network, "Retry time (maybe stale)"); 341 StringSyncStat retry_time(section_network, "Retry time (maybe stale)");
341 BoolSyncStat are_notifications_enabled(section_network, 342 BoolSyncStat are_notifications_enabled(section_network,
342 "Notifications Enabled"); 343 "Notifications Enabled");
343 344
344 base::ListValue* section_encryption = AddSection(stats_list, "Encryption"); 345 base::ListValue* section_encryption =
346 AddSection(stats_list.get(), "Encryption");
345 // TODO(crbug.com/702230): Remove the usages of raw pointers in this file. 347 // TODO(crbug.com/702230): Remove the usages of raw pointers in this file.
346 section_encryption->Reserve(9); 348 section_encryption->Reserve(9);
347 BoolSyncStat is_using_explicit_passphrase(section_encryption, 349 BoolSyncStat is_using_explicit_passphrase(section_encryption,
348 "Explicit Passphrase"); 350 "Explicit Passphrase");
349 BoolSyncStat is_passphrase_required(section_encryption, 351 BoolSyncStat is_passphrase_required(section_encryption,
350 "Passphrase Required"); 352 "Passphrase Required");
351 BoolSyncStat is_cryptographer_ready(section_encryption, 353 BoolSyncStat is_cryptographer_ready(section_encryption,
352 "Cryptographer Ready"); 354 "Cryptographer Ready");
353 BoolSyncStat has_pending_keys(section_encryption, 355 BoolSyncStat has_pending_keys(section_encryption,
354 "Cryptographer Has Pending Keys"); 356 "Cryptographer Has Pending Keys");
355 StringSyncStat encrypted_types(section_encryption, "Encrypted Types"); 357 StringSyncStat encrypted_types(section_encryption, "Encrypted Types");
356 BoolSyncStat has_keystore_key(section_encryption, "Has Keystore Key"); 358 BoolSyncStat has_keystore_key(section_encryption, "Has Keystore Key");
357 StringSyncStat keystore_migration_time(section_encryption, 359 StringSyncStat keystore_migration_time(section_encryption,
358 "Keystore Migration Time"); 360 "Keystore Migration Time");
359 StringSyncStat passphrase_type(section_encryption, "Passphrase Type"); 361 StringSyncStat passphrase_type(section_encryption, "Passphrase Type");
360 StringSyncStat passphrase_time(section_encryption, "Passphrase Time"); 362 StringSyncStat passphrase_time(section_encryption, "Passphrase Time");
361 363
362 base::ListValue* section_last_session = 364 base::ListValue* section_last_session =
363 AddSection(stats_list, "Status from Last Completed Session"); 365 AddSection(stats_list.get(), "Status from Last Completed Session");
364 // TODO(crbug.com/702230): Remove the usages of raw pointers in this file. 366 // TODO(crbug.com/702230): Remove the usages of raw pointers in this file.
365 section_last_session->Reserve(4); 367 section_last_session->Reserve(4);
366 StringSyncStat session_source(section_last_session, "Sync Source"); 368 StringSyncStat session_source(section_last_session, "Sync Source");
367 StringSyncStat get_key_result(section_last_session, "GetKey Step Result"); 369 StringSyncStat get_key_result(section_last_session, "GetKey Step Result");
368 StringSyncStat download_result(section_last_session, "Download Step Result"); 370 StringSyncStat download_result(section_last_session, "Download Step Result");
369 StringSyncStat commit_result(section_last_session, "Commit Step Result"); 371 StringSyncStat commit_result(section_last_session, "Commit Step Result");
370 372
371 base::ListValue* section_counters = AddSection(stats_list, "Running Totals"); 373 base::ListValue* section_counters =
374 AddSection(stats_list.get(), "Running Totals");
372 // TODO(crbug.com/702230): Remove the usages of raw pointers in this file. 375 // TODO(crbug.com/702230): Remove the usages of raw pointers in this file.
373 section_counters->Reserve(7); 376 section_counters->Reserve(7);
374 IntSyncStat notifications_received(section_counters, 377 IntSyncStat notifications_received(section_counters,
375 "Notifications Received"); 378 "Notifications Received");
376 IntSyncStat updates_received(section_counters, "Updates Downloaded"); 379 IntSyncStat updates_received(section_counters, "Updates Downloaded");
377 IntSyncStat tombstone_updates(section_counters, "Tombstone Updates"); 380 IntSyncStat tombstone_updates(section_counters, "Tombstone Updates");
378 IntSyncStat reflected_updates(section_counters, "Reflected Updates"); 381 IntSyncStat reflected_updates(section_counters, "Reflected Updates");
379 IntSyncStat successful_commits(section_counters, "Successful Commits"); 382 IntSyncStat successful_commits(section_counters, "Successful Commits");
380 IntSyncStat conflicts_resolved_local_wins(section_counters, 383 IntSyncStat conflicts_resolved_local_wins(section_counters,
381 "Conflicts Resolved: Client Wins"); 384 "Conflicts Resolved: Client Wins");
382 IntSyncStat conflicts_resolved_server_wins(section_counters, 385 IntSyncStat conflicts_resolved_server_wins(section_counters,
383 "Conflicts Resolved: Server Wins"); 386 "Conflicts Resolved: Server Wins");
384 387
385 base::ListValue* section_this_cycle = 388 base::ListValue* section_this_cycle =
386 AddSection(stats_list, "Transient Counters (this cycle)"); 389 AddSection(stats_list.get(), "Transient Counters (this cycle)");
387 // TODO(crbug.com/702230): Remove the usages of raw pointers in this file. 390 // TODO(crbug.com/702230): Remove the usages of raw pointers in this file.
388 section_this_cycle->Reserve(4); 391 section_this_cycle->Reserve(4);
389 IntSyncStat encryption_conflicts(section_this_cycle, "Encryption Conflicts"); 392 IntSyncStat encryption_conflicts(section_this_cycle, "Encryption Conflicts");
390 IntSyncStat hierarchy_conflicts(section_this_cycle, "Hierarchy Conflicts"); 393 IntSyncStat hierarchy_conflicts(section_this_cycle, "Hierarchy Conflicts");
391 IntSyncStat server_conflicts(section_this_cycle, "Server Conflicts"); 394 IntSyncStat server_conflicts(section_this_cycle, "Server Conflicts");
392 IntSyncStat committed_items(section_this_cycle, "Committed Items"); 395 IntSyncStat committed_items(section_this_cycle, "Committed Items");
393 396
394 base::ListValue* section_that_cycle = AddSection( 397 base::ListValue* section_that_cycle =
395 stats_list, "Transient Counters (last cycle of last completed session)"); 398 AddSection(stats_list.get(),
399 "Transient Counters (last cycle of last completed session)");
396 // TODO(crbug.com/702230): Remove the usages of raw pointers in this file. 400 // TODO(crbug.com/702230): Remove the usages of raw pointers in this file.
397 section_that_cycle->Reserve(3); 401 section_that_cycle->Reserve(3);
398 IntSyncStat updates_downloaded(section_that_cycle, "Updates Downloaded"); 402 IntSyncStat updates_downloaded(section_that_cycle, "Updates Downloaded");
399 IntSyncStat committed_count(section_that_cycle, "Committed Count"); 403 IntSyncStat committed_count(section_that_cycle, "Committed Count");
400 IntSyncStat entries(section_that_cycle, "Entries"); 404 IntSyncStat entries(section_that_cycle, "Entries");
401 405
402 base::ListValue* section_nudge_info = 406 base::ListValue* section_nudge_info =
403 AddSection(stats_list, "Nudge Source Counters"); 407 AddSection(stats_list.get(), "Nudge Source Counters");
404 // TODO(crbug.com/702230): Remove the usages of raw pointers in this file. 408 // TODO(crbug.com/702230): Remove the usages of raw pointers in this file.
405 section_nudge_info->Reserve(3); 409 section_nudge_info->Reserve(3);
406 IntSyncStat nudge_source_notification(section_nudge_info, 410 IntSyncStat nudge_source_notification(section_nudge_info,
407 "Server Invalidations"); 411 "Server Invalidations");
408 IntSyncStat nudge_source_local(section_nudge_info, "Local Changes"); 412 IntSyncStat nudge_source_local(section_nudge_info, "Local Changes");
409 IntSyncStat nudge_source_local_refresh(section_nudge_info, "Local Refreshes"); 413 IntSyncStat nudge_source_local_refresh(section_nudge_info, "Local Refreshes");
410 414
411 // This list of sections belongs in the 'details' field of the returned 415 // This list of sections belongs in the 'details' field of the returned
412 // message. 416 // message.
413 about_info->Set(kDetailsKey, stats_list); 417 about_info->Set(kDetailsKey, std::move(stats_list));
414 418
415 // Populate all the fields we declared above. 419 // Populate all the fields we declared above.
416 client_version.SetValue(GetVersionString(channel)); 420 client_version.SetValue(GetVersionString(channel));
417 421
418 if (!service) { 422 if (!service) {
419 summary_string.SetValue("Sync service does not exist"); 423 summary_string.SetValue("Sync service does not exist");
420 return about_info; 424 return about_info;
421 } 425 }
422 426
423 SyncStatus full_status; 427 SyncStatus full_status;
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 const bool actionable_error_detected = 547 const bool actionable_error_detected =
544 full_status.sync_protocol_error.error_type != UNKNOWN_ERROR && 548 full_status.sync_protocol_error.error_type != UNKNOWN_ERROR &&
545 full_status.sync_protocol_error.error_type != SYNC_SUCCESS; 549 full_status.sync_protocol_error.error_type != SYNC_SUCCESS;
546 550
547 about_info->SetBoolean("actionable_error_detected", 551 about_info->SetBoolean("actionable_error_detected",
548 actionable_error_detected); 552 actionable_error_detected);
549 553
550 // NOTE: We won't bother showing any of the following values unless 554 // NOTE: We won't bother showing any of the following values unless
551 // actionable_error_detected is set. 555 // actionable_error_detected is set.
552 556
553 base::ListValue* actionable_error = new base::ListValue(); 557 auto actionable_error = base::MakeUnique<base::ListValue>();
554 // TODO(crbug.com/702230): Remove the usages of raw pointers in this file. 558 // TODO(crbug.com/702230): Remove the usages of raw pointers in this file.
555 actionable_error->Reserve(4); 559 actionable_error->Reserve(4);
556 about_info->Set("actionable_error", actionable_error);
557 560
558 StringSyncStat error_type(actionable_error, "Error Type"); 561 StringSyncStat error_type(actionable_error.get(), "Error Type");
559 StringSyncStat action(actionable_error, "Action"); 562 StringSyncStat action(actionable_error.get(), "Action");
560 StringSyncStat url(actionable_error, "URL"); 563 StringSyncStat url(actionable_error.get(), "URL");
561 StringSyncStat description(actionable_error, "Error Description"); 564 StringSyncStat description(actionable_error.get(), "Error Description");
565 about_info->Set("actionable_error", std::move(actionable_error));
562 566
563 if (actionable_error_detected) { 567 if (actionable_error_detected) {
564 error_type.SetValue( 568 error_type.SetValue(
565 GetSyncErrorTypeString(full_status.sync_protocol_error.error_type)); 569 GetSyncErrorTypeString(full_status.sync_protocol_error.error_type));
566 action.SetValue( 570 action.SetValue(
567 GetClientActionString(full_status.sync_protocol_error.action)); 571 GetClientActionString(full_status.sync_protocol_error.action));
568 url.SetValue(full_status.sync_protocol_error.url); 572 url.SetValue(full_status.sync_protocol_error.url);
569 description.SetValue(full_status.sync_protocol_error.error_description); 573 description.SetValue(full_status.sync_protocol_error.error_description);
570 } 574 }
571 575
(...skipping 12 matching lines...) Expand all
584 } 588 }
585 589
586 about_info->Set("type_status", service->GetTypeStatusMap()); 590 about_info->Set("type_status", service->GetTypeStatusMap());
587 591
588 return about_info; 592 return about_info;
589 } 593 }
590 594
591 } // namespace sync_ui_util 595 } // namespace sync_ui_util
592 596
593 } // namespace syncer 597 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698