| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/macros.h" | 6 #include "base/macros.h" |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "mojo/public/c/system/main.h" | 9 #include "mojo/public/c/system/main.h" |
| 10 #include "mojo/public/cpp/bindings/binding_set.h" | 10 #include "mojo/public/cpp/bindings/binding_set.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 public InterfaceFactory<test::mojom::BlockedInterface>, | 26 public InterfaceFactory<test::mojom::BlockedInterface>, |
| 27 public test::mojom::ConnectTestService, | 27 public test::mojom::ConnectTestService, |
| 28 public test::mojom::StandaloneApp, | 28 public test::mojom::StandaloneApp, |
| 29 public test::mojom::BlockedInterface { | 29 public test::mojom::BlockedInterface { |
| 30 public: | 30 public: |
| 31 ConnectTestApp() {} | 31 ConnectTestApp() {} |
| 32 ~ConnectTestApp() override {} | 32 ~ConnectTestApp() override {} |
| 33 | 33 |
| 34 private: | 34 private: |
| 35 // mojo::ShellClient: | 35 // mojo::ShellClient: |
| 36 void Initialize(Connector* connector, const std::string& name, | 36 void Initialize(Connector* connector, const Identity& identity, |
| 37 const std::string& user_id, uint32_t id) override { | 37 uint32_t id) override { |
| 38 connector_ = connector; | 38 connector_ = connector; |
| 39 name_ = name; | 39 identity_ = identity; |
| 40 id_ = id; | 40 id_ = id; |
| 41 userid_ = user_id; | |
| 42 bindings_.set_connection_error_handler( | 41 bindings_.set_connection_error_handler( |
| 43 base::Bind(&ConnectTestApp::OnConnectionError, | 42 base::Bind(&ConnectTestApp::OnConnectionError, |
| 44 base::Unretained(this))); | 43 base::Unretained(this))); |
| 45 standalone_bindings_.set_connection_error_handler( | 44 standalone_bindings_.set_connection_error_handler( |
| 46 base::Bind(&ConnectTestApp::OnConnectionError, | 45 base::Bind(&ConnectTestApp::OnConnectionError, |
| 47 base::Unretained(this))); | 46 base::Unretained(this))); |
| 48 } | 47 } |
| 49 bool AcceptConnection(Connection* connection) override { | 48 bool AcceptConnection(Connection* connection) override { |
| 50 connection->AddInterface<test::mojom::ConnectTestService>(this); | 49 connection->AddInterface<test::mojom::ConnectTestService>(this); |
| 51 connection->AddInterface<test::mojom::StandaloneApp>(this); | 50 connection->AddInterface<test::mojom::StandaloneApp>(this); |
| 52 connection->AddInterface<test::mojom::BlockedInterface>(this); | 51 connection->AddInterface<test::mojom::BlockedInterface>(this); |
| 53 | 52 |
| 54 uint32_t remote_id = connection->GetRemoteInstanceID(); | 53 uint32_t remote_id = connection->GetRemoteInstanceID(); |
| 55 test::mojom::ConnectionStatePtr state(test::mojom::ConnectionState::New()); | 54 test::mojom::ConnectionStatePtr state(test::mojom::ConnectionState::New()); |
| 56 state->connection_local_name = connection->GetConnectionName(); | 55 state->connection_local_name = connection->GetConnectionName(); |
| 57 state->connection_remote_name = connection->GetRemoteApplicationName(); | 56 state->connection_remote_name = connection->GetRemoteIdentity().name(); |
| 58 state->connection_remote_userid = connection->GetRemoteUserID(); | 57 state->connection_remote_userid = connection->GetRemoteIdentity().user_id(); |
| 59 state->connection_remote_id = remote_id; | 58 state->connection_remote_id = remote_id; |
| 60 state->initialize_local_name = name_; | 59 state->initialize_local_name = identity_.name(); |
| 61 state->initialize_id = id_; | 60 state->initialize_id = id_; |
| 62 state->initialize_userid = userid_; | 61 state->initialize_userid = identity_.user_id(); |
| 63 connection->GetInterface(&caller_); | 62 connection->GetInterface(&caller_); |
| 64 caller_->ConnectionAccepted(std::move(state)); | 63 caller_->ConnectionAccepted(std::move(state)); |
| 65 | 64 |
| 66 return true; | 65 return true; |
| 67 } | 66 } |
| 68 void ShellConnectionLost() override { | 67 void ShellConnectionLost() override { |
| 69 if (base::MessageLoop::current() && | 68 if (base::MessageLoop::current() && |
| 70 base::MessageLoop::current()->is_running()) { | 69 base::MessageLoop::current()->is_running()) { |
| 71 base::MessageLoop::current()->QuitWhenIdle(); | 70 base::MessageLoop::current()->QuitWhenIdle(); |
| 72 } | 71 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 base::Bind(&ConnectTestApp::OnGotTitle, base::Unretained(this), | 109 base::Bind(&ConnectTestApp::OnGotTitle, base::Unretained(this), |
| 111 callback, &run_loop)); | 110 callback, &run_loop)); |
| 112 { | 111 { |
| 113 // This message is dispatched as a task on the same run loop, so we need | 112 // This message is dispatched as a task on the same run loop, so we need |
| 114 // to allow nesting in order to pump additional signals. | 113 // to allow nesting in order to pump additional signals. |
| 115 base::MessageLoop::ScopedNestableTaskAllower allow( | 114 base::MessageLoop::ScopedNestableTaskAllower allow( |
| 116 base::MessageLoop::current()); | 115 base::MessageLoop::current()); |
| 117 run_loop.Run(); | 116 run_loop.Run(); |
| 118 } | 117 } |
| 119 } | 118 } |
| 119 void GetInstance(const GetInstanceCallback& callback) override { |
| 120 callback.Run(identity_.instance()); |
| 121 } |
| 120 | 122 |
| 121 // test::mojom::BlockedInterface: | 123 // test::mojom::BlockedInterface: |
| 122 void GetTitleBlocked(const GetTitleBlockedCallback& callback) override { | 124 void GetTitleBlocked(const GetTitleBlockedCallback& callback) override { |
| 123 callback.Run("Called Blocked Interface!"); | 125 callback.Run("Called Blocked Interface!"); |
| 124 } | 126 } |
| 125 | 127 |
| 126 void OnConnectionBlocked( | 128 void OnConnectionBlocked( |
| 127 const ConnectToAllowedAppInBlockedPackageCallback& callback, | 129 const ConnectToAllowedAppInBlockedPackageCallback& callback, |
| 128 base::RunLoop* run_loop) { | 130 base::RunLoop* run_loop) { |
| 129 callback.Run("uninitialized"); | 131 callback.Run("uninitialized"); |
| 130 run_loop->Quit(); | 132 run_loop->Quit(); |
| 131 } | 133 } |
| 132 | 134 |
| 133 void OnGotTitle( | 135 void OnGotTitle( |
| 134 const ConnectToAllowedAppInBlockedPackageCallback& callback, | 136 const ConnectToAllowedAppInBlockedPackageCallback& callback, |
| 135 base::RunLoop* run_loop, | 137 base::RunLoop* run_loop, |
| 136 const mojo::String& title) { | 138 const mojo::String& title) { |
| 137 callback.Run(title); | 139 callback.Run(title); |
| 138 run_loop->Quit(); | 140 run_loop->Quit(); |
| 139 } | 141 } |
| 140 | 142 |
| 141 void OnConnectionError() { | 143 void OnConnectionError() { |
| 142 if (bindings_.empty() && standalone_bindings_.empty()) | 144 if (bindings_.empty() && standalone_bindings_.empty()) |
| 143 base::MessageLoop::current()->QuitWhenIdle(); | 145 base::MessageLoop::current()->QuitWhenIdle(); |
| 144 } | 146 } |
| 145 | 147 |
| 146 Connector* connector_ = nullptr; | 148 Connector* connector_ = nullptr; |
| 147 std::string name_; | 149 Identity identity_; |
| 148 uint32_t id_ = shell::mojom::kInvalidInstanceID; | 150 uint32_t id_ = shell::mojom::kInvalidInstanceID; |
| 149 std::string userid_ = mojom::kRootUserID; | |
| 150 BindingSet<test::mojom::ConnectTestService> bindings_; | 151 BindingSet<test::mojom::ConnectTestService> bindings_; |
| 151 BindingSet<test::mojom::StandaloneApp> standalone_bindings_; | 152 BindingSet<test::mojom::StandaloneApp> standalone_bindings_; |
| 152 BindingSet<test::mojom::BlockedInterface> blocked_bindings_; | 153 BindingSet<test::mojom::BlockedInterface> blocked_bindings_; |
| 153 test::mojom::ExposedInterfacePtr caller_; | 154 test::mojom::ExposedInterfacePtr caller_; |
| 154 | 155 |
| 155 DISALLOW_COPY_AND_ASSIGN(ConnectTestApp); | 156 DISALLOW_COPY_AND_ASSIGN(ConnectTestApp); |
| 156 }; | 157 }; |
| 157 | 158 |
| 158 } // namespace shell | 159 } // namespace shell |
| 159 } // namespace mojo | 160 } // namespace mojo |
| 160 | 161 |
| 161 | 162 |
| 162 MojoResult MojoMain(MojoHandle shell_handle) { | 163 MojoResult MojoMain(MojoHandle shell_handle) { |
| 163 MojoResult rv = mojo::ApplicationRunner( | 164 MojoResult rv = mojo::ApplicationRunner( |
| 164 new mojo::shell::ConnectTestApp).Run(shell_handle); | 165 new mojo::shell::ConnectTestApp).Run(shell_handle); |
| 165 return rv; | 166 return rv; |
| 166 } | 167 } |
| OLD | NEW |