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/public/test/test_mojo_app.h" | 5 #include "content/public/test/test_mojo_app.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop/message_loop.h" |
10 #include "mojo/shell/public/cpp/connection.h" | 11 #include "mojo/shell/public/cpp/connection.h" |
11 #include "mojo/shell/public/cpp/shell.h" | 12 #include "mojo/shell/public/cpp/connector.h" |
12 | 13 |
13 namespace content { | 14 namespace content { |
14 | 15 |
15 const char kTestMojoAppUrl[] = "system:content_mojo_test"; | 16 const char kTestMojoAppUrl[] = "system:content_mojo_test"; |
16 | 17 |
17 TestMojoApp::TestMojoApp() : service_binding_(this), shell_(nullptr) { | 18 TestMojoApp::TestMojoApp() : service_binding_(this) { |
18 } | 19 } |
19 | 20 |
20 TestMojoApp::~TestMojoApp() { | 21 TestMojoApp::~TestMojoApp() { |
21 } | 22 } |
22 | 23 |
23 void TestMojoApp::Initialize(mojo::Shell* shell, const std::string& url, | |
24 uint32_t id, uint32_t user_id) { | |
25 shell_ = shell; | |
26 } | |
27 | |
28 bool TestMojoApp::AcceptConnection(mojo::Connection* connection) { | 24 bool TestMojoApp::AcceptConnection(mojo::Connection* connection) { |
29 requestor_url_ = GURL(connection->GetRemoteApplicationURL()); | 25 requestor_url_ = GURL(connection->GetRemoteApplicationURL()); |
30 connection->AddInterface<TestMojoService>(this); | 26 connection->AddInterface<TestMojoService>(this); |
31 return true; | 27 return true; |
32 } | 28 } |
33 | 29 |
34 void TestMojoApp::Create(mojo::Connection* connection, | 30 void TestMojoApp::Create(mojo::Connection* connection, |
35 mojo::InterfaceRequest<TestMojoService> request) { | 31 mojo::InterfaceRequest<TestMojoService> request) { |
36 DCHECK(!service_binding_.is_bound()); | 32 DCHECK(!service_binding_.is_bound()); |
37 service_binding_.Bind(std::move(request)); | 33 service_binding_.Bind(std::move(request)); |
38 } | 34 } |
39 | 35 |
40 void TestMojoApp::DoSomething(const DoSomethingCallback& callback) { | 36 void TestMojoApp::DoSomething(const DoSomethingCallback& callback) { |
41 callback.Run(); | 37 callback.Run(); |
42 DCHECK(shell_); | 38 base::MessageLoop::current()->QuitWhenIdle(); |
43 shell_->Quit(); | |
44 } | 39 } |
45 | 40 |
46 void TestMojoApp::GetRequestorURL(const GetRequestorURLCallback& callback) { | 41 void TestMojoApp::GetRequestorURL(const GetRequestorURLCallback& callback) { |
47 callback.Run(requestor_url_.spec()); | 42 callback.Run(requestor_url_.spec()); |
48 } | 43 } |
49 | 44 |
50 } // namespace content | 45 } // namespace content |
OLD | NEW |