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 "mojo/shell/background/background_shell.h" | 5 #include "mojo/shell/background/background_shell.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
12 #include "base/synchronization/waitable_event.h" | 12 #include "base/synchronization/waitable_event.h" |
13 #include "base/threading/simple_thread.h" | 13 #include "base/threading/simple_thread.h" |
14 #include "mojo/message_pump/message_pump_mojo.h" | 14 #include "mojo/message_pump/message_pump_mojo.h" |
15 #include "mojo/shell/application_loader.h" | 15 #include "mojo/shell/application_loader.h" |
16 #include "mojo/shell/application_manager.h" | 16 #include "mojo/shell/application_manager.h" |
17 #include "mojo/shell/capability_filter.h" | 17 #include "mojo/shell/capability_filter.h" |
18 #include "mojo/shell/connect_to_application_params.h" | 18 #include "mojo/shell/connect_to_application_params.h" |
19 #include "mojo/shell/public/cpp/application_impl.h" | |
20 #include "mojo/shell/public/cpp/shell_client.h" | 19 #include "mojo/shell/public/cpp/shell_client.h" |
| 20 #include "mojo/shell/public/cpp/shell_connection.h" |
21 #include "mojo/shell/standalone/context.h" | 21 #include "mojo/shell/standalone/context.h" |
22 #include "url/gurl.h" | 22 #include "url/gurl.h" |
23 | 23 |
24 namespace mojo { | 24 namespace mojo { |
25 namespace shell { | 25 namespace shell { |
26 namespace { | 26 namespace { |
27 | 27 |
28 scoped_ptr<base::MessagePump> CreateMessagePumpMojo() { | 28 scoped_ptr<base::MessagePump> CreateMessagePumpMojo() { |
29 return make_scoped_ptr(new common::MessagePumpMojo); | 29 return make_scoped_ptr(new common::MessagePumpMojo); |
30 } | 30 } |
31 | 31 |
32 // Used to obtain the InterfaceRequest for an application. | 32 // Used to obtain the InterfaceRequest for an application. |
33 class BackgroundApplicationLoader : public ApplicationLoader { | 33 class BackgroundApplicationLoader : public ApplicationLoader { |
34 public: | 34 public: |
35 BackgroundApplicationLoader() {} | 35 BackgroundApplicationLoader() {} |
36 ~BackgroundApplicationLoader() override {} | 36 ~BackgroundApplicationLoader() override {} |
37 | 37 |
38 bool got_request() const { return got_request_; } | 38 bool got_request() const { return got_request_; } |
39 InterfaceRequest<mojom::Application> TakeApplicationRequest() { | 39 InterfaceRequest<mojom::ShellClient> TakeApplicationRequest() { |
40 return std::move(application_request_); | 40 return std::move(request_); |
41 } | 41 } |
42 | 42 |
43 // ApplicationLoader: | 43 // ApplicationLoader: |
44 void Load(const GURL& url, | 44 void Load(const GURL& url, |
45 InterfaceRequest<mojom::Application> application_request) override { | 45 InterfaceRequest<mojom::ShellClient> request) override { |
46 got_request_ = true; | 46 got_request_ = true; |
47 application_request_ = std::move(application_request); | 47 request_ = std::move(request); |
48 } | 48 } |
49 | 49 |
50 private: | 50 private: |
51 bool got_request_ = false; | 51 bool got_request_ = false; |
52 InterfaceRequest<mojom::Application> application_request_; | 52 InterfaceRequest<mojom::ShellClient> request_; |
53 | 53 |
54 DISALLOW_COPY_AND_ASSIGN(BackgroundApplicationLoader); | 54 DISALLOW_COPY_AND_ASSIGN(BackgroundApplicationLoader); |
55 }; | 55 }; |
56 | 56 |
57 class MojoMessageLoop : public base::MessageLoop { | 57 class MojoMessageLoop : public base::MessageLoop { |
58 public: | 58 public: |
59 MojoMessageLoop() | 59 MojoMessageLoop() |
60 : base::MessageLoop(base::MessageLoop::TYPE_CUSTOM, | 60 : base::MessageLoop(base::MessageLoop::TYPE_CUSTOM, |
61 base::Bind(&CreateMessagePumpMojo)) {} | 61 base::Bind(&CreateMessagePumpMojo)) {} |
62 ~MojoMessageLoop() override {} | 62 ~MojoMessageLoop() override {} |
63 | 63 |
64 void BindToCurrentThread() { base::MessageLoop::BindToCurrentThread(); } | 64 void BindToCurrentThread() { base::MessageLoop::BindToCurrentThread(); } |
65 | 65 |
66 private: | 66 private: |
67 DISALLOW_COPY_AND_ASSIGN(MojoMessageLoop); | 67 DISALLOW_COPY_AND_ASSIGN(MojoMessageLoop); |
68 }; | 68 }; |
69 | 69 |
70 } // namespace | 70 } // namespace |
71 | 71 |
72 // Manages the thread to startup mojo. | 72 // Manages the thread to startup mojo. |
73 class BackgroundShell::MojoThread : public base::SimpleThread { | 73 class BackgroundShell::MojoThread : public base::SimpleThread { |
74 public: | 74 public: |
75 MojoThread() : SimpleThread("mojo-background-shell") {} | 75 MojoThread() : SimpleThread("mojo-background-shell") {} |
76 ~MojoThread() override {} | 76 ~MojoThread() override {} |
77 | 77 |
78 void CreateApplicationImpl(base::WaitableEvent* signal, | 78 void CreateShellClientRequest(base::WaitableEvent* signal, |
79 scoped_ptr<ConnectToApplicationParams> params, | 79 scoped_ptr<ConnectToApplicationParams> params, |
80 InterfaceRequest<mojom::Application>* request) { | 80 InterfaceRequest<mojom::ShellClient>* request) { |
81 // Only valid to call this on the background thread. | 81 // Only valid to call this on the background thread. |
82 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 82 DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
83 | 83 |
84 // Ownership of |loader| passes to ApplicationManager. | 84 // Ownership of |loader| passes to ApplicationManager. |
85 BackgroundApplicationLoader* loader = new BackgroundApplicationLoader; | 85 BackgroundApplicationLoader* loader = new BackgroundApplicationLoader; |
86 const GURL url = params->target().url(); | 86 const GURL url = params->target().url(); |
87 context_->application_manager()->SetLoaderForURL(make_scoped_ptr(loader), | 87 context_->application_manager()->SetLoaderForURL(make_scoped_ptr(loader), |
88 url); | 88 url); |
89 context_->application_manager()->ConnectToApplication(std::move(params)); | 89 context_->application_manager()->ConnectToApplication(std::move(params)); |
90 DCHECK(loader->got_request()); | 90 DCHECK(loader->got_request()); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 BackgroundShell::~BackgroundShell() { | 151 BackgroundShell::~BackgroundShell() { |
152 thread_->Stop(); | 152 thread_->Stop(); |
153 } | 153 } |
154 | 154 |
155 void BackgroundShell::Init() { | 155 void BackgroundShell::Init() { |
156 DCHECK(!thread_); | 156 DCHECK(!thread_); |
157 thread_.reset(new MojoThread); | 157 thread_.reset(new MojoThread); |
158 thread_->Start(); | 158 thread_->Start(); |
159 } | 159 } |
160 | 160 |
161 InterfaceRequest<mojom::Application> BackgroundShell::CreateApplication( | 161 InterfaceRequest<mojom::ShellClient> BackgroundShell::CreateShellClientRequest( |
162 const GURL& url) { | 162 const GURL& url) { |
163 scoped_ptr<ConnectToApplicationParams> params(new ConnectToApplicationParams); | 163 scoped_ptr<ConnectToApplicationParams> params(new ConnectToApplicationParams); |
164 params->SetTarget( | 164 params->SetTarget( |
165 Identity(url, std::string(), GetPermissiveCapabilityFilter())); | 165 Identity(url, std::string(), GetPermissiveCapabilityFilter())); |
166 InterfaceRequest<mojom::Application> request; | 166 InterfaceRequest<mojom::ShellClient> request; |
167 base::WaitableEvent signal(true, false); | 167 base::WaitableEvent signal(true, false); |
168 thread_->message_loop()->task_runner()->PostTask( | 168 thread_->message_loop()->task_runner()->PostTask( |
169 FROM_HERE, base::Bind(&MojoThread::CreateApplicationImpl, | 169 FROM_HERE, base::Bind(&MojoThread::CreateShellClientRequest, |
170 base::Unretained(thread_.get()), &signal, | 170 base::Unretained(thread_.get()), &signal, |
171 base::Passed(¶ms), &request)); | 171 base::Passed(¶ms), &request)); |
172 signal.Wait(); | 172 signal.Wait(); |
173 return request; | 173 return request; |
174 } | 174 } |
175 | 175 |
176 void RegisterLocalAliases(PackageManagerImpl* manager) {} | 176 void RegisterLocalAliases(PackageManagerImpl* manager) {} |
177 | 177 |
178 } // namespace shell | 178 } // namespace shell |
179 } // namespace mojo | 179 } // namespace mojo |
OLD | NEW |