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

Side by Side Diff: chrome/browser/devtools/remote_debugging_server.cc

Issue 2295623002: DevTools: simplify http handler delegate as it is moving into content. (Closed)
Patch Set: lcean Created 4 years, 3 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 "chrome/browser/devtools/remote_debugging_server.h" 5 #include "chrome/browser/devtools/remote_debugging_server.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/devtools/devtools_window.h" 15 #include "chrome/browser/devtools/devtools_window.h"
16 #include "chrome/browser/history/top_sites_factory.h"
17 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/ui/browser.h" 17 #include "chrome/browser/ui/browser.h"
19 #include "chrome/browser/ui/browser_list.h" 18 #include "chrome/browser/ui/browser_list.h"
20 #include "chrome/common/chrome_content_client.h" 19 #include "chrome/common/chrome_content_client.h"
21 #include "chrome/common/chrome_paths.h" 20 #include "chrome/common/chrome_paths.h"
22 #include "chrome/grit/browser_resources.h" 21 #include "chrome/grit/browser_resources.h"
23 #include "components/devtools_http_handler/devtools_http_handler.h" 22 #include "components/devtools_http_handler/devtools_http_handler.h"
24 #include "components/devtools_http_handler/devtools_http_handler_delegate.h" 23 #include "components/devtools_http_handler/devtools_http_handler_delegate.h"
25 #include "components/history/core/browser/top_sites.h"
26 #include "components/version_info/version_info.h" 24 #include "components/version_info/version_info.h"
27 #include "content/public/browser/devtools_frontend_host.h" 25 #include "content/public/browser/devtools_frontend_host.h"
26 #include "content/public/browser/devtools_socket_factory.h"
28 #include "net/base/net_errors.h" 27 #include "net/base/net_errors.h"
29 #include "net/socket/tcp_server_socket.h" 28 #include "net/socket/tcp_server_socket.h"
30 #include "ui/base/resource/resource_bundle.h" 29 #include "ui/base/resource/resource_bundle.h"
31 30
32 namespace { 31 namespace {
33 32
34 base::LazyInstance<bool>::Leaky g_tethering_enabled = LAZY_INSTANCE_INITIALIZER; 33 base::LazyInstance<bool>::Leaky g_tethering_enabled = LAZY_INSTANCE_INITIALIZER;
35 34
36 const uint16_t kMinTetheringPort = 9333; 35 const uint16_t kMinTetheringPort = 9333;
37 const uint16_t kMaxTetheringPort = 9444; 36 const uint16_t kMaxTetheringPort = 9444;
38 const int kBackLog = 10; 37 const int kBackLog = 10;
39 38
40 class TCPServerSocketFactory 39 class TCPServerSocketFactory
41 : public devtools_http_handler::DevToolsHttpHandler::ServerSocketFactory { 40 : public content::DevToolsSocketFactory {
42 public: 41 public:
43 TCPServerSocketFactory(const std::string& address, uint16_t port) 42 TCPServerSocketFactory(const std::string& address, uint16_t port)
44 : address_(address), 43 : address_(address),
45 port_(port), 44 port_(port),
46 last_tethering_port_(kMinTetheringPort) {} 45 last_tethering_port_(kMinTetheringPort) {}
47 46
48 private: 47 private:
49 std::unique_ptr<net::ServerSocket> CreateLocalHostServerSocket(int port) { 48 std::unique_ptr<net::ServerSocket> CreateLocalHostServerSocket(int port) {
50 std::unique_ptr<net::ServerSocket> socket( 49 std::unique_ptr<net::ServerSocket> socket(
51 new net::TCPServerSocket(nullptr, net::NetLog::Source())); 50 new net::TCPServerSocket(nullptr, net::NetLog::Source()));
52 if (socket->ListenWithAddressAndPort( 51 if (socket->ListenWithAddressAndPort(
53 "127.0.0.1", port, kBackLog) == net::OK) 52 "127.0.0.1", port, kBackLog) == net::OK)
54 return socket; 53 return socket;
55 if (socket->ListenWithAddressAndPort("::1", port, kBackLog) == net::OK) 54 if (socket->ListenWithAddressAndPort("::1", port, kBackLog) == net::OK)
56 return socket; 55 return socket;
57 return std::unique_ptr<net::ServerSocket>(); 56 return std::unique_ptr<net::ServerSocket>();
58 } 57 }
59 58
60 // devtools_http_handler::DevToolsHttpHandler::ServerSocketFactory. 59 // content::DevToolsSocketFactory.
61 std::unique_ptr<net::ServerSocket> CreateForHttpServer() override { 60 std::unique_ptr<net::ServerSocket> CreateForHttpServer() override {
62 std::unique_ptr<net::ServerSocket> socket( 61 std::unique_ptr<net::ServerSocket> socket(
63 new net::TCPServerSocket(nullptr, net::NetLog::Source())); 62 new net::TCPServerSocket(nullptr, net::NetLog::Source()));
64 if (address_.empty()) 63 if (address_.empty())
65 return CreateLocalHostServerSocket(port_); 64 return CreateLocalHostServerSocket(port_);
66 if (socket->ListenWithAddressAndPort(address_, port_, kBackLog) == net::OK) 65 if (socket->ListenWithAddressAndPort(address_, port_, kBackLog) == net::OK)
67 return socket; 66 return socket;
68 return std::unique_ptr<net::ServerSocket>(); 67 return std::unique_ptr<net::ServerSocket>();
69 } 68 }
70 69
(...skipping 18 matching lines...) Expand all
89 88
90 class ChromeDevToolsHttpHandlerDelegate 89 class ChromeDevToolsHttpHandlerDelegate
91 : public devtools_http_handler::DevToolsHttpHandlerDelegate { 90 : public devtools_http_handler::DevToolsHttpHandlerDelegate {
92 public: 91 public:
93 ChromeDevToolsHttpHandlerDelegate(); 92 ChromeDevToolsHttpHandlerDelegate();
94 ~ChromeDevToolsHttpHandlerDelegate() override; 93 ~ChromeDevToolsHttpHandlerDelegate() override;
95 94
96 // devtools_http_handler::DevToolsHttpHandlerDelegate implementation. 95 // devtools_http_handler::DevToolsHttpHandlerDelegate implementation.
97 std::string GetDiscoveryPageHTML() override; 96 std::string GetDiscoveryPageHTML() override;
98 std::string GetFrontendResource(const std::string& path) override; 97 std::string GetFrontendResource(const std::string& path) override;
99 std::string GetPageThumbnailData(const GURL& url) override;
100 content::DevToolsExternalAgentProxyDelegate*
101 HandleWebSocketConnection(const std::string& path) override;
102 98
103 private: 99 private:
104 DISALLOW_COPY_AND_ASSIGN(ChromeDevToolsHttpHandlerDelegate); 100 DISALLOW_COPY_AND_ASSIGN(ChromeDevToolsHttpHandlerDelegate);
105 }; 101 };
106 102
107 ChromeDevToolsHttpHandlerDelegate::ChromeDevToolsHttpHandlerDelegate() { 103 ChromeDevToolsHttpHandlerDelegate::ChromeDevToolsHttpHandlerDelegate() {
108 } 104 }
109 105
110 ChromeDevToolsHttpHandlerDelegate::~ChromeDevToolsHttpHandlerDelegate() { 106 ChromeDevToolsHttpHandlerDelegate::~ChromeDevToolsHttpHandlerDelegate() {
111 } 107 }
112 108
113 std::string ChromeDevToolsHttpHandlerDelegate::GetDiscoveryPageHTML() { 109 std::string ChromeDevToolsHttpHandlerDelegate::GetDiscoveryPageHTML() {
114 std::set<Profile*> profiles;
115 for (auto* browser : *BrowserList::GetInstance())
116 profiles.insert(browser->profile());
117
118 for (std::set<Profile*>::iterator it = profiles.begin();
119 it != profiles.end(); ++it) {
120 scoped_refptr<history::TopSites> ts = TopSitesFactory::GetForProfile(*it);
121 if (ts) {
122 // TopSites updates itself after a delay. Ask TopSites to update itself
123 // when we're about to show the remote debugging landing page.
124 ts->SyncWithHistory();
125 }
126 }
127 return ResourceBundle::GetSharedInstance().GetRawDataResource( 110 return ResourceBundle::GetSharedInstance().GetRawDataResource(
128 IDR_DEVTOOLS_DISCOVERY_PAGE_HTML).as_string(); 111 IDR_DEVTOOLS_DISCOVERY_PAGE_HTML).as_string();
129 } 112 }
130 113
131 std::string ChromeDevToolsHttpHandlerDelegate::GetFrontendResource( 114 std::string ChromeDevToolsHttpHandlerDelegate::GetFrontendResource(
132 const std::string& path) { 115 const std::string& path) {
133 return content::DevToolsFrontendHost::GetFrontendResource(path).as_string(); 116 return content::DevToolsFrontendHost::GetFrontendResource(path).as_string();
134 } 117 }
135 118
136 std::string ChromeDevToolsHttpHandlerDelegate::GetPageThumbnailData(
137 const GURL& url) {
138 for (auto* browser : *BrowserList::GetInstance()) {
139 Profile* profile = browser->profile();
140 scoped_refptr<history::TopSites> top_sites =
141 TopSitesFactory::GetForProfile(profile);
142 if (!top_sites)
143 continue;
144 scoped_refptr<base::RefCountedMemory> data;
145 if (top_sites->GetPageThumbnail(url, false, &data))
146 return std::string(data->front_as<char>(), data->size());
147 }
148 return std::string();
149 }
150
151 content::DevToolsExternalAgentProxyDelegate*
152 ChromeDevToolsHttpHandlerDelegate::HandleWebSocketConnection(
153 const std::string& path) {
154 return nullptr;
155 }
156
157 } // namespace 119 } // namespace
158 120
159 // static 121 // static
160 void RemoteDebuggingServer::EnableTetheringForDebug() { 122 void RemoteDebuggingServer::EnableTetheringForDebug() {
161 g_tethering_enabled.Get() = true; 123 g_tethering_enabled.Get() = true;
162 } 124 }
163 125
164 RemoteDebuggingServer::RemoteDebuggingServer(const std::string& ip, 126 RemoteDebuggingServer::RemoteDebuggingServer(const std::string& ip,
165 uint16_t port) { 127 uint16_t port) {
166 base::FilePath output_dir; 128 base::FilePath output_dir;
(...skipping 14 matching lines...) Expand all
181 base::WrapUnique(new TCPServerSocketFactory(ip, port)), std::string(), 143 base::WrapUnique(new TCPServerSocketFactory(ip, port)), std::string(),
182 new ChromeDevToolsHttpHandlerDelegate(), output_dir, debug_frontend_dir, 144 new ChromeDevToolsHttpHandlerDelegate(), output_dir, debug_frontend_dir,
183 version_info::GetProductNameAndVersionForUserAgent(), ::GetUserAgent())); 145 version_info::GetProductNameAndVersionForUserAgent(), ::GetUserAgent()));
184 } 146 }
185 147
186 RemoteDebuggingServer::~RemoteDebuggingServer() { 148 RemoteDebuggingServer::~RemoteDebuggingServer() {
187 // Ensure Profile is alive, because the whole DevTools subsystem 149 // Ensure Profile is alive, because the whole DevTools subsystem
188 // accesses it during shutdown. 150 // accesses it during shutdown.
189 DCHECK(g_browser_process->profile_manager()); 151 DCHECK(g_browser_process->profile_manager());
190 } 152 }
OLDNEW
« no previous file with comments | « chrome/browser/devtools/remote_debugging_server.h ('k') | chrome/test/data/devtools/target_list/background.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698