OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 CONTENT_BROWSER_MOJO_BROWSER_SHELL_CONNECTION_H_ | 5 #ifndef CONTENT_BROWSER_MOJO_BROWSER_SHELL_CONNECTION_H_ |
6 #define CONTENT_BROWSER_MOJO_BROWSER_SHELL_CONNECTION_H_ | 6 #define CONTENT_BROWSER_MOJO_BROWSER_SHELL_CONNECTION_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 #include <unordered_map> | 10 #include <unordered_map> |
(...skipping 15 matching lines...) Expand all Loading... |
26 namespace content { | 26 namespace content { |
27 | 27 |
28 // A connection from the browser process to the Mojo shell. There may be | 28 // A connection from the browser process to the Mojo shell. There may be |
29 // multiple connections in a single browser process. Each connection may have | 29 // multiple connections in a single browser process. Each connection may have |
30 // its own identity, e.g., a connection with unique user ID per BrowserContext. | 30 // its own identity, e.g., a connection with unique user ID per BrowserContext. |
31 class BrowserShellConnection | 31 class BrowserShellConnection |
32 : public shell::ShellClient, | 32 : public shell::ShellClient, |
33 public shell::InterfaceFactory<shell::mojom::ShellClientFactory>, | 33 public shell::InterfaceFactory<shell::mojom::ShellClientFactory>, |
34 public shell::mojom::ShellClientFactory { | 34 public shell::mojom::ShellClientFactory { |
35 public: | 35 public: |
| 36 using ShellClientRequestHandler = |
| 37 base::Callback<void(shell::mojom::ShellClientRequest)>; |
| 38 |
| 39 // Constructs a connection which does not own a ShellClient pipe. This |
| 40 // connection must be manually fed new incoming connections via its |
| 41 // shell::ShellClient interface. |
| 42 BrowserShellConnection(); |
| 43 |
| 44 // Constructs a connection associated with its own ShellClient pipe. |
36 explicit BrowserShellConnection(shell::mojom::ShellClientRequest request); | 45 explicit BrowserShellConnection(shell::mojom::ShellClientRequest request); |
| 46 |
37 ~BrowserShellConnection() override; | 47 ~BrowserShellConnection() override; |
38 | 48 |
39 shell::Connector* GetConnector(); | 49 shell::Connector* GetConnector(); |
40 | 50 |
41 // Adds an embedded application to this connection's ShellClientFactory. | 51 // Adds an embedded application to this connection's ShellClientFactory. |
42 // |callback| will be used to create a new instance of the application on | 52 // |callback| will be used to create a new instance of the application on |
43 // |task_runner|'s thread if no instance is running when an incoming | 53 // |task_runner|'s thread if no instance is running when an incoming |
44 // connection is made to |name|. If |task_runner| is null, the calling thread | 54 // connection is made to |name|. If |task_runner| is null, the calling thread |
45 // will be used to run the application. | 55 // will be used to run the application. |
46 void AddEmbeddedApplication( | 56 void AddEmbeddedApplication( |
47 const base::StringPiece& name, | 57 const base::StringPiece& name, |
48 const EmbeddedApplicationRunner::FactoryCallback& callback, | 58 const EmbeddedApplicationRunner::FactoryCallback& callback, |
49 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); | 59 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); |
50 | 60 |
| 61 // Adds a generic ShellClientRequestHandler for a given application name. This |
| 62 // will be used to satisfy any incoming calls to CreateShellClient() which |
| 63 // reference the given name. |
| 64 // |
| 65 // For in-process applications, it is preferrable to use |
| 66 // |AddEmbeddedApplication()| as defined above. |
| 67 void AddShellClientRequestHandler(const base::StringPiece& name, |
| 68 const ShellClientRequestHandler& handler); |
| 69 |
51 private: | 70 private: |
52 // shell::ShellClient: | 71 // shell::ShellClient: |
53 bool AcceptConnection(shell::Connection* connection) override; | 72 bool AcceptConnection(shell::Connection* connection) override; |
54 | 73 |
55 // shell::InterfaceFactory<shell::mojom::ShellClientFactory>: | 74 // shell::InterfaceFactory<shell::mojom::ShellClientFactory>: |
56 void Create(shell::Connection* connection, | 75 void Create(shell::Connection* connection, |
57 shell::mojom::ShellClientFactoryRequest request) override; | 76 shell::mojom::ShellClientFactoryRequest request) override; |
58 | 77 |
59 // shell::mojom::ShellClientFactory: | 78 // shell::mojom::ShellClientFactory: |
60 void CreateShellClient(shell::mojom::ShellClientRequest request, | 79 void CreateShellClient(shell::mojom::ShellClientRequest request, |
61 const mojo::String& name) override; | 80 const mojo::String& name) override; |
62 | 81 |
63 std::unique_ptr<shell::ShellConnection> shell_connection_; | 82 std::unique_ptr<shell::ShellConnection> shell_connection_; |
64 mojo::BindingSet<shell::mojom::ShellClientFactory> factory_bindings_; | 83 mojo::BindingSet<shell::mojom::ShellClientFactory> factory_bindings_; |
65 std::unordered_map<std::string, std::unique_ptr<EmbeddedApplicationRunner>> | 84 std::unordered_map<std::string, std::unique_ptr<EmbeddedApplicationRunner>> |
66 embedded_apps_; | 85 embedded_apps_; |
| 86 std::unordered_map<std::string, ShellClientRequestHandler> request_handlers_; |
67 | 87 |
68 DISALLOW_COPY_AND_ASSIGN(BrowserShellConnection); | 88 DISALLOW_COPY_AND_ASSIGN(BrowserShellConnection); |
69 }; | 89 }; |
70 | 90 |
71 } // namespace content | 91 } // namespace content |
72 | 92 |
73 #endif // CONTENT_BROWSER_MOJO_BROWSER_SHELL_CONNECTION_H_ | 93 #endif // CONTENT_BROWSER_MOJO_BROWSER_SHELL_CONNECTION_H_ |
OLD | NEW |