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_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 74 virtual void AsPath( | 74 virtual void AsPath( |
| 75 base::TaskRunner* task_runner, | 75 base::TaskRunner* task_runner, |
| 76 base::Callback<void(const base::FilePath&, bool)> callback) = 0; | 76 base::Callback<void(const base::FilePath&, bool)> callback) = 0; |
| 77 | 77 |
| 78 virtual std::string MimeType() = 0; | 78 virtual std::string MimeType() = 0; |
| 79 | 79 |
| 80 virtual bool HasMojoMagic() = 0; | 80 virtual bool HasMojoMagic() = 0; |
| 81 | 81 |
| 82 virtual bool PeekFirstLine(std::string* line) = 0; | 82 virtual bool PeekFirstLine(std::string* line) = 0; |
| 83 | 83 |
| 84 virtual bool CleanPath() = 0; | |
|
Aaron Boodman
2015/01/22 19:51:30
This doesn't appear to ever be answered based on r
qsr
2015/01/26 09:12:13
Done.
| |
| 85 | |
| 84 void Load() { | 86 void Load() { |
| 85 // If the response begins with a #!mojo <content-handler-url>, use it. | 87 // If the response begins with a #!mojo <content-handler-url>, use it. |
| 86 GURL url; | 88 GURL url; |
| 87 std::string shebang; | 89 std::string shebang; |
| 88 if (PeekContentHandler(&shebang, &url)) { | 90 if (PeekContentHandler(&shebang, &url)) { |
| 89 load_callback_.Run( | 91 load_callback_.Run( |
| 90 url, shell_handle_.Pass(), | 92 url, shell_handle_.Pass(), |
| 91 AsURLResponse(context_->task_runners()->blocking_pool(), | 93 AsURLResponse(context_->task_runners()->blocking_pool(), |
| 92 static_cast<int>(shebang.size()))); | 94 static_cast<int>(shebang.size()))); |
| 93 return; | 95 return; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 | 134 |
| 133 if (!path_exists) { | 135 if (!path_exists) { |
| 134 LOG(ERROR) << "Library not started because library path '" << path.value() | 136 LOG(ERROR) << "Library not started because library path '" << path.value() |
| 135 << "' does not exist."; | 137 << "' does not exist."; |
| 136 ReportComplete(); | 138 ReportComplete(); |
| 137 return; | 139 return; |
| 138 } | 140 } |
| 139 | 141 |
| 140 runner_ = runner_factory_->Create(context_); | 142 runner_ = runner_factory_->Create(context_); |
| 141 runner_->Start( | 143 runner_->Start( |
| 142 path, shell_handle_.Pass(), | 144 path, CleanPath(), shell_handle_.Pass(), |
| 143 base::Bind(&Loader::ReportComplete, weak_ptr_factory_.GetWeakPtr())); | 145 base::Bind(&Loader::ReportComplete, weak_ptr_factory_.GetWeakPtr())); |
| 144 } | 146 } |
| 145 | 147 |
| 146 ScopedMessagePipeHandle shell_handle_; | 148 ScopedMessagePipeHandle shell_handle_; |
| 147 ApplicationLoader::LoadCallback load_callback_; | 149 ApplicationLoader::LoadCallback load_callback_; |
| 148 LoaderCompleteCallback loader_complete_callback_; | 150 LoaderCompleteCallback loader_complete_callback_; |
| 149 Context* context_; | 151 Context* context_; |
| 150 MimeTypeToURLMap* mime_type_to_url_; | 152 MimeTypeToURLMap* mime_type_to_url_; |
| 151 DynamicServiceRunnerFactory* runner_factory_; | 153 DynamicServiceRunnerFactory* runner_factory_; |
| 152 scoped_ptr<DynamicServiceRunner> runner_; | 154 scoped_ptr<DynamicServiceRunner> runner_; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 227 bool PeekFirstLine(std::string* line) override { | 229 bool PeekFirstLine(std::string* line) override { |
| 228 std::string start_of_file; | 230 std::string start_of_file; |
| 229 ReadFileToString(path_, &start_of_file, kMaxShebangLength); | 231 ReadFileToString(path_, &start_of_file, kMaxShebangLength); |
| 230 size_t return_position = start_of_file.find('\n'); | 232 size_t return_position = start_of_file.find('\n'); |
| 231 if (return_position == std::string::npos) | 233 if (return_position == std::string::npos) |
| 232 return false; | 234 return false; |
| 233 *line = start_of_file.substr(0, return_position + 1); | 235 *line = start_of_file.substr(0, return_position + 1); |
| 234 return true; | 236 return true; |
| 235 } | 237 } |
| 236 | 238 |
| 239 bool CleanPath() override { return false; } | |
| 240 | |
| 237 GURL url_; | 241 GURL url_; |
| 238 base::FilePath path_; | 242 base::FilePath path_; |
| 239 | 243 |
| 240 DISALLOW_COPY_AND_ASSIGN(LocalLoader); | 244 DISALLOW_COPY_AND_ASSIGN(LocalLoader); |
| 241 }; | 245 }; |
| 242 | 246 |
| 243 // A loader for network files. | 247 // A loader for network files. |
| 244 class DynamicApplicationLoader::NetworkLoader : public Loader { | 248 class DynamicApplicationLoader::NetworkLoader : public Loader { |
| 245 public: | 249 public: |
| 246 NetworkLoader(const GURL& url, | 250 NetworkLoader(const GURL& url, |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 332 return BlockingPeekNBytes(response_->body.get(), &magic, strlen(kMojoMagic), | 336 return BlockingPeekNBytes(response_->body.get(), &magic, strlen(kMojoMagic), |
| 333 kPeekTimeout) && | 337 kPeekTimeout) && |
| 334 magic == kMojoMagic; | 338 magic == kMojoMagic; |
| 335 } | 339 } |
| 336 | 340 |
| 337 bool PeekFirstLine(std::string* line) override { | 341 bool PeekFirstLine(std::string* line) override { |
| 338 return BlockingPeekLine(response_->body.get(), line, kMaxShebangLength, | 342 return BlockingPeekLine(response_->body.get(), line, kMaxShebangLength, |
| 339 kPeekTimeout); | 343 kPeekTimeout); |
| 340 } | 344 } |
| 341 | 345 |
| 346 bool CleanPath() override { return true; } | |
| 347 | |
| 342 void StartNetworkRequest(const GURL& url, NetworkService* network_service) { | 348 void StartNetworkRequest(const GURL& url, NetworkService* network_service) { |
| 343 URLRequestPtr request(URLRequest::New()); | 349 URLRequestPtr request(URLRequest::New()); |
| 344 request->url = String::From(url); | 350 request->url = String::From(url); |
| 345 request->auto_follow_redirects = true; | 351 request->auto_follow_redirects = true; |
| 346 | 352 |
| 347 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 353 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 348 switches::kDisableCache)) { | 354 switches::kDisableCache)) { |
| 349 request->bypass_cache = true; | 355 request->bypass_cache = true; |
| 350 } | 356 } |
| 351 | 357 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 435 // TODO(darin): What should we do about service errors? This implies that | 441 // TODO(darin): What should we do about service errors? This implies that |
| 436 // the app closed its handle to the service manager. Maybe we don't care? | 442 // the app closed its handle to the service manager. Maybe we don't care? |
| 437 } | 443 } |
| 438 | 444 |
| 439 void DynamicApplicationLoader::LoaderComplete(Loader* loader) { | 445 void DynamicApplicationLoader::LoaderComplete(Loader* loader) { |
| 440 loaders_.erase(std::find(loaders_.begin(), loaders_.end(), loader)); | 446 loaders_.erase(std::find(loaders_.begin(), loaders_.end(), loader)); |
| 441 } | 447 } |
| 442 | 448 |
| 443 } // namespace shell | 449 } // namespace shell |
| 444 } // namespace mojo | 450 } // namespace mojo |
| OLD | NEW |