OLD | NEW |
---|---|
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 "content/browser/debugger/devtools_http_handler_impl.h" | 5 #include "content/browser/debugger/devtools_http_handler_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
121 int DevToolsHttpHandler::GetFrontendResourceId(const std::string& name) { | 121 int DevToolsHttpHandler::GetFrontendResourceId(const std::string& name) { |
122 for (size_t i = 0; i < kDevtoolsResourcesSize; ++i) { | 122 for (size_t i = 0; i < kDevtoolsResourcesSize; ++i) { |
123 if (name == kDevtoolsResources[i].name) | 123 if (name == kDevtoolsResources[i].name) |
124 return kDevtoolsResources[i].value; | 124 return kDevtoolsResources[i].value; |
125 } | 125 } |
126 return -1; | 126 return -1; |
127 } | 127 } |
128 | 128 |
129 // static | 129 // static |
130 DevToolsHttpHandler* DevToolsHttpHandler::Start( | 130 DevToolsHttpHandler* DevToolsHttpHandler::Start( |
131 const std::string& ip, | |
132 int port, | |
133 const std::string& frontend_url, | 131 const std::string& frontend_url, |
132 net::StreamListenSocketFactory* socket_factory, | |
134 net::URLRequestContextGetter* request_context_getter, | 133 net::URLRequestContextGetter* request_context_getter, |
135 DevToolsHttpHandlerDelegate* delegate) { | 134 DevToolsHttpHandlerDelegate* delegate) { |
136 DevToolsHttpHandlerImpl* http_handler = | 135 DevToolsHttpHandlerImpl* http_handler = |
137 new DevToolsHttpHandlerImpl(ip, | 136 new DevToolsHttpHandlerImpl(frontend_url, |
pfeldman
2012/05/14 11:12:00
socket_factory should probably go first (as it was
Philippe
2012/05/14 12:36:52
I made it second to keep the mutable state last. f
mmenke
2012/05/14 20:45:19
The factory doesn't look terribly mutable to me.
Philippe
2012/05/15 14:39:09
In practice (in TCPListenSocketFactory::CreateAndL
| |
138 port, | 137 socket_factory, |
139 frontend_url, | |
140 request_context_getter, | 138 request_context_getter, |
141 delegate); | 139 delegate); |
142 http_handler->Start(); | 140 http_handler->Start(); |
143 return http_handler; | 141 return http_handler; |
144 } | 142 } |
145 | 143 |
146 DevToolsHttpHandlerImpl::~DevToolsHttpHandlerImpl() { | 144 DevToolsHttpHandlerImpl::~DevToolsHttpHandlerImpl() { |
147 // Stop() must be called prior to this being called | 145 // Stop() must be called prior to this being called |
148 DCHECK(server_.get() == NULL); | 146 DCHECK(server_.get() == NULL); |
149 } | 147 } |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
521 | 519 |
522 | 520 |
523 // See comments re: HEAD requests in OnResponseStarted(). | 521 // See comments re: HEAD requests in OnResponseStarted(). |
524 if (!request->status().is_io_pending()) { | 522 if (!request->status().is_io_pending()) { |
525 server_->Send(connection_id, "0\r\n\r\n"); | 523 server_->Send(connection_id, "0\r\n\r\n"); |
526 RequestCompleted(request); | 524 RequestCompleted(request); |
527 } | 525 } |
528 } | 526 } |
529 | 527 |
530 DevToolsHttpHandlerImpl::DevToolsHttpHandlerImpl( | 528 DevToolsHttpHandlerImpl::DevToolsHttpHandlerImpl( |
531 const std::string& ip, | |
532 int port, | |
533 const std::string& frontend_url, | 529 const std::string& frontend_url, |
530 net::StreamListenSocketFactory* socket_factory, | |
534 net::URLRequestContextGetter* request_context_getter, | 531 net::URLRequestContextGetter* request_context_getter, |
535 DevToolsHttpHandlerDelegate* delegate) | 532 DevToolsHttpHandlerDelegate* delegate) |
536 : ip_(ip), | 533 : overridden_frontend_url_(frontend_url), |
537 port_(port), | 534 socket_factory_(socket_factory), |
538 overridden_frontend_url_(frontend_url), | |
539 request_context_getter_(request_context_getter), | 535 request_context_getter_(request_context_getter), |
540 delegate_(delegate) { | 536 delegate_(delegate) { |
541 if (overridden_frontend_url_.empty()) | 537 if (overridden_frontend_url_.empty()) |
542 overridden_frontend_url_ = "/devtools/devtools.html"; | 538 overridden_frontend_url_ = "/devtools/devtools.html"; |
543 | 539 |
544 default_binding_.reset(new DevToolsDefaultBindingHandler); | 540 default_binding_.reset(new DevToolsDefaultBindingHandler); |
545 binding_ = default_binding_.get(); | 541 binding_ = default_binding_.get(); |
546 | 542 |
547 AddRef(); | 543 AddRef(); |
548 } | 544 } |
549 | 545 |
550 void DevToolsHttpHandlerImpl::Init() { | 546 void DevToolsHttpHandlerImpl::Init() { |
551 server_ = new net::HttpServer(ip_, port_, this); | 547 server_ = new net::HttpServer(this, socket_factory_.get()); |
552 } | 548 } |
553 | 549 |
554 // Run on I/O thread | 550 // Run on I/O thread |
555 void DevToolsHttpHandlerImpl::TeardownAndRelease() { | 551 void DevToolsHttpHandlerImpl::TeardownAndRelease() { |
556 server_ = NULL; | 552 server_ = NULL; |
557 BrowserThread::PostTask( | 553 BrowserThread::PostTask( |
558 BrowserThread::UI, FROM_HERE, | 554 BrowserThread::UI, FROM_HERE, |
559 base::Bind(&DevToolsHttpHandlerImpl::Release, this)); | 555 base::Bind(&DevToolsHttpHandlerImpl::Release, this)); |
560 } | 556 } |
561 | 557 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
617 void DevToolsHttpHandlerImpl::AcceptWebSocket( | 613 void DevToolsHttpHandlerImpl::AcceptWebSocket( |
618 int connection_id, | 614 int connection_id, |
619 const net::HttpServerRequestInfo& request) { | 615 const net::HttpServerRequestInfo& request) { |
620 BrowserThread::PostTask( | 616 BrowserThread::PostTask( |
621 BrowserThread::IO, FROM_HERE, | 617 BrowserThread::IO, FROM_HERE, |
622 base::Bind(&net::HttpServer::AcceptWebSocket, server_.get(), | 618 base::Bind(&net::HttpServer::AcceptWebSocket, server_.get(), |
623 connection_id, request)); | 619 connection_id, request)); |
624 } | 620 } |
625 | 621 |
626 } // namespace content | 622 } // namespace content |
OLD | NEW |