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

Side by Side Diff: content/browser/devtools/devtools_http_handler.cc

Issue 2344753002: DevTools: return discovered targets asynchronously. (Closed)
Patch Set: for bots Created 4 years, 2 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
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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 version.SetString("User-Agent", user_agent_); 527 version.SetString("User-Agent", user_agent_);
528 #if defined(OS_ANDROID) 528 #if defined(OS_ANDROID)
529 version.SetString("Android-Package", 529 version.SetString("Android-Package",
530 base::android::BuildInfo::GetInstance()->package_name()); 530 base::android::BuildInfo::GetInstance()->package_name());
531 #endif 531 #endif
532 SendJson(connection_id, net::HTTP_OK, &version, std::string()); 532 SendJson(connection_id, net::HTTP_OK, &version, std::string());
533 return; 533 return;
534 } 534 }
535 535
536 if (command == "list") { 536 if (command == "list") {
537 std::string host = info.headers["host"]; 537 DevToolsAgentHost::DiscoverAllHosts(
538 DevToolsAgentHost::List agent_hosts = 538 base::Bind(&DevToolsHttpHandler::RespondToJsonList,
539 DevToolsAgentHost::DiscoverAllHosts(); 539 weak_factory_.GetWeakPtr(), connection_id,
540 std::sort(agent_hosts.begin(), agent_hosts.end(), TimeComparator); 540 info.headers["host"]));
541 agent_host_map_.clear();
542 base::ListValue list_value;
543 for (auto& agent_host : agent_hosts) {
544 agent_host_map_[agent_host->GetId()] = agent_host;
545 list_value.Append(SerializeDescriptor(agent_host, host));
546 }
547 SendJson(connection_id, net::HTTP_OK, &list_value, std::string());
548 return; 541 return;
549 } 542 }
550 543
551 if (command == "new") { 544 if (command == "new") {
552 GURL url(net::UnescapeURLComponent( 545 GURL url(net::UnescapeURLComponent(
553 query, net::UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS | 546 query, net::UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS |
554 net::UnescapeRule::PATH_SEPARATORS)); 547 net::UnescapeRule::PATH_SEPARATORS));
555 if (!url.is_valid()) 548 if (!url.is_valid())
556 url = GURL(url::kAboutBlankURL); 549 url = GURL(url::kAboutBlankURL);
557 scoped_refptr<DevToolsAgentHost> agent_host = nullptr; 550 scoped_refptr<DevToolsAgentHost> agent_host = nullptr;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 return; 599 return;
607 } 600 }
608 } 601 }
609 SendJson(connection_id, 602 SendJson(connection_id,
610 net::HTTP_NOT_FOUND, 603 net::HTTP_NOT_FOUND,
611 NULL, 604 NULL,
612 "Unknown command: " + command); 605 "Unknown command: " + command);
613 return; 606 return;
614 } 607 }
615 608
609 void DevToolsHttpHandler::RespondToJsonList(
610 int connection_id,
611 const std::string& host,
612 DevToolsAgentHost::List hosts) {
613 DevToolsAgentHost::List agent_hosts = std::move(hosts);
614 std::sort(agent_hosts.begin(), agent_hosts.end(), TimeComparator);
615 agent_host_map_.clear();
616 base::ListValue list_value;
617 for (auto& agent_host : agent_hosts) {
618 agent_host_map_[agent_host->GetId()] = agent_host;
619 list_value.Append(SerializeDescriptor(agent_host, host));
620 }
621 SendJson(connection_id, net::HTTP_OK, &list_value, std::string());
622 }
623
616 scoped_refptr<DevToolsAgentHost> DevToolsHttpHandler::GetAgentHost( 624 scoped_refptr<DevToolsAgentHost> DevToolsHttpHandler::GetAgentHost(
617 const std::string& target_id) { 625 const std::string& target_id) {
618 DescriptorMap::const_iterator it = agent_host_map_.find(target_id); 626 DescriptorMap::const_iterator it = agent_host_map_.find(target_id);
619 return it != agent_host_map_.end() ? it->second : nullptr; 627 return it != agent_host_map_.end() ? it->second : nullptr;
620 } 628 }
621 629
622 void DevToolsHttpHandler::OnDiscoveryPageRequest(int connection_id) { 630 void DevToolsHttpHandler::OnDiscoveryPageRequest(int connection_id) {
623 std::string response = delegate_->GetDiscoveryPageHTML(); 631 std::string response = delegate_->GetDiscoveryPageHTML();
624 Send200(connection_id, response, "text/html; charset=UTF-8"); 632 Send200(connection_id, response, "text/html; charset=UTF-8");
625 } 633 }
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 id.c_str(), 860 id.c_str(),
853 host); 861 host);
854 dictionary->SetString( 862 dictionary->SetString(
855 kTargetDevtoolsFrontendUrlField, devtools_frontend_url); 863 kTargetDevtoolsFrontendUrlField, devtools_frontend_url);
856 } 864 }
857 865
858 return dictionary; 866 return dictionary;
859 } 867 }
860 868
861 } // namespace content 869 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/devtools/devtools_http_handler.h ('k') | content/browser/devtools/protocol/browser_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698