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 "mojo/public/cpp/system/buffer.h" |
16 #include "services/shell/public/cpp/interface_registry.h" | 17 #include "services/shell/public/cpp/interface_registry.h" |
17 | 18 |
18 namespace content { | 19 namespace content { |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 class TestMojoServiceImpl : public mojom::TestMojoService { | 23 class TestMojoServiceImpl : public mojom::TestMojoService { |
23 public: | 24 public: |
24 static void Create(mojo::InterfaceRequest<mojom::TestMojoService> request) { | 25 static void Create(mojo::InterfaceRequest<mojom::TestMojoService> request) { |
25 mojo::MakeStrongBinding(base::WrapUnique(new TestMojoServiceImpl), | 26 mojo::MakeStrongBinding(base::WrapUnique(new TestMojoServiceImpl), |
(...skipping 12 matching lines...) Expand all Loading... |
38 void CreateFolder(const CreateFolderCallback& callback) override { | 39 void CreateFolder(const CreateFolderCallback& callback) override { |
39 // Note: This is used to check if the sandbox is disabled or not since | 40 // Note: This is used to check if the sandbox is disabled or not since |
40 // creating a folder is forbidden when it is enabled. | 41 // creating a folder is forbidden when it is enabled. |
41 callback.Run(base::ScopedTempDir().CreateUniqueTempDir()); | 42 callback.Run(base::ScopedTempDir().CreateUniqueTempDir()); |
42 } | 43 } |
43 | 44 |
44 void GetRequestorName(const GetRequestorNameCallback& callback) override { | 45 void GetRequestorName(const GetRequestorNameCallback& callback) override { |
45 NOTREACHED(); | 46 NOTREACHED(); |
46 } | 47 } |
47 | 48 |
| 49 void CreateSharedBuffer(const std::string& message, |
| 50 const CreateSharedBufferCallback& callback) override { |
| 51 mojo::ScopedSharedBufferHandle buffer = |
| 52 mojo::SharedBufferHandle::Create(message.size()); |
| 53 CHECK(buffer.is_valid()); |
| 54 |
| 55 mojo::ScopedSharedBufferMapping mapping = buffer->Map(message.size()); |
| 56 CHECK(mapping); |
| 57 std::copy(message.begin(), message.end(), |
| 58 reinterpret_cast<char*>(mapping.get())); |
| 59 |
| 60 callback.Run(std::move(buffer)); |
| 61 } |
| 62 |
48 private: | 63 private: |
49 explicit TestMojoServiceImpl() {} | 64 explicit TestMojoServiceImpl() {} |
50 | 65 |
51 DISALLOW_COPY_AND_ASSIGN(TestMojoServiceImpl); | 66 DISALLOW_COPY_AND_ASSIGN(TestMojoServiceImpl); |
52 }; | 67 }; |
53 | 68 |
54 std::unique_ptr<shell::Service> CreateTestApp( | 69 std::unique_ptr<shell::Service> CreateTestApp( |
55 const base::Closure& quit_closure) { | 70 const base::Closure& quit_closure) { |
56 return std::unique_ptr<shell::Service>(new TestMojoApp); | 71 return std::unique_ptr<shell::Service>(new TestMojoApp); |
57 } | 72 } |
58 | 73 |
59 } // namespace | 74 } // namespace |
60 | 75 |
61 ShellContentUtilityClient::~ShellContentUtilityClient() { | 76 ShellContentUtilityClient::~ShellContentUtilityClient() { |
62 } | 77 } |
63 | 78 |
64 void ShellContentUtilityClient::RegisterMojoApplications( | 79 void ShellContentUtilityClient::RegisterMojoApplications( |
65 StaticMojoApplicationMap* apps) { | 80 StaticMojoApplicationMap* apps) { |
66 MojoApplicationInfo app_info; | 81 MojoApplicationInfo app_info; |
67 app_info.application_factory = base::Bind(&CreateTestApp); | 82 app_info.application_factory = base::Bind(&CreateTestApp); |
68 apps->insert(std::make_pair(kTestMojoAppUrl, app_info)); | 83 apps->insert(std::make_pair(kTestMojoAppUrl, app_info)); |
69 } | 84 } |
70 | 85 |
71 void ShellContentUtilityClient::ExposeInterfacesToBrowser( | 86 void ShellContentUtilityClient::ExposeInterfacesToBrowser( |
72 shell::InterfaceRegistry* registry) { | 87 shell::InterfaceRegistry* registry) { |
73 registry->AddInterface(base::Bind(&TestMojoServiceImpl::Create)); | 88 registry->AddInterface(base::Bind(&TestMojoServiceImpl::Create)); |
74 } | 89 } |
75 | 90 |
76 } // namespace content | 91 } // namespace content |
OLD | NEW |