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

Unified Diff: chrome/browser/devtools/devtools_targets_ui.cc

Issue 2825533002: Introduce SerializeDictionaryForest for devtools_target_ui (Closed)
Patch Set: Self review Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/devtools/devtools_targets_ui.cc
diff --git a/chrome/browser/devtools/devtools_targets_ui.cc b/chrome/browser/devtools/devtools_targets_ui.cc
index f45c2fbf353c7d13b5ac2caf149a229ea76eff5d..c199dd22fce74e2588130cf6d7a82876028ec62f 100644
--- a/chrome/browser/devtools/devtools_targets_ui.cc
+++ b/chrome/browser/devtools/devtools_targets_ui.cc
@@ -18,6 +18,7 @@
#include "base/values.h"
#include "base/version.h"
#include "chrome/browser/devtools/device/devtools_android_bridge.h"
+#include "chrome/browser/devtools/serialize_dictionary_forest.h"
#include "content/public/browser/browser_child_process_observer.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/child_process_data.h"
@@ -233,35 +234,34 @@ void LocalTargetsUIHandler::UpdateTargets() {
void LocalTargetsUIHandler::SendTargets(
const content::DevToolsAgentHost::List& targets) {
- base::ListValue list_value;
- std::map<std::string, base::DictionaryValue*> id_to_descriptor;
-
- targets_.clear();
- for (scoped_refptr<DevToolsAgentHost> host : targets) {
- targets_[host->GetId()] = host;
- id_to_descriptor[host->GetId()] = Serialize(host).release();
- }
+ std::vector<DictionaryForestNode> forest;
+ forest.reserve(targets.size());
+
+ {
+ std::map<std::string, DictionaryForestNode*> id_to_node;
jdoerrie 2017/04/18 09:57:44 Small suggestion: Given that you care about perfor
vabr (Chromium) 2017/04/19 11:03:17 Thanks! What I'm reading in the description of ba
jdoerrie 2017/04/19 11:45:51 No, you are right, the main advantages of flat con
+
+ // Reset |targets_| and fill the forest with nodes without edges.
+ targets_.clear();
+ for (const scoped_refptr<DevToolsAgentHost>& host : targets) {
+ targets_[host->GetId()] = host;
+ forest.push_back({nullptr, *Serialize(host.get())});
+ id_to_node[host->GetId()] = &forest.back();
+ }
- for (auto& it : targets_) {
- scoped_refptr<DevToolsAgentHost> host = it.second;
- base::DictionaryValue* descriptor = id_to_descriptor[host->GetId()];
- DCHECK(descriptor);
- std::string parent_id = host->GetParentId();
- if (parent_id.empty() || id_to_descriptor.count(parent_id) == 0) {
- list_value.Append(base::WrapUnique(descriptor));
- } else {
- base::DictionaryValue* parent = id_to_descriptor[parent_id];
- base::ListValue* guests_weak = NULL;
- if (!parent->GetList(kGuestList, &guests_weak)) {
- auto guests = base::MakeUnique<base::ListValue>();
- guests_weak = guests.get();
- parent->Set(kGuestList, std::move(guests));
- }
- guests_weak->Append(base::WrapUnique(descriptor));
+ // Now add the edges.
+ for (const scoped_refptr<DevToolsAgentHost>& host : targets) {
+ std::string parent_id = host->GetParentId();
+ if (parent_id.empty())
+ continue;
+ auto node_it = id_to_node.find(parent_id);
+ if (node_it == id_to_node.end())
+ continue;
+ id_to_node[host->GetId()]->parent = node_it->second;
}
}
- SendSerializedTargets(list_value);
+ SendSerializedTargets(
+ SerializeDictionaryForest(std::move(forest), kGuestList));
dgozman 2017/04/17 21:22:43 Since there could be no more than one parent, I ha
vabr (Chromium) 2017/04/18 08:52:49 Thanks for the suggestion. One thing which is les
}
// AdbTargetsUIHandler --------------------------------------------------------
@@ -369,7 +369,8 @@ void AdbTargetsUIHandler::DeviceListChanged(
remote_browsers_[browser_id] = browser;
for (const auto& page : browser->pages()) {
scoped_refptr<DevToolsAgentHost> host = page->CreateTarget();
- std::unique_ptr<base::DictionaryValue> target_data = Serialize(host);
+ std::unique_ptr<base::DictionaryValue> target_data =
+ Serialize(host.get());
// Pass the screen size in the target object to make sure that
// the caching logic does not prevent the target item from updating
// when the screen size changes.
@@ -438,7 +439,7 @@ DevToolsTargetsUIHandler::GetBrowserAgentHost(const std::string& browser_id) {
}
std::unique_ptr<base::DictionaryValue> DevToolsTargetsUIHandler::Serialize(
- scoped_refptr<DevToolsAgentHost> host) {
+ DevToolsAgentHost* host) {
auto target_data = base::MakeUnique<base::DictionaryValue>();
target_data->SetString(kTargetSourceField, source_id_);
target_data->SetString(kTargetIdField, host->GetId());

Powered by Google App Engine
This is Rietveld 408576698