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

Issue 2825533002: Introduce SerializeDictionaryForest for devtools_target_ui (Closed)

Created:
3 years, 8 months ago by vabr (Chromium)
Modified:
3 years, 8 months ago
Reviewers:
jdoerrie, dgozman
CC:
chromium-reviews, pfeldman, devtools-reviews_chromium.org
Target Ref:
refs/heads/master
Project:
chromium
Visibility:
Public.

Description

Introduce SerializeDictionaryForest for devtools_target_ui Currently, LocalTargetsUIHandler::SendTargets contains a very succinct code to create a base::Value description of a forest of DevToolsAgentHost instances. One property of base::ListValue which made this code possible was that Values were stored in unique_ptrs inside ListValue. In particular, passing a value to ListValue::Append left the previously owning pointer still useful as a weak pointer. That property no longer holds true, because ListValue has been converted to store Values directly in https://crrev.com/a5676c607e107238b2d0cdd55e626c93669a92f1. This results in use of values which have been std::moved, i.e., a kind of use-after-free. What's worse -- this code is not tested enough for sanitizers to have caught this, and was already seen in the wild by users of Chrome 59 and 60 as crashes. This CL wants to achieve these goals: * Fix the code to not to rely on implementation details of ListValue. * Increase unit test coverage of the new code. * Make the code more explicit and clearer. The CL does the following to achieve the above goals: * It introduces an explicit topological sort of the forest of DevToolsAgentHosts. This allows to do changes to base::Values before passing them inside a ListValue, so after calling ListValue::Append it does not matter what happens to the passed Values. * The CL also separates the topological sort into a helper function, and adds a unit test for that. The touched code also seemed to create too many scoped_refptr<DevToolsAgentHost> instances: in cases where there is already a scoped_refptr holding an object alive outside of the current context, it is better to use just raw pointers in for loops and argument passing, to avoid unnecessary churn with AddRef/Release calls. Therefore this CL also changed for loops inside of LocalTargetsUIHandler::SendTargets to use const scoped_refptr& (still avoids the AddRef/Release churn when raw pointer is not an option) as well as the argument of DevToolsTargetsUIHandler::Serialize to just a raw pointer. BUG=712119 Review-Url: https://codereview.chromium.org/2825533002 Cr-Commit-Position: refs/heads/master@{#465948} Committed: https://chromium.googlesource.com/chromium/src/+/668159776484e722ffaaad38c8201fc49e62b937

Patch Set 1 #

Patch Set 2 : Self review #

Total comments: 13

Patch Set 3 : ChildrenRange, base::Reversed and Value::GetList #

Total comments: 2

Patch Set 4 : Recursion + DFS #

Patch Set 5 : Let the helper compute the tree #

Total comments: 6

Patch Set 6 : non-pre-ordered test and out params #

Unified diffs Side-by-side diffs Delta from patch set Stats (+262 lines, -27 lines) Patch
M chrome/browser/devtools/BUILD.gn View 1 2 3 4 1 chunk +2 lines, -0 lines 0 comments Download
M chrome/browser/devtools/devtools_targets_ui.h View 1 chunk +1 line, -1 line 0 comments Download
M chrome/browser/devtools/devtools_targets_ui.cc View 1 2 3 4 4 chunks +11 lines, -26 lines 0 comments Download
A chrome/browser/devtools/serialize_host_descriptions.h View 1 2 3 4 1 chunk +29 lines, -0 lines 0 comments Download
A chrome/browser/devtools/serialize_host_descriptions.cc View 1 2 3 4 5 1 chunk +102 lines, -0 lines 0 comments Download
A chrome/browser/devtools/serialize_host_descriptions_unittest.cc View 1 2 3 4 5 1 chunk +116 lines, -0 lines 0 comments Download
M chrome/test/BUILD.gn View 1 2 3 4 1 chunk +1 line, -0 lines 0 comments Download

Messages

