devtools_http_handler.h revision 1320f92c476a1ad9d19dba2a48c72b75566198e9
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 3// found in the LICENSE file. 4 5#ifndef CONTENT_PUBLIC_BROWSER_DEVTOOLS_HTTP_HANDLER_H_ 6#define CONTENT_PUBLIC_BROWSER_DEVTOOLS_HTTP_HANDLER_H_ 7 8#include <string> 9 10#include "base/files/file_path.h" 11#include "base/memory/scoped_ptr.h" 12#include "content/common/content_export.h" 13 14class GURL; 15 16namespace net { 17class ServerSocket; 18class URLRequestContextGetter; 19} 20 21namespace content { 22 23class DevToolsHttpHandlerDelegate; 24 25// This class is used for managing DevTools remote debugging server. 26// Clients can connect to the specified ip:port and start debugging 27// this browser. 28class DevToolsHttpHandler { 29 public: 30 31 // Factory of net::ServerSocket. This is to separate instantiating dev tools 32 // and instantiating server socket. 33 class CONTENT_EXPORT ServerSocketFactory { 34 public: 35 ServerSocketFactory(const std::string& address, int port, int backlog); 36 virtual ~ServerSocketFactory(); 37 38 // Returns a new instance of ServerSocket or NULL if an error occurred. 39 // It calls ServerSocket::ListenWithAddressAndPort() with address, port and 40 // backlog passed to constructor. 41 virtual scoped_ptr<net::ServerSocket> CreateAndListen() const; 42 43 protected: 44 // Creates a server socket. ServerSocket::Listen() will be called soon 45 // unless it returns NULL. 46 virtual scoped_ptr<net::ServerSocket> Create() const = 0; 47 48 const std::string address_; 49 const int port_; 50 const int backlog_; 51 52 private: 53 DISALLOW_COPY_AND_ASSIGN(ServerSocketFactory); 54 }; 55 56 // Returns true if the given protocol version is supported. 57 CONTENT_EXPORT static bool IsSupportedProtocolVersion( 58 const std::string& version); 59 60 // Returns frontend resource id for the given resource |name|. 61 CONTENT_EXPORT static int GetFrontendResourceId( 62 const std::string& name); 63 64 // Takes ownership over |socket_factory| and |delegate|. 65 // If |active_port_output_directory| is non-empty, it is assumed the 66 // socket_factory was initialized with an ephemeral port (0). The 67 // port selected by the OS will be written to a well-known file in 68 // the output directory. 69 CONTENT_EXPORT static DevToolsHttpHandler* Start( 70 scoped_ptr<ServerSocketFactory> server_socket_factory, 71 const std::string& frontend_url, 72 DevToolsHttpHandlerDelegate* delegate, 73 const base::FilePath& active_port_output_directory); 74 75 // Called from the main thread in order to stop protocol handler. 76 // Automatically destroys the handler instance. 77 virtual void Stop() = 0; 78 79 // Returns the URL for the address to debug |agent_host|. 80 virtual GURL GetFrontendURL() = 0; 81 82 protected: 83 virtual ~DevToolsHttpHandler() {} 84}; 85 86} // namespace content 87 88#endif // CONTENT_PUBLIC_BROWSER_DEVTOOLS_HTTP_HANDLER_H_ 89