| 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 #ifndef COMPONENTS_DEVTOOLS_HTTP_HANDLER_DEVTOOLS_HTTP_HANDLER_H_ | 5 #ifndef COMPONENTS_DEVTOOLS_HTTP_HANDLER_DEVTOOLS_HTTP_HANDLER_H_ |
| 6 #define COMPONENTS_DEVTOOLS_HTTP_HANDLER_DEVTOOLS_HTTP_HANDLER_H_ | 6 #define COMPONENTS_DEVTOOLS_HTTP_HANDLER_DEVTOOLS_HTTP_HANDLER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> |
| 9 #include <string> | 10 #include <string> |
| 10 | 11 |
| 11 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "components/devtools_discovery/devtools_target_descriptor.h" | 15 #include "components/devtools_discovery/devtools_target_descriptor.h" |
| 16 #include "net/http/http_status_code.h" | 16 #include "net/http/http_status_code.h" |
| 17 | 17 |
| 18 class GURL; | 18 class GURL; |
| 19 | 19 |
| 20 namespace base { | 20 namespace base { |
| 21 class DictionaryValue; | 21 class DictionaryValue; |
| 22 class Thread; | 22 class Thread; |
| 23 class Value; | 23 class Value; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 43 | 43 |
| 44 // Factory of net::ServerSocket. This is to separate instantiating dev tools | 44 // Factory of net::ServerSocket. This is to separate instantiating dev tools |
| 45 // and instantiating server sockets. | 45 // and instantiating server sockets. |
| 46 // All methods including destructor are called on a separate thread | 46 // All methods including destructor are called on a separate thread |
| 47 // different from any BrowserThread instance. | 47 // different from any BrowserThread instance. |
| 48 class ServerSocketFactory { | 48 class ServerSocketFactory { |
| 49 public: | 49 public: |
| 50 virtual ~ServerSocketFactory() {} | 50 virtual ~ServerSocketFactory() {} |
| 51 | 51 |
| 52 // Returns a new instance of ServerSocket or nullptr if an error occurred. | 52 // Returns a new instance of ServerSocket or nullptr if an error occurred. |
| 53 virtual scoped_ptr<net::ServerSocket> CreateForHttpServer(); | 53 virtual std::unique_ptr<net::ServerSocket> CreateForHttpServer(); |
| 54 | 54 |
| 55 // Creates a named socket for reversed tethering implementation (used with | 55 // Creates a named socket for reversed tethering implementation (used with |
| 56 // remote debugging, primarily for mobile). | 56 // remote debugging, primarily for mobile). |
| 57 virtual scoped_ptr<net::ServerSocket> CreateForTethering( | 57 virtual std::unique_ptr<net::ServerSocket> CreateForTethering( |
| 58 std::string* out_name); | 58 std::string* out_name); |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 // Takes ownership over |socket_factory| and |delegate|. | 61 // Takes ownership over |socket_factory| and |delegate|. |
| 62 // If |frontend_url| is empty, assumes it's bundled, and uses | 62 // If |frontend_url| is empty, assumes it's bundled, and uses |
| 63 // |delegate->GetFrontendResource()|. | 63 // |delegate->GetFrontendResource()|. |
| 64 // |delegate| is only accessed on UI thread. | 64 // |delegate| is only accessed on UI thread. |
| 65 // If |active_port_output_directory| is non-empty, it is assumed the | 65 // If |active_port_output_directory| is non-empty, it is assumed the |
| 66 // socket_factory was initialized with an ephemeral port (0). 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 | 67 // port selected by the OS will be written to a well-known file in |
| 68 // the output directory. | 68 // the output directory. |
| 69 DevToolsHttpHandler( | 69 DevToolsHttpHandler( |
| 70 scoped_ptr<ServerSocketFactory> server_socket_factory, | 70 std::unique_ptr<ServerSocketFactory> server_socket_factory, |
| 71 const std::string& frontend_url, | 71 const std::string& frontend_url, |
| 72 DevToolsHttpHandlerDelegate* delegate, | 72 DevToolsHttpHandlerDelegate* delegate, |
| 73 const base::FilePath& active_port_output_directory, | 73 const base::FilePath& active_port_output_directory, |
| 74 const base::FilePath& debug_frontend_dir, | 74 const base::FilePath& debug_frontend_dir, |
| 75 const std::string& product_name, | 75 const std::string& product_name, |
| 76 const std::string& user_agent); | 76 const std::string& user_agent); |
| 77 ~DevToolsHttpHandler(); | 77 ~DevToolsHttpHandler(); |
| 78 | 78 |
| 79 // Returns the URL for the file at |path| in frontend. | 79 // Returns the URL for the file at |path| in frontend. |
| 80 GURL GetFrontendURL(const std::string& path); | 80 GURL GetFrontendURL(const std::string& path); |
| 81 | 81 |
| 82 private: | 82 private: |
| 83 friend class ServerWrapper; | 83 friend class ServerWrapper; |
| 84 friend void ServerStartedOnUI( | 84 friend void ServerStartedOnUI( |
| 85 base::WeakPtr<DevToolsHttpHandler> handler, | 85 base::WeakPtr<DevToolsHttpHandler> handler, |
| 86 base::Thread* thread, | 86 base::Thread* thread, |
| 87 ServerWrapper* server_wrapper, | 87 ServerWrapper* server_wrapper, |
| 88 DevToolsHttpHandler::ServerSocketFactory* socket_factory, | 88 DevToolsHttpHandler::ServerSocketFactory* socket_factory, |
| 89 scoped_ptr<net::IPEndPoint> ip_address); | 89 std::unique_ptr<net::IPEndPoint> ip_address); |
| 90 | 90 |
| 91 void OnJsonRequest(int connection_id, | 91 void OnJsonRequest(int connection_id, |
| 92 const net::HttpServerRequestInfo& info); | 92 const net::HttpServerRequestInfo& info); |
| 93 void OnThumbnailRequest(int connection_id, const std::string& target_id); | 93 void OnThumbnailRequest(int connection_id, const std::string& target_id); |
| 94 void OnDiscoveryPageRequest(int connection_id); | 94 void OnDiscoveryPageRequest(int connection_id); |
| 95 void OnFrontendResourceRequest(int connection_id, const std::string& path); | 95 void OnFrontendResourceRequest(int connection_id, const std::string& path); |
| 96 void OnWebSocketRequest(int connection_id, | 96 void OnWebSocketRequest(int connection_id, |
| 97 const net::HttpServerRequestInfo& info); | 97 const net::HttpServerRequestInfo& info); |
| 98 void OnWebSocketMessage(int connection_id, const std::string& data); | 98 void OnWebSocketMessage(int connection_id, const std::string& data); |
| 99 void OnClose(int connection_id); | 99 void OnClose(int connection_id); |
| 100 | 100 |
| 101 void ServerStarted(base::Thread* thread, | 101 void ServerStarted(base::Thread* thread, |
| 102 ServerWrapper* server_wrapper, | 102 ServerWrapper* server_wrapper, |
| 103 ServerSocketFactory* socket_factory, | 103 ServerSocketFactory* socket_factory, |
| 104 scoped_ptr<net::IPEndPoint> ip_address); | 104 std::unique_ptr<net::IPEndPoint> ip_address); |
| 105 | 105 |
| 106 devtools_discovery::DevToolsTargetDescriptor* GetDescriptor( | 106 devtools_discovery::DevToolsTargetDescriptor* GetDescriptor( |
| 107 const std::string& target_id); | 107 const std::string& target_id); |
| 108 | 108 |
| 109 void SendJson(int connection_id, | 109 void SendJson(int connection_id, |
| 110 net::HttpStatusCode status_code, | 110 net::HttpStatusCode status_code, |
| 111 base::Value* value, | 111 base::Value* value, |
| 112 const std::string& message); | 112 const std::string& message); |
| 113 void Send200(int connection_id, | 113 void Send200(int connection_id, |
| 114 const std::string& data, | 114 const std::string& data, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 126 base::DictionaryValue* SerializeDescriptor( | 126 base::DictionaryValue* SerializeDescriptor( |
| 127 const devtools_discovery::DevToolsTargetDescriptor& descriptor, | 127 const devtools_discovery::DevToolsTargetDescriptor& descriptor, |
| 128 const std::string& host); | 128 const std::string& host); |
| 129 | 129 |
| 130 // The thread used by the devtools handler to run server socket. | 130 // The thread used by the devtools handler to run server socket. |
| 131 base::Thread* thread_; | 131 base::Thread* thread_; |
| 132 std::string frontend_url_; | 132 std::string frontend_url_; |
| 133 std::string product_name_; | 133 std::string product_name_; |
| 134 std::string user_agent_; | 134 std::string user_agent_; |
| 135 ServerWrapper* server_wrapper_; | 135 ServerWrapper* server_wrapper_; |
| 136 scoped_ptr<net::IPEndPoint> server_ip_address_; | 136 std::unique_ptr<net::IPEndPoint> server_ip_address_; |
| 137 typedef std::map<int, DevToolsAgentHostClientImpl*> ConnectionToClientMap; | 137 typedef std::map<int, DevToolsAgentHostClientImpl*> ConnectionToClientMap; |
| 138 ConnectionToClientMap connection_to_client_; | 138 ConnectionToClientMap connection_to_client_; |
| 139 const scoped_ptr<DevToolsHttpHandlerDelegate> delegate_; | 139 const std::unique_ptr<DevToolsHttpHandlerDelegate> delegate_; |
| 140 ServerSocketFactory* socket_factory_; | 140 ServerSocketFactory* socket_factory_; |
| 141 using DescriptorMap = | 141 using DescriptorMap = |
| 142 std::map<std::string, devtools_discovery::DevToolsTargetDescriptor*>; | 142 std::map<std::string, devtools_discovery::DevToolsTargetDescriptor*>; |
| 143 DescriptorMap descriptor_map_; | 143 DescriptorMap descriptor_map_; |
| 144 base::WeakPtrFactory<DevToolsHttpHandler> weak_factory_; | 144 base::WeakPtrFactory<DevToolsHttpHandler> weak_factory_; |
| 145 | 145 |
| 146 DISALLOW_COPY_AND_ASSIGN(DevToolsHttpHandler); | 146 DISALLOW_COPY_AND_ASSIGN(DevToolsHttpHandler); |
| 147 }; | 147 }; |
| 148 | 148 |
| 149 } // namespace devtools_http_handler | 149 } // namespace devtools_http_handler |
| 150 | 150 |
| 151 #endif // COMPONENTS_DEVTOOLS_HTTP_HANDLER_DEVTOOLS_HTTP_HANDLER_H_ | 151 #endif // COMPONENTS_DEVTOOLS_HTTP_HANDLER_DEVTOOLS_HTTP_HANDLER_H_ |
| OLD | NEW |