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 "content/common/mojo/embedded_application_runner.h" | 5 #include "content/common/mojo/embedded_application_runner.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
45 | 45 |
46 DCHECK(application_task_runner_); | 46 DCHECK(application_task_runner_); |
47 application_task_runner_->PostTask( | 47 application_task_runner_->PostTask( |
48 FROM_HERE, | 48 FROM_HERE, |
49 base::Bind(&Instance::BindServiceRequestOnApplicationThread, this, | 49 base::Bind(&Instance::BindServiceRequestOnApplicationThread, this, |
50 base::Passed(&request))); | 50 base::Passed(&request))); |
51 } | 51 } |
52 | 52 |
53 void ShutDown() { | 53 void ShutDown() { |
54 DCHECK(runner_thread_checker_.CalledOnValidThread()); | 54 DCHECK(runner_thread_checker_.CalledOnValidThread()); |
55 // Any extant ServiceContexts must be destroyed on the correct thread. | |
Ken Rockot(use gerrit already)
2016/07/27 18:23:05
If application_task_runner_ is null, the app has a
kmackay
2016/07/27 18:51:59
Done.
| |
56 if (application_task_runner_) { | |
57 application_task_runner_->PostTask(FROM_HERE, | |
58 base::Bind(&Instance::Quit, this)); | |
59 } | |
55 if (thread_) { | 60 if (thread_) { |
Ken Rockot(use gerrit already)
2016/07/27 18:23:05
And you can just delete this block now
kmackay
2016/07/27 18:51:59
I wasn't sure if we wanted to make sure that the a
| |
56 thread_.reset(); | 61 thread_.reset(); |
57 application_task_runner_ = nullptr; | 62 application_task_runner_ = nullptr; |
58 } | 63 } |
59 } | 64 } |
60 | 65 |
61 private: | 66 private: |
62 void BindServiceRequestOnApplicationThread( | 67 void BindServiceRequestOnApplicationThread( |
63 shell::mojom::ServiceRequest request) { | 68 shell::mojom::ServiceRequest request) { |
64 DCHECK(application_task_runner_->BelongsToCurrentThread()); | 69 DCHECK(application_task_runner_->BelongsToCurrentThread()); |
65 | 70 |
(...skipping 29 matching lines...) Expand all Loading... | |
95 break; | 100 break; |
96 } | 101 } |
97 } | 102 } |
98 } | 103 } |
99 | 104 |
100 void Quit() { | 105 void Quit() { |
101 DCHECK(application_task_runner_->BelongsToCurrentThread()); | 106 DCHECK(application_task_runner_->BelongsToCurrentThread()); |
102 | 107 |
103 shell_connections_.clear(); | 108 shell_connections_.clear(); |
104 service_.reset(); | 109 service_.reset(); |
105 quit_task_runner_->PostTask( | 110 quit_task_runner_->PostTask( |
Ken Rockot(use gerrit already)
2016/07/27 18:23:05
Since you're here, mind also changing this to invo
kmackay
2016/07/27 18:51:59
Done.
| |
106 FROM_HERE, base::Bind(&Instance::QuitOnRunnerThread, this)); | 111 FROM_HERE, base::Bind(&Instance::QuitOnRunnerThread, this)); |
107 } | 112 } |
108 | 113 |
109 void QuitOnRunnerThread() { | 114 void QuitOnRunnerThread() { |
110 DCHECK(runner_thread_checker_.CalledOnValidThread()); | 115 DCHECK(runner_thread_checker_.CalledOnValidThread()); |
111 ShutDown(); | 116 if (thread_) { |
117 thread_.reset(); | |
118 application_task_runner_ = nullptr; | |
119 } | |
112 quit_closure_.Run(); | 120 quit_closure_.Run(); |
113 } | 121 } |
114 | 122 |
115 const std::string name_; | 123 const std::string name_; |
116 const MojoApplicationInfo::ApplicationFactory factory_callback_; | 124 const MojoApplicationInfo::ApplicationFactory factory_callback_; |
117 const bool use_own_thread_; | 125 const bool use_own_thread_; |
118 const base::Closure quit_closure_; | 126 const base::Closure quit_closure_; |
119 const scoped_refptr<base::SingleThreadTaskRunner> quit_task_runner_; | 127 const scoped_refptr<base::SingleThreadTaskRunner> quit_task_runner_; |
120 | 128 |
121 // Thread checker used to ensure certain operations happen only on the | 129 // Thread checker used to ensure certain operations happen only on the |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
157 const base::Closure& quit_closure) { | 165 const base::Closure& quit_closure) { |
158 quit_closure_ = quit_closure; | 166 quit_closure_ = quit_closure; |
159 } | 167 } |
160 | 168 |
161 void EmbeddedApplicationRunner::OnQuit() { | 169 void EmbeddedApplicationRunner::OnQuit() { |
162 if (!quit_closure_.is_null()) | 170 if (!quit_closure_.is_null()) |
163 quit_closure_.Run(); | 171 quit_closure_.Run(); |
164 } | 172 } |
165 | 173 |
166 } // namespace content | 174 } // namespace content |
OLD | NEW |