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

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

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

Powered by Google App Engine
This is Rietveld 408576698