| 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 #include <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 Start(); | 45 Start(); |
| 46 } | 46 } |
| 47 ~ProvidedShellClient() override { | 47 ~ProvidedShellClient() override { |
| 48 Join(); | 48 Join(); |
| 49 } | 49 } |
| 50 | 50 |
| 51 private: | 51 private: |
| 52 // mojo::ShellClient: | 52 // mojo::ShellClient: |
| 53 void Initialize(Connector* connector, const Identity& identity, | 53 void Initialize(Connector* connector, const Identity& identity, |
| 54 uint32_t id) override { | 54 uint32_t id) override { |
| 55 name_ = identity.name(); | 55 identity_ = identity; |
| 56 userid_ = identity.user_id(); | |
| 57 id_ = id; | 56 id_ = id; |
| 58 bindings_.set_connection_error_handler( | 57 bindings_.set_connection_error_handler( |
| 59 base::Bind(&ProvidedShellClient::OnConnectionError, | 58 base::Bind(&ProvidedShellClient::OnConnectionError, |
| 60 base::Unretained(this))); | 59 base::Unretained(this))); |
| 61 } | 60 } |
| 62 bool AcceptConnection(Connection* connection) override { | 61 bool AcceptConnection(Connection* connection) override { |
| 63 connection->AddInterface<test::mojom::ConnectTestService>(this); | 62 connection->AddInterface<test::mojom::ConnectTestService>(this); |
| 64 connection->AddInterface<test::mojom::BlockedInterface>(this); | 63 connection->AddInterface<test::mojom::BlockedInterface>(this); |
| 65 | 64 |
| 66 uint32_t remote_id = connection->GetRemoteInstanceID(); | 65 uint32_t remote_id = connection->GetRemoteInstanceID(); |
| 67 test::mojom::ConnectionStatePtr state(test::mojom::ConnectionState::New()); | 66 test::mojom::ConnectionStatePtr state(test::mojom::ConnectionState::New()); |
| 68 state->connection_local_name = connection->GetConnectionName(); | 67 state->connection_local_name = connection->GetConnectionName(); |
| 69 state->connection_remote_name = connection->GetRemoteIdentity().name(); | 68 state->connection_remote_name = connection->GetRemoteIdentity().name(); |
| 70 state->connection_remote_userid = connection->GetRemoteIdentity().user_id(); | 69 state->connection_remote_userid = connection->GetRemoteIdentity().user_id(); |
| 71 state->connection_remote_id = remote_id; | 70 state->connection_remote_id = remote_id; |
| 72 state->initialize_local_name = name_; | 71 state->initialize_local_name = identity_.name(); |
| 73 state->initialize_id = id_; | 72 state->initialize_id = id_; |
| 74 state->initialize_userid = userid_; | 73 state->initialize_userid = identity_.user_id(); |
| 75 connection->GetInterface(&caller_); | 74 connection->GetInterface(&caller_); |
| 76 caller_->ConnectionAccepted(std::move(state)); | 75 caller_->ConnectionAccepted(std::move(state)); |
| 77 | 76 |
| 78 return true; | 77 return true; |
| 79 } | 78 } |
| 80 | 79 |
| 81 // InterfaceFactory<test::mojom::ConnectTestService>: | 80 // InterfaceFactory<test::mojom::ConnectTestService>: |
| 82 void Create(Connection* connection, | 81 void Create(Connection* connection, |
| 83 test::mojom::ConnectTestServiceRequest request) override { | 82 test::mojom::ConnectTestServiceRequest request) override { |
| 84 bindings_.AddBinding(this, std::move(request)); | 83 bindings_.AddBinding(this, std::move(request)); |
| 85 } | 84 } |
| 86 | 85 |
| 87 // InterfaceFactory<test::mojom::BlockedInterface>: | 86 // InterfaceFactory<test::mojom::BlockedInterface>: |
| 88 void Create(Connection* connection, | 87 void Create(Connection* connection, |
| 89 test::mojom::BlockedInterfaceRequest request) override { | 88 test::mojom::BlockedInterfaceRequest request) override { |
| 90 blocked_bindings_.AddBinding(this, std::move(request)); | 89 blocked_bindings_.AddBinding(this, std::move(request)); |
| 91 } | 90 } |
| 92 | 91 |
| 93 // test::mojom::ConnectTestService: | 92 // test::mojom::ConnectTestService: |
| 94 void GetTitle(const GetTitleCallback& callback) override { | 93 void GetTitle(const GetTitleCallback& callback) override { |
| 95 callback.Run(title_); | 94 callback.Run(title_); |
| 96 } | 95 } |
| 96 void GetInstance(const GetInstanceCallback& callback) override { |
| 97 callback.Run(identity_.instance()); |
| 98 } |
| 97 | 99 |
| 98 // test::mojom::BlockedInterface: | 100 // test::mojom::BlockedInterface: |
| 99 void GetTitleBlocked(const GetTitleBlockedCallback& callback) override { | 101 void GetTitleBlocked(const GetTitleBlockedCallback& callback) override { |
| 100 callback.Run("Called Blocked Interface!"); | 102 callback.Run("Called Blocked Interface!"); |
| 101 } | 103 } |
| 102 | 104 |
| 103 // base::SimpleThread: | 105 // base::SimpleThread: |
| 104 void Run() override { | 106 void Run() override { |
| 105 ApplicationRunner(this).Run(request_.PassMessagePipe().release().value(), | 107 ApplicationRunner(this).Run(request_.PassMessagePipe().release().value(), |
| 106 false); | 108 false); |
| 107 delete this; | 109 delete this; |
| 108 } | 110 } |
| 109 | 111 |
| 110 void OnConnectionError() { | 112 void OnConnectionError() { |
| 111 if (bindings_.empty()) | 113 if (bindings_.empty()) |
| 112 base::MessageLoop::current()->QuitWhenIdle(); | 114 base::MessageLoop::current()->QuitWhenIdle(); |
| 113 } | 115 } |
| 114 | 116 |
| 115 std::string name_; | 117 Identity identity_; |
| 116 uint32_t id_ = shell::mojom::kInvalidInstanceID; | 118 uint32_t id_ = shell::mojom::kInvalidInstanceID; |
| 117 std::string userid_ = mojom::kRootUserID; | |
| 118 const std::string title_; | 119 const std::string title_; |
| 119 mojom::ShellClientRequest request_; | 120 mojom::ShellClientRequest request_; |
| 120 test::mojom::ExposedInterfacePtr caller_; | 121 test::mojom::ExposedInterfacePtr caller_; |
| 121 BindingSet<test::mojom::ConnectTestService> bindings_; | 122 BindingSet<test::mojom::ConnectTestService> bindings_; |
| 122 BindingSet<test::mojom::BlockedInterface> blocked_bindings_; | 123 BindingSet<test::mojom::BlockedInterface> blocked_bindings_; |
| 123 | 124 |
| 124 DISALLOW_COPY_AND_ASSIGN(ProvidedShellClient); | 125 DISALLOW_COPY_AND_ASSIGN(ProvidedShellClient); |
| 125 }; | 126 }; |
| 126 | 127 |
| 127 class ConnectTestShellClient | 128 class ConnectTestShellClient |
| 128 : public ShellClient, | 129 : public ShellClient, |
| 129 public InterfaceFactory<mojom::ShellClientFactory>, | 130 public InterfaceFactory<mojom::ShellClientFactory>, |
| 130 public InterfaceFactory<test::mojom::ConnectTestService>, | 131 public InterfaceFactory<test::mojom::ConnectTestService>, |
| 131 public mojom::ShellClientFactory, | 132 public mojom::ShellClientFactory, |
| 132 public test::mojom::ConnectTestService { | 133 public test::mojom::ConnectTestService { |
| 133 public: | 134 public: |
| 134 ConnectTestShellClient() {} | 135 ConnectTestShellClient() {} |
| 135 ~ConnectTestShellClient() override {} | 136 ~ConnectTestShellClient() override {} |
| 136 | 137 |
| 137 private: | 138 private: |
| 138 // mojo::ShellClient: | 139 // mojo::ShellClient: |
| 139 void Initialize(Connector* connector, const Identity& identity, | 140 void Initialize(Connector* connector, const Identity& identity, |
| 140 uint32_t id) override { | 141 uint32_t id) override { |
| 142 identity_ = identity; |
| 141 bindings_.set_connection_error_handler( | 143 bindings_.set_connection_error_handler( |
| 142 base::Bind(&ConnectTestShellClient::OnConnectionError, | 144 base::Bind(&ConnectTestShellClient::OnConnectionError, |
| 143 base::Unretained(this))); | 145 base::Unretained(this))); |
| 144 } | 146 } |
| 145 bool AcceptConnection(Connection* connection) override { | 147 bool AcceptConnection(Connection* connection) override { |
| 146 connection->AddInterface<ShellClientFactory>(this); | 148 connection->AddInterface<ShellClientFactory>(this); |
| 147 connection->AddInterface<test::mojom::ConnectTestService>(this); | 149 connection->AddInterface<test::mojom::ConnectTestService>(this); |
| 148 return true; | 150 return true; |
| 149 } | 151 } |
| 150 void ShellConnectionLost() override { | 152 void ShellConnectionLost() override { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 172 if (name == "mojo:connect_test_a") | 174 if (name == "mojo:connect_test_a") |
| 173 new ProvidedShellClient("A", std::move(request)); | 175 new ProvidedShellClient("A", std::move(request)); |
| 174 else if (name == "mojo:connect_test_b") | 176 else if (name == "mojo:connect_test_b") |
| 175 new ProvidedShellClient("B", std::move(request)); | 177 new ProvidedShellClient("B", std::move(request)); |
| 176 } | 178 } |
| 177 | 179 |
| 178 // test::mojom::ConnectTestService: | 180 // test::mojom::ConnectTestService: |
| 179 void GetTitle(const GetTitleCallback& callback) override { | 181 void GetTitle(const GetTitleCallback& callback) override { |
| 180 callback.Run("ROOT"); | 182 callback.Run("ROOT"); |
| 181 } | 183 } |
| 184 void GetInstance(const GetInstanceCallback& callback) override { |
| 185 callback.Run(identity_.instance()); |
| 186 } |
| 182 | 187 |
| 183 void OnConnectionError() { | 188 void OnConnectionError() { |
| 184 if (bindings_.empty()) | 189 if (bindings_.empty()) |
| 185 base::MessageLoop::current()->QuitWhenIdle(); | 190 base::MessageLoop::current()->QuitWhenIdle(); |
| 186 } | 191 } |
| 187 | 192 |
| 193 Identity identity_; |
| 188 std::vector<scoped_ptr<ShellClient>> delegates_; | 194 std::vector<scoped_ptr<ShellClient>> delegates_; |
| 189 BindingSet<mojom::ShellClientFactory> shell_client_factory_bindings_; | 195 BindingSet<mojom::ShellClientFactory> shell_client_factory_bindings_; |
| 190 BindingSet<test::mojom::ConnectTestService> bindings_; | 196 BindingSet<test::mojom::ConnectTestService> bindings_; |
| 191 | 197 |
| 192 DISALLOW_COPY_AND_ASSIGN(ConnectTestShellClient); | 198 DISALLOW_COPY_AND_ASSIGN(ConnectTestShellClient); |
| 193 }; | 199 }; |
| 194 | 200 |
| 195 } // namespace shell | 201 } // namespace shell |
| 196 } // namespace mojo | 202 } // namespace mojo |
| 197 | 203 |
| 198 | 204 |
| 199 MojoResult MojoMain(MojoHandle shell_handle) { | 205 MojoResult MojoMain(MojoHandle shell_handle) { |
| 200 MojoResult rv = mojo::ApplicationRunner( | 206 MojoResult rv = mojo::ApplicationRunner( |
| 201 new mojo::shell::ConnectTestShellClient).Run(shell_handle); | 207 new mojo::shell::ConnectTestShellClient).Run(shell_handle); |
| 202 return rv; | 208 return rv; |
| 203 } | 209 } |
| OLD | NEW |