Chromium Code Reviews| 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 a48364b02623707e3ef3cef5898c951211d09d31..c15f3e2c0f75af03d7d29c131c2a22d23238af40 100644 |
| --- a/chrome/browser/devtools/devtools_targets_ui.cc |
| +++ b/chrome/browser/devtools/devtools_targets_ui.cc |
| @@ -4,9 +4,11 @@ |
| #include "chrome/browser/devtools/devtools_targets_ui.h" |
| +#include <memory> |
| #include <utility> |
| #include "base/location.h" |
| +#include "base/memory/ptr_util.h" |
| #include "base/memory/weak_ptr.h" |
| #include "base/single_thread_task_runner.h" |
| #include "base/stl_util.h" |
| @@ -233,7 +235,8 @@ void LocalTargetsUIHandler::UpdateTargets() { |
| void LocalTargetsUIHandler::SendTargets( |
| const content::DevToolsAgentHost::List& targets) { |
| base::ListValue list_value; |
| - std::map<std::string, base::DictionaryValue*> id_to_descriptor; |
| + std::map<std::string, std::unique_ptr<base::DictionaryValue>> |
| + id_to_descriptor; |
| targets_.clear(); |
| for (scoped_refptr<DevToolsAgentHost> host : targets) { |
| @@ -243,18 +246,20 @@ void LocalTargetsUIHandler::SendTargets( |
| for (auto& it : targets_) { |
| scoped_refptr<DevToolsAgentHost> host = it.second; |
| - base::DictionaryValue* descriptor = id_to_descriptor[host->GetId()]; |
| + std::unique_ptr<base::DictionaryValue> descriptor = |
| + std::move(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(descriptor); |
| + list_value.Append(std::move(descriptor)); |
| } else { |
| - base::DictionaryValue* parent = id_to_descriptor[parent_id]; |
| + base::DictionaryValue* parent = id_to_descriptor[parent_id].get(); |
|
danakj
2016/09/15 21:07:34
Um, hm. We're moving things out of this map now, w
dcheng
2016/09/15 21:10:22
Well. The tests pass ^_^
But I agree that this is
pfeldman
2016/09/16 21:39:02
Haven't looked at this code for a while...
So we
dcheng
2016/09/16 23:15:01
Keeping two trees seems strictly worse... so I jus
|
| base::ListValue* guests = NULL; |
| if (!parent->GetList(kGuestList, &guests)) { |
| guests = new base::ListValue(); |
| parent->Set(kGuestList, guests); |
| } |
| - guests->Append(descriptor); |
| + guests->Append(std::move(descriptor)); |
| } |
| } |
| @@ -369,7 +374,7 @@ void AdbTargetsUIHandler::DeviceListChanged( |
| for (const auto& page : browser->pages()) { |
| scoped_refptr<DevToolsAgentHost> host = |
| android_bridge_->CreatePageTarget(page); |
| - base::DictionaryValue* target_data = Serialize(host); |
| + std::unique_ptr<base::DictionaryValue> target_data = Serialize(host); |
| target_data->SetBoolean( |
| kAdbAttachedForeignField, |
| host->IsAttached() && |
| @@ -381,7 +386,7 @@ void AdbTargetsUIHandler::DeviceListChanged( |
| target_data->SetInteger(kAdbScreenWidthField, screen_size.width()); |
| target_data->SetInteger(kAdbScreenHeightField, screen_size.height()); |
| targets_[host->GetId()] = host; |
| - page_list->Append(target_data); |
| + page_list->Append(std::move(target_data)); |
| } |
| browser_list->Append(std::move(browser_data)); |
| } |
| @@ -439,9 +444,9 @@ DevToolsTargetsUIHandler::GetBrowserAgentHost(const std::string& browser_id) { |
| return NULL; |
| } |
| -base::DictionaryValue* DevToolsTargetsUIHandler::Serialize( |
| +std::unique_ptr<base::DictionaryValue> DevToolsTargetsUIHandler::Serialize( |
| scoped_refptr<DevToolsAgentHost> host) { |
| - base::DictionaryValue* target_data = new base::DictionaryValue(); |
| + auto target_data = base::MakeUnique<base::DictionaryValue>(); |
| target_data->SetString(kTargetSourceField, source_id_); |
| target_data->SetString(kTargetIdField, host->GetId()); |
| target_data->SetString(kTargetTypeField, host->GetType()); |