Chromium Code Reviews| 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 "shell/dynamic_application_loader.h" | 5 #include "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/files/file.h" | 9 #include "base/files/file.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
| 12 #include "base/format_macros.h" | 12 #include "base/format_macros.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/md5.h" | 14 #include "base/md5.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "base/message_loop/message_loop.h" | 17 #include "base/message_loop/message_loop.h" |
| 18 #include "base/process/process.h" | 18 #include "base/process/process.h" |
| 19 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
| 20 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
| 21 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
| 22 #include "mojo/common/common_type_converters.h" | 22 #include "mojo/common/common_type_converters.h" |
| 23 #include "mojo/common/data_pipe_utils.h" | 23 #include "mojo/common/data_pipe_utils.h" |
| 24 #include "mojo/public/cpp/system/data_pipe.h" | 24 #include "mojo/public/cpp/system/data_pipe.h" |
| 25 #include "mojo/services/network/public/interfaces/url_loader.mojom.h" | 25 #include "mojo/services/network/public/interfaces/url_loader.mojom.h" |
| 26 #include "shell/context.h" | 26 #include "shell/context.h" |
| 27 #include "shell/data_pipe_peek.h" | 27 #include "shell/data_pipe_peek.h" |
| 28 #include "shell/filename_util.h" | 28 #include "shell/filename_util.h" |
| 29 #if MOJO_USE_NACL | |
| 30 #include "shell/nacl/nacl_service_runner.h" | |
| 31 #endif | |
| 29 #include "shell/switches.h" | 32 #include "shell/switches.h" |
| 30 #include "url/url_util.h" | 33 #include "url/url_util.h" |
| 31 | 34 |
| 32 namespace mojo { | 35 namespace mojo { |
| 33 namespace shell { | 36 namespace shell { |
| 34 | 37 |
| 35 namespace { | 38 namespace { |
| 36 | 39 |
| 37 static const char kMojoMagic[] = "#!mojo "; | 40 static const char kMojoMagic[] = "#!mojo "; |
| 38 static const size_t kMaxShebangLength = 2048; | 41 static const size_t kMaxShebangLength = 2048; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 iter->second, application_request_.Pass(), | 106 iter->second, application_request_.Pass(), |
| 104 AsURLResponse(context_->task_runners()->blocking_pool(), 0)); | 107 AsURLResponse(context_->task_runners()->blocking_pool(), 0)); |
| 105 return; | 108 return; |
| 106 } | 109 } |
| 107 | 110 |
| 108 // TODO(aa): Sanity check that the thing we got looks vaguely like a mojo | 111 // TODO(aa): Sanity check that the thing we got looks vaguely like a mojo |
| 109 // application. That could either mean looking for the platform-specific dll | 112 // application. That could either mean looking for the platform-specific dll |
| 110 // header, or looking for some specific mojo signature prepended to the | 113 // header, or looking for some specific mojo signature prepended to the |
| 111 // library. | 114 // library. |
| 112 | 115 |
| 113 AsPath(context_->task_runners()->blocking_pool(), | 116 AsPath(context_->task_runners()->blocking_pool(), |
|
jamesr
2015/01/28 23:11:30
hmm, wouldn't it make more sense to check for .nex
Nick Bray (chromium)
2015/01/29 22:31:35
Done.
| |
| 114 base::Bind(&Loader::RunLibrary, weak_ptr_factory_.GetWeakPtr())); | 117 base::Bind(&Loader::RunLibrary, weak_ptr_factory_.GetWeakPtr())); |
| 115 } | 118 } |
| 116 | 119 |
| 117 void ReportComplete() { loader_complete_callback_.Run(this); } | 120 void ReportComplete() { loader_complete_callback_.Run(this); } |
| 118 | 121 |
| 119 private: | 122 private: |
| 120 bool PeekContentHandler(std::string* mojo_shebang, | 123 bool PeekContentHandler(std::string* mojo_shebang, |
| 121 GURL* mojo_content_handler_url) { | 124 GURL* mojo_content_handler_url) { |
| 122 std::string shebang; | 125 std::string shebang; |
| 123 if (HasMojoMagic() && PeekFirstLine(&shebang)) { | 126 if (HasMojoMagic() && PeekFirstLine(&shebang)) { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 134 void RunLibrary(const base::FilePath& path, bool path_exists) { | 137 void RunLibrary(const base::FilePath& path, bool path_exists) { |
| 135 DCHECK(application_request_.is_pending()); | 138 DCHECK(application_request_.is_pending()); |
| 136 | 139 |
| 137 if (!path_exists) { | 140 if (!path_exists) { |
| 138 LOG(ERROR) << "Library not started because library path '" << path.value() | 141 LOG(ERROR) << "Library not started because library path '" << path.value() |
| 139 << "' does not exist."; | 142 << "' does not exist."; |
| 140 ReportComplete(); | 143 ReportComplete(); |
| 141 return; | 144 return; |
| 142 } | 145 } |
| 143 | 146 |
| 144 runner_ = runner_factory_->Create(context_); | 147 // TODO(ncbray) sniff or infer the content type at a previous stage in the |
| 145 runner_->Start( | 148 // pipeline. |
| 146 path, cleanup_behavior_, application_request_.Pass(), | 149 if (path.Extension() == FILE_PATH_LITERAL(".nexe")) { |
| 147 base::Bind(&Loader::ReportComplete, weak_ptr_factory_.GetWeakPtr())); | 150 #if MOJO_USE_NACL |
| 151 nacl_runner_ = scoped_ptr<NaClServiceRunner>( | |
|
jamesr
2015/01/28 23:11:30
nacl_runner_.reset(new ....);
Nick Bray (chromium)
2015/01/29 22:31:34
Done.
| |
| 152 new NaClServiceRunner(context_)); | |
| 153 nacl_runner_->Start(path, application_request_.Pass()); | |
|
jamesr
2015/01/28 23:11:30
add a return; here and leave the last bit un-inden
Nick Bray (chromium)
2015/01/29 22:31:34
Done.
| |
| 154 #else | |
| 155 LOG(ERROR) << "Library not started because Native Client is not enabled."; | |
| 156 ReportComplete(); | |
|
jamesr
2015/01/28 23:11:30
return;
Nick Bray (chromium)
2015/01/29 22:31:34
Done.
| |
| 157 #endif | |
| 158 } else { | |
| 159 runner_ = runner_factory_->Create(context_); | |
| 160 runner_->Start( | |
| 161 path, cleanup_behavior_, application_request_.Pass(), | |
| 162 base::Bind(&Loader::ReportComplete, weak_ptr_factory_.GetWeakPtr())); | |
| 163 } | |
| 148 } | 164 } |
| 149 | 165 |
| 150 DynamicServiceRunner::CleanupBehavior cleanup_behavior_; | 166 DynamicServiceRunner::CleanupBehavior cleanup_behavior_; |
| 151 InterfaceRequest<Application> application_request_; | 167 InterfaceRequest<Application> application_request_; |
| 152 ApplicationLoader::LoadCallback load_callback_; | 168 ApplicationLoader::LoadCallback load_callback_; |
| 153 LoaderCompleteCallback loader_complete_callback_; | 169 LoaderCompleteCallback loader_complete_callback_; |
| 154 Context* context_; | 170 Context* context_; |
| 155 MimeTypeToURLMap* mime_type_to_url_; | 171 MimeTypeToURLMap* mime_type_to_url_; |
| 156 DynamicServiceRunnerFactory* runner_factory_; | 172 DynamicServiceRunnerFactory* runner_factory_; |
| 157 scoped_ptr<DynamicServiceRunner> runner_; | 173 scoped_ptr<DynamicServiceRunner> runner_; |
| 174 #if MOJO_USE_NACL | |
| 175 scoped_ptr<NaClServiceRunner> nacl_runner_; | |
| 176 #endif | |
| 158 base::WeakPtrFactory<Loader> weak_ptr_factory_; | 177 base::WeakPtrFactory<Loader> weak_ptr_factory_; |
| 159 }; | 178 }; |
| 160 | 179 |
| 161 // A loader for local files. | 180 // A loader for local files. |
| 162 class DynamicApplicationLoader::LocalLoader : public Loader { | 181 class DynamicApplicationLoader::LocalLoader : public Loader { |
| 163 public: | 182 public: |
| 164 LocalLoader(const GURL& url, | 183 LocalLoader(const GURL& url, |
| 165 MimeTypeToURLMap* mime_type_to_url, | 184 MimeTypeToURLMap* mime_type_to_url, |
| 166 Context* context, | 185 Context* context, |
| 167 DynamicServiceRunnerFactory* runner_factory, | 186 DynamicServiceRunnerFactory* runner_factory, |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 494 // TODO(darin): What should we do about service errors? This implies that | 513 // TODO(darin): What should we do about service errors? This implies that |
| 495 // the app closed its handle to the service manager. Maybe we don't care? | 514 // the app closed its handle to the service manager. Maybe we don't care? |
| 496 } | 515 } |
| 497 | 516 |
| 498 void DynamicApplicationLoader::LoaderComplete(Loader* loader) { | 517 void DynamicApplicationLoader::LoaderComplete(Loader* loader) { |
| 499 loaders_.erase(std::find(loaders_.begin(), loaders_.end(), loader)); | 518 loaders_.erase(std::find(loaders_.begin(), loaders_.end(), loader)); |
| 500 } | 519 } |
| 501 | 520 |
| 502 } // namespace shell | 521 } // namespace shell |
| 503 } // namespace mojo | 522 } // namespace mojo |
| OLD | NEW |