| OLD | NEW |
| 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 #include <utility> | 5 #include <utility> |
| 6 | 6 |
| 7 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 // Loader implementation. | 116 // Loader implementation. |
| 117 void Load(const std::string& name, | 117 void Load(const std::string& name, |
| 118 mojom::ShellClientRequest request) override { | 118 mojom::ShellClientRequest request) override { |
| 119 ++num_loads_; | 119 ++num_loads_; |
| 120 shell_connection_.reset(new ShellConnection(this, std::move(request))); | 120 shell_connection_.reset(new ShellConnection(this, std::move(request))); |
| 121 } | 121 } |
| 122 | 122 |
| 123 // mojo::ShellClient implementation. | 123 // mojo::ShellClient implementation. |
| 124 bool AcceptConnection(Connection* connection) override { | 124 bool AcceptConnection(Connection* connection) override { |
| 125 connection->AddInterface<TestService>(this); | 125 connection->AddInterface<TestService>(this); |
| 126 last_requestor_name_ = connection->GetRemoteApplicationName(); | 126 last_requestor_name_ = connection->GetRemoteIdentity().name(); |
| 127 return true; | 127 return true; |
| 128 } | 128 } |
| 129 | 129 |
| 130 // InterfaceFactory<TestService> implementation. | 130 // InterfaceFactory<TestService> implementation. |
| 131 void Create(Connection* connection, | 131 void Create(Connection* connection, |
| 132 InterfaceRequest<TestService> request) override { | 132 InterfaceRequest<TestService> request) override { |
| 133 new TestServiceImpl(context_, std::move(request)); | 133 new TestServiceImpl(context_, std::move(request)); |
| 134 } | 134 } |
| 135 | 135 |
| 136 scoped_ptr<ShellConnection> shell_connection_; | 136 scoped_ptr<ShellConnection> shell_connection_; |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 ~Tester() override {} | 346 ~Tester() override {} |
| 347 | 347 |
| 348 private: | 348 private: |
| 349 void Load(const std::string& name, | 349 void Load(const std::string& name, |
| 350 InterfaceRequest<mojom::ShellClient> request) override { | 350 InterfaceRequest<mojom::ShellClient> request) override { |
| 351 app_.reset(new ShellConnection(this, std::move(request))); | 351 app_.reset(new ShellConnection(this, std::move(request))); |
| 352 } | 352 } |
| 353 | 353 |
| 354 bool AcceptConnection(Connection* connection) override { | 354 bool AcceptConnection(Connection* connection) override { |
| 355 if (!requestor_name_.empty() && | 355 if (!requestor_name_.empty() && |
| 356 requestor_name_ != connection->GetRemoteApplicationName()) { | 356 requestor_name_ != connection->GetRemoteIdentity().name()) { |
| 357 context_->set_tester_called_quit(); | 357 context_->set_tester_called_quit(); |
| 358 context_->QuitSoon(); | 358 context_->QuitSoon(); |
| 359 base::MessageLoop::current()->QuitWhenIdle(); | 359 base::MessageLoop::current()->QuitWhenIdle(); |
| 360 return false; | 360 return false; |
| 361 } | 361 } |
| 362 // If we're coming from A, then add B, otherwise A. | 362 // If we're coming from A, then add B, otherwise A. |
| 363 if (connection->GetRemoteApplicationName() == kTestAURLString) | 363 if (connection->GetRemoteIdentity().name() == kTestAURLString) |
| 364 connection->AddInterface<TestB>(this); | 364 connection->AddInterface<TestB>(this); |
| 365 else | 365 else |
| 366 connection->AddInterface<TestA>(this); | 366 connection->AddInterface<TestA>(this); |
| 367 return true; | 367 return true; |
| 368 } | 368 } |
| 369 | 369 |
| 370 void Create(Connection* connection, | 370 void Create(Connection* connection, |
| 371 InterfaceRequest<TestA> request) override { | 371 InterfaceRequest<TestA> request) override { |
| 372 a_bindings_.push_back( | 372 a_bindings_.push_back( |
| 373 new TestAImpl(app_->connector(), context_, std::move(request), this)); | 373 new TestAImpl(app_->connector(), context_, std::move(request), this)); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 } | 426 } |
| 427 | 427 |
| 428 protected: | 428 protected: |
| 429 template <typename Interface> | 429 template <typename Interface> |
| 430 void ConnectToInterface(const std::string& name, | 430 void ConnectToInterface(const std::string& name, |
| 431 InterfacePtr<Interface>* ptr) { | 431 InterfacePtr<Interface>* ptr) { |
| 432 base::RunLoop loop; | 432 base::RunLoop loop; |
| 433 mojom::InterfaceProviderPtr remote_interfaces; | 433 mojom::InterfaceProviderPtr remote_interfaces; |
| 434 scoped_ptr<ConnectParams> params(new ConnectParams); | 434 scoped_ptr<ConnectParams> params(new ConnectParams); |
| 435 params->set_source(CreateShellIdentity()); | 435 params->set_source(CreateShellIdentity()); |
| 436 params->set_target(Identity(name)); | 436 params->set_target(Identity(name, mojom::kRootUserID)); |
| 437 params->set_remote_interfaces(GetProxy(&remote_interfaces)); | 437 params->set_remote_interfaces(GetProxy(&remote_interfaces)); |
| 438 params->set_connect_callback( | 438 params->set_connect_callback( |
| 439 base::Bind(&OnConnect, base::Unretained(&loop))); | 439 base::Bind(&OnConnect, base::Unretained(&loop))); |
| 440 shell_->Connect(std::move(params)); | 440 shell_->Connect(std::move(params)); |
| 441 loop.Run(); | 441 loop.Run(); |
| 442 | 442 |
| 443 mojo::GetInterface(remote_interfaces.get(), ptr); | 443 mojo::GetInterface(remote_interfaces.get(), ptr); |
| 444 } | 444 } |
| 445 | 445 |
| 446 base::ShadowingAtExitManager at_exit_; | 446 base::ShadowingAtExitManager at_exit_; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 EXPECT_TRUE(c.encountered_error()); | 516 EXPECT_TRUE(c.encountered_error()); |
| 517 } | 517 } |
| 518 | 518 |
| 519 TEST_F(LoaderTest, TestEndApplicationClosure) { | 519 TEST_F(LoaderTest, TestEndApplicationClosure) { |
| 520 ClosingLoader* loader = new ClosingLoader(); | 520 ClosingLoader* loader = new ClosingLoader(); |
| 521 shell_->SetLoaderForName(scoped_ptr<Loader>(loader), "test:test"); | 521 shell_->SetLoaderForName(scoped_ptr<Loader>(loader), "test:test"); |
| 522 | 522 |
| 523 bool called = false; | 523 bool called = false; |
| 524 scoped_ptr<ConnectParams> params(new ConnectParams); | 524 scoped_ptr<ConnectParams> params(new ConnectParams); |
| 525 params->set_source(CreateShellIdentity()); | 525 params->set_source(CreateShellIdentity()); |
| 526 params->set_target(Identity("test:test", "", mojom::kRootUserID)); | 526 params->set_target(Identity("test:test", mojom::kRootUserID)); |
| 527 shell_->SetInstanceQuitCallback( | 527 shell_->SetInstanceQuitCallback( |
| 528 base::Bind(&QuitClosure, params->target(), &called)); | 528 base::Bind(&QuitClosure, params->target(), &called)); |
| 529 shell_->Connect(std::move(params)); | 529 shell_->Connect(std::move(params)); |
| 530 loop_.Run(); | 530 loop_.Run(); |
| 531 EXPECT_TRUE(called); | 531 EXPECT_TRUE(called); |
| 532 } | 532 } |
| 533 | 533 |
| 534 TEST_F(LoaderTest, SameIdentityShouldNotCauseDuplicateLoad) { | 534 TEST_F(LoaderTest, SameIdentityShouldNotCauseDuplicateLoad) { |
| 535 // 1 because LoaderTest connects once at startup. | 535 // 1 because LoaderTest connects once at startup. |
| 536 EXPECT_EQ(1, test_loader_->num_loads()); | 536 EXPECT_EQ(1, test_loader_->num_loads()); |
| 537 | 537 |
| 538 TestServicePtr test_service; | 538 TestServicePtr test_service; |
| 539 ConnectToInterface("test:foo", &test_service); | 539 ConnectToInterface("test:foo", &test_service); |
| 540 EXPECT_EQ(2, test_loader_->num_loads()); | 540 EXPECT_EQ(2, test_loader_->num_loads()); |
| 541 | 541 |
| 542 // Exactly the same name as above. | 542 // Exactly the same name as above. |
| 543 ConnectToInterface("test:foo", &test_service); | 543 ConnectToInterface("test:foo", &test_service); |
| 544 EXPECT_EQ(2, test_loader_->num_loads()); | 544 EXPECT_EQ(2, test_loader_->num_loads()); |
| 545 | 545 |
| 546 // A different identity because the domain is different. | 546 // A different identity because the domain is different. |
| 547 ConnectToInterface("test:bar", &test_service); | 547 ConnectToInterface("test:bar", &test_service); |
| 548 EXPECT_EQ(3, test_loader_->num_loads()); | 548 EXPECT_EQ(3, test_loader_->num_loads()); |
| 549 } | 549 } |
| 550 | 550 |
| 551 } // namespace test | 551 } // namespace test |
| 552 } // namespace shell | 552 } // namespace shell |
| 553 } // namespace mojo | 553 } // namespace mojo |
| OLD | NEW |