Setup for connecting the Viz DevTools server

Watch for a server socket when the frame sink manager is created, and
run the viz devtools server on the compositor thread if it is present.

The server socket is not passed in through mojo yet, so the devtools
server will not be created.

Bug: 816802
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel
Change-Id: Ic02853a2e1f845df365716c29e4f974ffd7482dc
Reviewed-on: https://chromium-review.googlesource.com/c/1285078
Reviewed-by: Ramin Halavati <[email protected]>
Reviewed-by: Tom Sepez <[email protected]>
Reviewed-by: Sadrul Chowdhury <[email protected]>
Reviewed-by: Peter Kasting <[email protected]>
Reviewed-by: kylechar <[email protected]>
Commit-Queue: Sean Gilhuly <[email protected]>
Cr-Commit-Position: refs/heads/master@{#604571}
diff --git a/components/ui_devtools/devtools_server.h b/components/ui_devtools/devtools_server.h
index 572ed3e..438a3998 100644
--- a/components/ui_devtools/devtools_server.h
+++ b/components/ui_devtools/devtools_server.h
@@ -24,30 +24,50 @@
 class UI_DEVTOOLS_EXPORT UiDevToolsServer
     : public network::server::HttpServer::Delegate {
  public:
+  // Network tags to be used for the UI and the Viz devtools servers.
+  static const net::NetworkTrafficAnnotationTag kUIDevtoolsServerTag;
+  static const net::NetworkTrafficAnnotationTag kVizDevtoolsServerTag;
+
   ~UiDevToolsServer() override;
 
   // Returns an empty unique_ptr if ui devtools flag isn't enabled or if a
-  // server instance has already been created. Server doesn't know anything
-  // about the caller, so both UI and Viz pass their corresponding params.
-  static std::unique_ptr<UiDevToolsServer> Create(
+  // server instance has already been created.
+  static std::unique_ptr<UiDevToolsServer> CreateForViews(
       network::mojom::NetworkContext* network_context,
       const char* enable_devtools_flag,
       int default_port);
 
+  // Assumes that the devtools flag is enabled, and was checked when the socket
+  // was created.
+  static std::unique_ptr<UiDevToolsServer> CreateForViz(
+      network::mojom::TCPServerSocketPtr server_socket,
+      int port);
+
+  // Creates a TCPServerSocket to be used by a UiDevToolsServer.
+  static void CreateTCPServerSocket(
+      network::mojom::TCPServerSocketRequest server_socket_request,
+      network::mojom::NetworkContext* network_context,
+      int port,
+      net::NetworkTrafficAnnotationTag tag,
+      network::mojom::NetworkContext::CreateTCPServerSocketCallback callback);
+
   // Returns a list of attached UiDevToolsClient name + URL
   using NameUrlPair = std::pair<std::string, std::string>;
   static std::vector<NameUrlPair> GetClientNamesAndUrls();
 
+  // Returns the port number specified by a command line flag. If a number is
+  // not specified as a command line argument, returns the |default_port|.
+  static int GetUiDevToolsPort(const char* enable_devtools_flag,
+                               int default_port);
+
   void AttachClient(std::unique_ptr<UiDevToolsClient> client);
   void SendOverWebSocket(int connection_id, const String& message);
 
   int port() const { return port_; }
 
  private:
-  UiDevToolsServer(const char* enable_devtools_flag, int default_port);
+  UiDevToolsServer(int port, const net::NetworkTrafficAnnotationTag tag);
 
-  void Start(network::mojom::NetworkContext* network_context,
-             const std::string& address_string);
   void MakeServer(network::mojom::TCPServerSocketPtr server_socket,
                   int result,
                   const base::Optional<net::IPEndPoint>& local_addr);
@@ -73,6 +93,8 @@
   // The port the devtools server listens on
   const int port_;
 
+  const net::NetworkTrafficAnnotationTag tag_;
+
   // The server (owned by ash for now)
   static UiDevToolsServer* devtools_server_;