Total messages: 36 (23 generated)
vabr (Chromium)
Hi all! dgozman@ -- could you please review the whole patch? jdoerrie@ -- could you ...
3 years, 8 months ago (2017-04-17 20:16:34 UTC) #8
dgozman
Thank you for fixing this! I believe we can simplify this a bit, see below. ...
3 years, 8 months ago (2017-04-17 21:22:43 UTC) #9
vabr (Chromium)
Thanks for the quick reply! https://codereview.chromium.org/2825533002/diff/20001/chrome/browser/devtools/devtools_targets_ui.cc File chrome/browser/devtools/devtools_targets_ui.cc (right): https://codereview.chromium.org/2825533002/diff/20001/chrome/browser/devtools/devtools_targets_ui.cc#newcode264 chrome/browser/devtools/devtools_targets_ui.cc:264: SerializeDictionaryForest(std::move(forest), kGuestList)); On 2017/04/17 ...
3 years, 8 months ago (2017-04-18 08:52:49 UTC) #10
jdoerrie
Thank you very much for fixing this, vabr@! Usage of std::move + base::Value LGTM. https://codereview.chromium.org/2825533002/diff/20001/chrome/browser/devtools/devtools_targets_ui.cc ...
3 years, 8 months ago (2017-04-18 09:57:45 UTC) #11
jdoerrie
https://codereview.chromium.org/2825533002/diff/20001/chrome/browser/devtools/serialize_dictionary_forest.cc File chrome/browser/devtools/serialize_dictionary_forest.cc (right): https://codereview.chromium.org/2825533002/diff/20001/chrome/browser/devtools/serialize_dictionary_forest.cc#newcode137 chrome/browser/devtools/serialize_dictionary_forest.cc:137: base::MakeUnique<base::Value>(std::move(child_description))); FYI, r465517 just landed, so you could get ...
3 years, 8 months ago (2017-04-19 08:35:00 UTC) #12
vabr (Chromium)
@jdoerrie: Thanks for the review. Please see my replies and the updated patch. @dgozman: Looking ...
3 years, 8 months ago (2017-04-19 11:03:17 UTC) #15
jdoerrie
Still LGTM :) TIL about base::Reversed, thanks! https://codereview.chromium.org/2825533002/diff/20001/chrome/browser/devtools/devtools_targets_ui.cc File chrome/browser/devtools/devtools_targets_ui.cc (right): https://codereview.chromium.org/2825533002/diff/20001/chrome/browser/devtools/devtools_targets_ui.cc#newcode241 chrome/browser/devtools/devtools_targets_ui.cc:241: std::map<std::string, DictionaryForestNode*> ...
3 years, 8 months ago (2017-04-19 11:45:51 UTC) #18
vabr (Chromium)
@dgozman -- just a quick heads-up: I did some benchmarking and based on the result ...
3 years, 8 months ago (2017-04-19 13:35:05 UTC) #19
vabr (Chromium)
Hi dgozman@, Thanks for bearing with me! The benchmark discussion is in https://crbug.com/712119#c6 with a ...
3 years, 8 months ago (2017-04-19 16:25:49 UTC) #26
dgozman
This looks very nice, thank you! A couple of nits below. lgtm https://codereview.chromium.org/2825533002/diff/80001/chrome/browser/devtools/serialize_host_descriptions.cc File chrome/browser/devtools/serialize_host_descriptions.cc ...
3 years, 8 months ago (2017-04-19 22:05:14 UTC) #29
vabr (Chromium)
Thanks for the review! I addressed the comments and will send this to CQ now. ...
3 years, 8 months ago (2017-04-20 07:29:39 UTC) #30
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.org/2825533002/100001
3 years, 8 months ago (2017-04-20 07:30:02 UTC) #33
commit-bot: I haz the power
3 years, 8 months ago (2017-04-20 08:27:19 UTC) #36
Message was sent while issue was closed.
Committed patchset #6 (id:100001) as
https://chromium.googlesource.com/chromium/src/+/668159776484e722ffaaad38c820...

Powered by Google App Engine
This is Rietveld 408576698