OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/dynamic_application_loader.h" | 5 #include "mojo/shell/dynamic_application_loader.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "mojo/common/common_type_converters.h" | 13 #include "mojo/common/common_type_converters.h" |
14 #include "mojo/common/data_pipe_utils.h" | 14 #include "mojo/common/data_pipe_utils.h" |
15 #include "mojo/services/public/interfaces/network/url_loader.mojom.h" | 15 #include "mojo/services/public/interfaces/network/url_loader.mojom.h" |
16 #include "mojo/shell/context.h" | 16 #include "mojo/shell/context.h" |
17 #include "mojo/shell/keep_alive.h" | |
18 #include "mojo/shell/switches.h" | 17 #include "mojo/shell/switches.h" |
19 #include "net/base/filename_util.h" | 18 #include "net/base/filename_util.h" |
20 | 19 |
21 namespace mojo { | 20 namespace mojo { |
22 namespace shell { | 21 namespace shell { |
23 | 22 |
24 namespace { | |
25 | |
26 void RunLibraryComplete(DynamicServiceRunner* runner, | |
27 const base::FilePath& temp_file) { | |
28 delete runner; | |
29 if (!temp_file.empty()) | |
30 base::DeleteFile(temp_file, false); | |
31 } | |
32 | |
33 } // namespace | |
34 | |
35 DynamicApplicationLoader::DynamicApplicationLoader( | 23 DynamicApplicationLoader::DynamicApplicationLoader( |
36 Context* context, | 24 Context* context, |
37 scoped_ptr<DynamicServiceRunnerFactory> runner_factory) | 25 scoped_ptr<DynamicServiceRunnerFactory> runner_factory) |
38 : context_(context), | 26 : context_(context), |
39 runner_factory_(runner_factory.Pass()), | 27 runner_factory_(runner_factory.Pass()), |
40 weak_ptr_factory_(this) { | 28 weak_ptr_factory_(this) { |
41 } | 29 } |
42 | 30 |
43 DynamicApplicationLoader::~DynamicApplicationLoader() { | 31 DynamicApplicationLoader::~DynamicApplicationLoader() { |
44 } | 32 } |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
136 file, | 124 file, |
137 callbacks, | 125 callbacks, |
138 kDeleteFileAfter)); | 126 kDeleteFileAfter)); |
139 } | 127 } |
140 | 128 |
141 void DynamicApplicationLoader::RunLibrary( | 129 void DynamicApplicationLoader::RunLibrary( |
142 const base::FilePath& path, | 130 const base::FilePath& path, |
143 scoped_refptr<LoadCallbacks> callbacks, | 131 scoped_refptr<LoadCallbacks> callbacks, |
144 bool delete_file_after, | 132 bool delete_file_after, |
145 bool path_exists) { | 133 bool path_exists) { |
146 // TODO(aa): We need to create a runner, even if we're not going to use it, | 134 |
147 // because it getting destroyed is what causes shell to shut down. If we don't | 135 ScopedMessagePipeHandle shell_handle = callbacks->RegisterApplication(); |
148 // create this, in the case where shell never successfully creates even one | 136 if (!shell_handle.is_valid()) |
149 // app, then shell will never shut down, because no runners are ever | 137 return; |
150 // destroyed. | 138 |
151 scoped_ptr<DynamicServiceRunner> runner(runner_factory_->Create(context_)); | |
152 if (!path_exists) { | 139 if (!path_exists) { |
153 DVLOG(1) << "Library not started because library path '" | 140 DVLOG(1) << "Library not started because library path '" |
154 << path.value() << "' does not exist."; | 141 << path.value() << "' does not exist."; |
155 return; | 142 return; |
156 } | 143 } |
157 | 144 |
158 ScopedMessagePipeHandle shell_handle = callbacks->RegisterApplication(); | 145 scoped_ptr<DynamicServiceRunner> runner = |
159 if (!shell_handle.is_valid()) | 146 runner_factory_->Create(context_).Pass(); |
160 return; | 147 runner->Start(path, |
148 shell_handle.Pass(), | |
149 base::Bind(&DynamicApplicationLoader::RunLibraryComplete, | |
150 weak_ptr_factory_.GetWeakPtr(), | |
151 base::Unretained(runner.get()), | |
tim (not reviewing)
2014/08/23 00:14:27
Hm. So if I have this right, a DynamicServiceRunne
DaveMoore
2014/08/24 22:31:11
We could if we made TerminateShellConnections bloc
tim (not reviewing)
2014/08/25 16:56:47
Your patch makes it so we won't Quit the shell Mes
| |
152 delete_file_after ? path : base::FilePath())); | |
153 runners_.push_back(runner.release()); | |
154 } | |
161 | 155 |
162 DynamicServiceRunner* runner_raw = runner.release(); | 156 void DynamicApplicationLoader::RunLibraryComplete( |
163 runner_raw->Start(path, | 157 DynamicServiceRunner* runner, |
164 shell_handle.Pass(), | 158 const base::FilePath& temp_file) { |
165 base::Bind(&RunLibraryComplete, | 159 for (ScopedVector<DynamicServiceRunner>::iterator it = runners_.begin(); |
166 base::Unretained(runner_raw), | 160 it != runners_.end(); ++it) { |
167 delete_file_after ? path : base::FilePath())); | 161 if (*it == runner) { |
162 runners_.erase(it); | |
163 if (!temp_file.empty()) | |
164 base::DeleteFile(temp_file, false); | |
165 return; | |
166 } | |
167 } | |
168 } | 168 } |
169 | 169 |
170 void DynamicApplicationLoader::OnServiceError(ApplicationManager* manager, | 170 void DynamicApplicationLoader::OnServiceError(ApplicationManager* manager, |
171 const GURL& url) { | 171 const GURL& url) { |
172 // TODO(darin): What should we do about service errors? This implies that | 172 // TODO(darin): What should we do about service errors? This implies that |
173 // the app closed its handle to the service manager. Maybe we don't care? | 173 // the app closed its handle to the service manager. Maybe we don't care? |
174 } | 174 } |
175 | 175 |
176 } // namespace shell | 176 } // namespace shell |
177 } // namespace mojo | 177 } // namespace mojo |
OLD | NEW |