Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Side by Side Diff: mojo/shell/public/cpp/shell_connection.h

Issue 1725353003: Eliminate mojo::Shell client lib class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@15connector
Patch Set: . Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/shell/public/cpp/shell_client.h ('k') | mojo/shell/runner/child/native_apptest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 MOJO_SHELL_PUBLIC_CPP_SHELL_CONNECTION_H_ 5 #ifndef MOJO_SHELL_PUBLIC_CPP_SHELL_CONNECTION_H_
6 #define MOJO_SHELL_PUBLIC_CPP_SHELL_CONNECTION_H_ 6 #define MOJO_SHELL_PUBLIC_CPP_SHELL_CONNECTION_H_
7 7
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/scoped_vector.h" 12 #include "base/memory/scoped_vector.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "mojo/public/cpp/bindings/binding.h" 14 #include "mojo/public/cpp/bindings/binding.h"
15 #include "mojo/public/cpp/bindings/callback.h" 15 #include "mojo/public/cpp/bindings/callback.h"
16 #include "mojo/public/cpp/system/core.h" 16 #include "mojo/public/cpp/system/core.h"
17 #include "mojo/shell/public/cpp/shell.h"
18 #include "mojo/shell/public/cpp/shell_client.h" 17 #include "mojo/shell/public/cpp/shell_client.h"
19 #include "mojo/shell/public/interfaces/shell.mojom.h" 18 #include "mojo/shell/public/interfaces/shell.mojom.h"
20 #include "mojo/shell/public/interfaces/shell_client.mojom.h" 19 #include "mojo/shell/public/interfaces/shell_client.mojom.h"
21 20
22 namespace mojo { 21 namespace mojo {
23 22
24 class AppRefCountImpl;
25 class Connector; 23 class Connector;
26 24
27 // Encapsulates a connection to the Mojo Shell in two parts: 25 // Encapsulates a connection to the Mojo Shell in two parts:
28 // - a bound InterfacePtr to mojo::shell::mojom::Shell, the primary mechanism 26 // - a bound InterfacePtr to mojo::shell::mojom::Shell, the primary mechanism
29 // by which the instantiating application interacts with other services 27 // by which the instantiating application interacts with other services
30 // brokered by the Mojo Shell. 28 // brokered by the Mojo Shell.
31 // - a bound InterfaceRequest of mojo::shell::mojom::ShellClient, an interface 29 // - a bound InterfaceRequest of mojo::shell::mojom::ShellClient, an interface
32 // used by the Mojo Shell to inform this application of lifecycle events and 30 // used by the Mojo Shell to inform this application of lifecycle events and
33 // inbound connections brokered by it. 31 // inbound connections brokered by it.
34 // 32 //
35 // This class should be used in two scenarios: 33 // This class should be used in two scenarios:
36 // - During early startup to bind the mojo::shell::mojom::ShellClientRequest 34 // - During early startup to bind the mojo::shell::mojom::ShellClientRequest
37 // obtained from the Mojo Shell. This is typically in response to either 35 // obtained from the Mojo Shell. This is typically in response to either
38 // MojoMain() or main(). 36 // MojoMain() or main().
39 // - In an implementation of mojo::shell::mojom::ContentHandler to bind the 37 // - In an implementation of mojo::shell::mojom::ContentHandler to bind the
40 // mojo::shell::mojom::ShellClientRequest passed via StartApplication. In this 38 // mojo::shell::mojom::ShellClientRequest passed via StartApplication. In this
41 // scenario there can be many instances of this class per process. 39 // scenario there can be many instances of this class per process.
42 // 40 //
43 // Instances of this class are constructed with an implementation of the Shell 41 // Instances of this class are constructed with an implementation of the Shell
44 // Client Lib's mojo::ShellClient interface. See documentation in shell_client.h 42 // Client Lib's mojo::ShellClient interface. See documentation in shell_client.h
45 // for details. 43 // for details.
46 // 44 //
47 // Though this class provides the canonical implementation of the Shell Client 45 class ShellConnection : public shell::mojom::ShellClient {
48 // lib's mojo::Shell interface, this interface should not be reached through
49 // pointers to this type.
50 class ShellConnection : public Shell, public shell::mojom::ShellClient {
51 public: 46 public:
52 // Does not take ownership of |delegate|, which must remain valid for the 47 // Does not take ownership of |delegate|, which must remain valid for the
53 // lifetime of ShellConnection. 48 // lifetime of ShellConnection.
54 ShellConnection(mojo::ShellClient* client, 49 ShellConnection(mojo::ShellClient* client,
55 InterfaceRequest<shell::mojom::ShellClient> request); 50 InterfaceRequest<shell::mojom::ShellClient> request);
56 ~ShellConnection() override; 51 ~ShellConnection() override;
57 52
58 // Block the calling thread until the Initialize() method is called by the 53 // Block the calling thread until the Initialize() method is called by the
59 // shell. 54 // shell.
60 void WaitForInitialize(); 55 void WaitForInitialize();
61 56
57 Connector* connector() { return connector_.get(); }
58
62 private: 59 private:
63 friend AppRefCountImpl;
64
65 // Shell:
66 scoped_ptr<Connection> Connect(const std::string& url) override;
67 scoped_ptr<Connection> Connect(Connector::ConnectParams* params) override;
68 scoped_ptr<Connector> CloneConnector() const override;
69 scoped_ptr<AppRefCount> CreateAppRefCount() override;
70 void Quit() override;
71
72 // shell::mojom::ShellClient: 60 // shell::mojom::ShellClient:
73 void Initialize(shell::mojom::ConnectorPtr connector, 61 void Initialize(shell::mojom::ConnectorPtr connector,
74 const mojo::String& url, 62 const mojo::String& url,
75 uint32_t id, 63 uint32_t id,
76 uint32_t user_id) override; 64 uint32_t user_id) override;
77 void AcceptConnection( 65 void AcceptConnection(
78 const String& requestor_url, 66 const String& requestor_url,
79 uint32_t requestor_id, 67 uint32_t requestor_id,
80 uint32_t requestor_user_id, 68 uint32_t requestor_user_id,
81 shell::mojom::InterfaceProviderRequest remote_interfaces, 69 shell::mojom::InterfaceProviderRequest remote_interfaces,
82 shell::mojom::InterfaceProviderPtr local_interfaces, 70 shell::mojom::InterfaceProviderPtr local_interfaces,
83 Array<String> allowed_interfaces, 71 Array<String> allowed_interfaces,
84 const String& url) override; 72 const String& url) override;
85 73
86 void OnConnectionError(); 74 void OnConnectionError();
87 75
88 // Called from AppRefCountImpl.
89 void AddRef();
90 void Release();
91
92 // We track the lifetime of incoming connection registries as it more 76 // We track the lifetime of incoming connection registries as it more
93 // convenient for the client. 77 // convenient for the client.
94 ScopedVector<Connection> incoming_connections_; 78 ScopedVector<Connection> incoming_connections_;
95 mojo::ShellClient* client_; 79 mojo::ShellClient* client_;
96 Binding<shell::mojom::ShellClient> binding_; 80 Binding<shell::mojom::ShellClient> binding_;
97 scoped_ptr<Connector> connector_; 81 scoped_ptr<Connector> connector_;
98 int ref_count_;
99 base::WeakPtrFactory<ShellConnection> weak_factory_; 82 base::WeakPtrFactory<ShellConnection> weak_factory_;
100 83
101 MOJO_DISALLOW_COPY_AND_ASSIGN(ShellConnection); 84 MOJO_DISALLOW_COPY_AND_ASSIGN(ShellConnection);
102 }; 85 };
103 86
104 } // namespace mojo 87 } // namespace mojo
105 88
106 #endif // MOJO_SHELL_PUBLIC_CPP_SHELL_CONNECTION_H_ 89 #endif // MOJO_SHELL_PUBLIC_CPP_SHELL_CONNECTION_H_
OLDNEW
« no previous file with comments | « mojo/shell/public/cpp/shell_client.h ('k') | mojo/shell/runner/child/native_apptest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698