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 "mojo/shell/static_application_loader.h" | 5 #include "mojo/shell/static_application_loader.h" |
6 | 6 |
| 7 #include <utility> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/macros.h" | 10 #include "base/macros.h" |
9 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
10 #include "base/task_runner.h" | 12 #include "base/task_runner.h" |
11 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
12 #include "base/threading/simple_thread.h" | 14 #include "base/threading/simple_thread.h" |
13 #include "mojo/application/public/cpp/application_delegate.h" | 15 #include "mojo/application/public/cpp/application_delegate.h" |
14 #include "mojo/application/public/cpp/application_runner.h" | 16 #include "mojo/application/public/cpp/application_runner.h" |
15 #include "mojo/application/public/interfaces/application.mojom.h" | 17 #include "mojo/application/public/interfaces/application.mojom.h" |
16 #include "mojo/public/cpp/bindings/interface_request.h" | 18 #include "mojo/public/cpp/bindings/interface_request.h" |
17 | 19 |
18 namespace mojo { | 20 namespace mojo { |
19 namespace shell { | 21 namespace shell { |
20 | 22 |
21 namespace { | 23 namespace { |
22 | 24 |
23 class RunnerThread : public base::SimpleThread { | 25 class RunnerThread : public base::SimpleThread { |
24 public: | 26 public: |
25 RunnerThread(const GURL& url, | 27 RunnerThread(const GURL& url, |
26 InterfaceRequest<Application> request, | 28 InterfaceRequest<Application> request, |
27 scoped_refptr<base::TaskRunner> exit_task_runner, | 29 scoped_refptr<base::TaskRunner> exit_task_runner, |
28 const base::Closure& exit_callback, | 30 const base::Closure& exit_callback, |
29 const StaticApplicationLoader::ApplicationFactory& factory) | 31 const StaticApplicationLoader::ApplicationFactory& factory) |
30 : base::SimpleThread("Mojo Application: " + url.spec()), | 32 : base::SimpleThread("Mojo Application: " + url.spec()), |
31 request_(request.Pass()), | 33 request_(std::move(request)), |
32 exit_task_runner_(exit_task_runner), | 34 exit_task_runner_(exit_task_runner), |
33 exit_callback_(exit_callback), | 35 exit_callback_(exit_callback), |
34 factory_(factory) {} | 36 factory_(factory) {} |
35 | 37 |
36 void Run() override { | 38 void Run() override { |
37 scoped_ptr<ApplicationRunner> runner( | 39 scoped_ptr<ApplicationRunner> runner( |
38 new ApplicationRunner(factory_.Run().release())); | 40 new ApplicationRunner(factory_.Run().release())); |
39 runner->Run(request_.PassMessagePipe().release().value(), | 41 runner->Run(request_.PassMessagePipe().release().value(), |
40 false /* init_base */); | 42 false /* init_base */); |
41 exit_task_runner_->PostTask(FROM_HERE, exit_callback_); | 43 exit_task_runner_->PostTask(FROM_HERE, exit_callback_); |
(...skipping 29 matching lines...) Expand all Loading... |
71 void StaticApplicationLoader::Load(const GURL& url, | 73 void StaticApplicationLoader::Load(const GURL& url, |
72 InterfaceRequest<Application> request) { | 74 InterfaceRequest<Application> request) { |
73 if (thread_) | 75 if (thread_) |
74 return; | 76 return; |
75 | 77 |
76 // If the application's thread quits on its own before this loader dies, we | 78 // If the application's thread quits on its own before this loader dies, we |
77 // reset the Thread object, allowing future Load requests to be fulfilled | 79 // reset the Thread object, allowing future Load requests to be fulfilled |
78 // with a new app instance. | 80 // with a new app instance. |
79 auto exit_callback = base::Bind(&StaticApplicationLoader::StopAppThread, | 81 auto exit_callback = base::Bind(&StaticApplicationLoader::StopAppThread, |
80 weak_factory_.GetWeakPtr()); | 82 weak_factory_.GetWeakPtr()); |
81 thread_.reset( | 83 thread_.reset(new RunnerThread(url, std::move(request), |
82 new RunnerThread(url, request.Pass(), base::ThreadTaskRunnerHandle::Get(), | 84 base::ThreadTaskRunnerHandle::Get(), |
83 exit_callback, factory_)); | 85 exit_callback, factory_)); |
84 thread_->Start(); | 86 thread_->Start(); |
85 } | 87 } |
86 | 88 |
87 void StaticApplicationLoader::StopAppThread() { | 89 void StaticApplicationLoader::StopAppThread() { |
88 thread_->Join(); | 90 thread_->Join(); |
89 thread_.reset(); | 91 thread_.reset(); |
90 if (!quit_callback_.is_null()) | 92 if (!quit_callback_.is_null()) |
91 quit_callback_.Run(); | 93 quit_callback_.Run(); |
92 } | 94 } |
93 | 95 |
94 } // namespace shell | 96 } // namespace shell |
95 } // namespace mojo | 97 } // namespace mojo |
OLD | NEW |