Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/devtools/devtools_targets_ui.h" | 5 #include "chrome/browser/devtools/devtools_targets_ui.h" |
| 6 | 6 |
| 7 #include <memory> | |
| 7 #include <utility> | 8 #include <utility> |
| 8 | 9 |
| 9 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/memory/ptr_util.h" | |
| 10 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 11 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 12 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 13 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 15 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/thread_task_runner_handle.h" |
| 16 #include "base/values.h" | 18 #include "base/values.h" |
| 17 #include "base/version.h" | 19 #include "base/version.h" |
| 18 #include "chrome/browser/devtools/device/devtools_android_bridge.h" | 20 #include "chrome/browser/devtools/device/devtools_android_bridge.h" |
| 19 #include "content/public/browser/browser_child_process_observer.h" | 21 #include "content/public/browser/browser_child_process_observer.h" |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 226 base::TimeDelta::FromMilliseconds(kUpdateDelay))); | 228 base::TimeDelta::FromMilliseconds(kUpdateDelay))); |
| 227 } | 229 } |
| 228 | 230 |
| 229 void LocalTargetsUIHandler::UpdateTargets() { | 231 void LocalTargetsUIHandler::UpdateTargets() { |
| 230 SendTargets(DevToolsAgentHost::GetOrCreateAll()); | 232 SendTargets(DevToolsAgentHost::GetOrCreateAll()); |
| 231 } | 233 } |
| 232 | 234 |
| 233 void LocalTargetsUIHandler::SendTargets( | 235 void LocalTargetsUIHandler::SendTargets( |
| 234 const content::DevToolsAgentHost::List& targets) { | 236 const content::DevToolsAgentHost::List& targets) { |
| 235 base::ListValue list_value; | 237 base::ListValue list_value; |
| 236 std::map<std::string, base::DictionaryValue*> id_to_descriptor; | 238 std::map<std::string, std::unique_ptr<base::DictionaryValue>> |
| 239 id_to_descriptor; | |
| 237 | 240 |
| 238 targets_.clear(); | 241 targets_.clear(); |
| 239 for (scoped_refptr<DevToolsAgentHost> host : targets) { | 242 for (scoped_refptr<DevToolsAgentHost> host : targets) { |
| 240 targets_[host->GetId()] = host; | 243 targets_[host->GetId()] = host; |
| 241 id_to_descriptor[host->GetId()] = Serialize(host); | 244 id_to_descriptor[host->GetId()] = Serialize(host); |
| 242 } | 245 } |
| 243 | 246 |
| 244 for (auto& it : targets_) { | 247 for (auto& it : targets_) { |
| 245 scoped_refptr<DevToolsAgentHost> host = it.second; | 248 scoped_refptr<DevToolsAgentHost> host = it.second; |
| 246 base::DictionaryValue* descriptor = id_to_descriptor[host->GetId()]; | 249 std::unique_ptr<base::DictionaryValue> descriptor = |
| 250 std::move(id_to_descriptor[host->GetId()]); | |
| 251 DCHECK(descriptor); | |
| 247 std::string parent_id = host->GetParentId(); | 252 std::string parent_id = host->GetParentId(); |
| 248 if (parent_id.empty() || id_to_descriptor.count(parent_id) == 0) { | 253 if (parent_id.empty() || id_to_descriptor.count(parent_id) == 0) { |
| 249 list_value.Append(descriptor); | 254 list_value.Append(std::move(descriptor)); |
| 250 } else { | 255 } else { |
| 251 base::DictionaryValue* parent = id_to_descriptor[parent_id]; | 256 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
| |
| 252 base::ListValue* guests = NULL; | 257 base::ListValue* guests = NULL; |
| 253 if (!parent->GetList(kGuestList, &guests)) { | 258 if (!parent->GetList(kGuestList, &guests)) { |
| 254 guests = new base::ListValue(); | 259 guests = new base::ListValue(); |
| 255 parent->Set(kGuestList, guests); | 260 parent->Set(kGuestList, guests); |
| 256 } | 261 } |
| 257 guests->Append(descriptor); | 262 guests->Append(std::move(descriptor)); |
| 258 } | 263 } |
| 259 } | 264 } |
| 260 | 265 |
| 261 SendSerializedTargets(list_value); | 266 SendSerializedTargets(list_value); |
| 262 } | 267 } |
| 263 | 268 |
| 264 // AdbTargetsUIHandler -------------------------------------------------------- | 269 // AdbTargetsUIHandler -------------------------------------------------------- |
| 265 | 270 |
| 266 class AdbTargetsUIHandler | 271 class AdbTargetsUIHandler |
| 267 : public DevToolsTargetsUIHandler, | 272 : public DevToolsTargetsUIHandler, |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 362 std::string browser_id = browser->GetId(); | 367 std::string browser_id = browser->GetId(); |
| 363 browser_data->SetString(kTargetIdField, browser_id); | 368 browser_data->SetString(kTargetIdField, browser_id); |
| 364 browser_data->SetString(kTargetSourceField, source_id()); | 369 browser_data->SetString(kTargetSourceField, source_id()); |
| 365 | 370 |
| 366 base::ListValue* page_list = new base::ListValue(); | 371 base::ListValue* page_list = new base::ListValue(); |
| 367 remote_browsers_[browser_id] = browser; | 372 remote_browsers_[browser_id] = browser; |
| 368 browser_data->Set(kAdbPagesList, page_list); | 373 browser_data->Set(kAdbPagesList, page_list); |
| 369 for (const auto& page : browser->pages()) { | 374 for (const auto& page : browser->pages()) { |
| 370 scoped_refptr<DevToolsAgentHost> host = | 375 scoped_refptr<DevToolsAgentHost> host = |
| 371 android_bridge_->CreatePageTarget(page); | 376 android_bridge_->CreatePageTarget(page); |
| 372 base::DictionaryValue* target_data = Serialize(host); | 377 std::unique_ptr<base::DictionaryValue> target_data = Serialize(host); |
| 373 target_data->SetBoolean( | 378 target_data->SetBoolean( |
| 374 kAdbAttachedForeignField, | 379 kAdbAttachedForeignField, |
| 375 host->IsAttached() && | 380 host->IsAttached() && |
| 376 !android_bridge_->HasDevToolsWindow(host->GetId())); | 381 !android_bridge_->HasDevToolsWindow(host->GetId())); |
| 377 // Pass the screen size in the target object to make sure that | 382 // Pass the screen size in the target object to make sure that |
| 378 // the caching logic does not prevent the target item from updating | 383 // the caching logic does not prevent the target item from updating |
| 379 // when the screen size changes. | 384 // when the screen size changes. |
| 380 gfx::Size screen_size = device->screen_size(); | 385 gfx::Size screen_size = device->screen_size(); |
| 381 target_data->SetInteger(kAdbScreenWidthField, screen_size.width()); | 386 target_data->SetInteger(kAdbScreenWidthField, screen_size.width()); |
| 382 target_data->SetInteger(kAdbScreenHeightField, screen_size.height()); | 387 target_data->SetInteger(kAdbScreenHeightField, screen_size.height()); |
| 383 targets_[host->GetId()] = host; | 388 targets_[host->GetId()] = host; |
| 384 page_list->Append(target_data); | 389 page_list->Append(std::move(target_data)); |
| 385 } | 390 } |
| 386 browser_list->Append(std::move(browser_data)); | 391 browser_list->Append(std::move(browser_data)); |
| 387 } | 392 } |
| 388 | 393 |
| 389 device_list.Append(std::move(device_data)); | 394 device_list.Append(std::move(device_data)); |
| 390 } | 395 } |
| 391 SendSerializedTargets(device_list); | 396 SendSerializedTargets(device_list); |
| 392 } | 397 } |
| 393 | 398 |
| 394 } // namespace | 399 } // namespace |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 432 | 437 |
| 433 void DevToolsTargetsUIHandler::Open(const std::string& browser_id, | 438 void DevToolsTargetsUIHandler::Open(const std::string& browser_id, |
| 434 const std::string& url) { | 439 const std::string& url) { |
| 435 } | 440 } |
| 436 | 441 |
| 437 scoped_refptr<DevToolsAgentHost> | 442 scoped_refptr<DevToolsAgentHost> |
| 438 DevToolsTargetsUIHandler::GetBrowserAgentHost(const std::string& browser_id) { | 443 DevToolsTargetsUIHandler::GetBrowserAgentHost(const std::string& browser_id) { |
| 439 return NULL; | 444 return NULL; |
| 440 } | 445 } |
| 441 | 446 |
| 442 base::DictionaryValue* DevToolsTargetsUIHandler::Serialize( | 447 std::unique_ptr<base::DictionaryValue> DevToolsTargetsUIHandler::Serialize( |
| 443 scoped_refptr<DevToolsAgentHost> host) { | 448 scoped_refptr<DevToolsAgentHost> host) { |
| 444 base::DictionaryValue* target_data = new base::DictionaryValue(); | 449 auto target_data = base::MakeUnique<base::DictionaryValue>(); |
| 445 target_data->SetString(kTargetSourceField, source_id_); | 450 target_data->SetString(kTargetSourceField, source_id_); |
| 446 target_data->SetString(kTargetIdField, host->GetId()); | 451 target_data->SetString(kTargetIdField, host->GetId()); |
| 447 target_data->SetString(kTargetTypeField, host->GetType()); | 452 target_data->SetString(kTargetTypeField, host->GetType()); |
| 448 target_data->SetBoolean(kAttachedField, host->IsAttached()); | 453 target_data->SetBoolean(kAttachedField, host->IsAttached()); |
| 449 target_data->SetString(kUrlField, host->GetURL().spec()); | 454 target_data->SetString(kUrlField, host->GetURL().spec()); |
| 450 target_data->SetString(kNameField, host->GetTitle()); | 455 target_data->SetString(kNameField, host->GetTitle()); |
| 451 target_data->SetString(kFaviconUrlField, host->GetFaviconURL().spec()); | 456 target_data->SetString(kFaviconUrlField, host->GetFaviconURL().spec()); |
| 452 target_data->SetString(kDescriptionField, host->GetDescription()); | 457 target_data->SetString(kDescriptionField, host->GetDescription()); |
| 453 return target_data; | 458 return target_data; |
| 454 } | 459 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 497 device_status_dict->SetString(kPortForwardingBrowserId, | 502 device_status_dict->SetString(kPortForwardingBrowserId, |
| 498 sit->first->GetId()); | 503 sit->first->GetId()); |
| 499 | 504 |
| 500 std::string device_id = base::StringPrintf( | 505 std::string device_id = base::StringPrintf( |
| 501 kAdbDeviceIdFormat, | 506 kAdbDeviceIdFormat, |
| 502 sit->first->serial().c_str()); | 507 sit->first->serial().c_str()); |
| 503 result.Set(device_id, device_status_dict); | 508 result.Set(device_id, device_status_dict); |
| 504 } | 509 } |
| 505 callback_.Run(result); | 510 callback_.Run(result); |
| 506 } | 511 } |
| OLD | NEW |