| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "content/shell/utility/shell_content_utility_client.h" | 5 #include "content/shell/utility/shell_content_utility_client.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
| 12 #include "base/process/process.h" | 12 #include "base/process/process.h" |
| 13 #include "content/public/test/test_mojo_app.h" | 13 #include "content/public/test/test_mojo_app.h" |
| 14 #include "content/public/test/test_mojo_service.mojom.h" | 14 #include "content/public/test/test_mojo_service.mojom.h" |
| 15 #include "mojo/public/cpp/bindings/strong_binding.h" | 15 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 16 #include "services/shell/public/cpp/interface_registry.h" | 16 #include "services/shell/public/cpp/interface_registry.h" |
| 17 | 17 |
| 18 namespace content { | 18 namespace content { |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 class TestMojoServiceImpl : public mojom::TestMojoService { | 22 class TestMojoServiceImpl : public mojom::TestMojoService { |
| 23 public: | 23 public: |
| 24 static void Create(mojo::InterfaceRequest<mojom::TestMojoService> request) { | 24 static void Create(mojo::InterfaceRequest<mojom::TestMojoService> request) { |
| 25 new TestMojoServiceImpl(std::move(request)); | 25 mojo::MakeStrongBinding(base::WrapUnique(new TestMojoServiceImpl), |
| 26 std::move(request)); |
| 26 } | 27 } |
| 27 | 28 |
| 28 // mojom::TestMojoService implementation: | 29 // mojom::TestMojoService implementation: |
| 29 void DoSomething(const DoSomethingCallback& callback) override { | 30 void DoSomething(const DoSomethingCallback& callback) override { |
| 30 callback.Run(); | 31 callback.Run(); |
| 31 } | 32 } |
| 32 | 33 |
| 33 void DoTerminateProcess(const DoTerminateProcessCallback& callback) override { | 34 void DoTerminateProcess(const DoTerminateProcessCallback& callback) override { |
| 34 base::Process::Current().Terminate(0, false); | 35 base::Process::Current().Terminate(0, false); |
| 35 } | 36 } |
| 36 | 37 |
| 37 void CreateFolder(const CreateFolderCallback& callback) override { | 38 void CreateFolder(const CreateFolderCallback& callback) override { |
| 38 // Note: This is used to check if the sandbox is disabled or not since | 39 // Note: This is used to check if the sandbox is disabled or not since |
| 39 // creating a folder is forbidden when it is enabled. | 40 // creating a folder is forbidden when it is enabled. |
| 40 callback.Run(base::ScopedTempDir().CreateUniqueTempDir()); | 41 callback.Run(base::ScopedTempDir().CreateUniqueTempDir()); |
| 41 } | 42 } |
| 42 | 43 |
| 43 void GetRequestorName(const GetRequestorNameCallback& callback) override { | 44 void GetRequestorName(const GetRequestorNameCallback& callback) override { |
| 44 NOTREACHED(); | 45 NOTREACHED(); |
| 45 } | 46 } |
| 46 | 47 |
| 47 private: | 48 private: |
| 48 explicit TestMojoServiceImpl( | 49 explicit TestMojoServiceImpl() {} |
| 49 mojo::InterfaceRequest<mojom::TestMojoService> request) | |
| 50 : binding_(this, std::move(request)) {} | |
| 51 | |
| 52 mojo::StrongBinding<mojom::TestMojoService> binding_; | |
| 53 | 50 |
| 54 DISALLOW_COPY_AND_ASSIGN(TestMojoServiceImpl); | 51 DISALLOW_COPY_AND_ASSIGN(TestMojoServiceImpl); |
| 55 }; | 52 }; |
| 56 | 53 |
| 57 std::unique_ptr<shell::Service> CreateTestApp( | 54 std::unique_ptr<shell::Service> CreateTestApp( |
| 58 const base::Closure& quit_closure) { | 55 const base::Closure& quit_closure) { |
| 59 return std::unique_ptr<shell::Service>(new TestMojoApp); | 56 return std::unique_ptr<shell::Service>(new TestMojoApp); |
| 60 } | 57 } |
| 61 | 58 |
| 62 } // namespace | 59 } // namespace |
| 63 | 60 |
| 64 ShellContentUtilityClient::~ShellContentUtilityClient() { | 61 ShellContentUtilityClient::~ShellContentUtilityClient() { |
| 65 } | 62 } |
| 66 | 63 |
| 67 void ShellContentUtilityClient::RegisterMojoApplications( | 64 void ShellContentUtilityClient::RegisterMojoApplications( |
| 68 StaticMojoApplicationMap* apps) { | 65 StaticMojoApplicationMap* apps) { |
| 69 MojoApplicationInfo app_info; | 66 MojoApplicationInfo app_info; |
| 70 app_info.application_factory = base::Bind(&CreateTestApp); | 67 app_info.application_factory = base::Bind(&CreateTestApp); |
| 71 apps->insert(std::make_pair(kTestMojoAppUrl, app_info)); | 68 apps->insert(std::make_pair(kTestMojoAppUrl, app_info)); |
| 72 } | 69 } |
| 73 | 70 |
| 74 void ShellContentUtilityClient::ExposeInterfacesToBrowser( | 71 void ShellContentUtilityClient::ExposeInterfacesToBrowser( |
| 75 shell::InterfaceRegistry* registry) { | 72 shell::InterfaceRegistry* registry) { |
| 76 registry->AddInterface(base::Bind(&TestMojoServiceImpl::Create)); | 73 registry->AddInterface(base::Bind(&TestMojoServiceImpl::Create)); |
| 77 } | 74 } |
| 78 | 75 |
| 79 } // namespace content | 76 } // namespace content |
| OLD | NEW |