Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(125)

Side by Side Diff: shell/dynamic_application_loader.cc

Issue 829183005: Always use mojo_shell in over-http mode (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Fix pprof Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | sky/tools/debugger/prompt/prompt.cc » ('j') | sky/tools/debugger/prompt/prompt.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "base/format_macros.h" 11 #include "base/format_macros.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
16 #include "base/process/process.h"
16 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
17 #include "base/strings/stringprintf.h" 18 #include "base/strings/stringprintf.h"
18 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
19 #include "mojo/common/common_type_converters.h" 20 #include "mojo/common/common_type_converters.h"
20 #include "mojo/common/data_pipe_utils.h" 21 #include "mojo/common/data_pipe_utils.h"
21 #include "mojo/public/cpp/system/data_pipe.h" 22 #include "mojo/public/cpp/system/data_pipe.h"
22 #include "mojo/services/network/public/interfaces/url_loader.mojom.h" 23 #include "mojo/services/network/public/interfaces/url_loader.mojom.h"
23 #include "shell/context.h" 24 #include "shell/context.h"
24 #include "shell/data_pipe_peek.h" 25 #include "shell/data_pipe_peek.h"
25 #include "shell/filename_util.h" 26 #include "shell/filename_util.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 103
103 // TODO(aa): Sanity check that the thing we got looks vaguely like a mojo 104 // TODO(aa): Sanity check that the thing we got looks vaguely like a mojo
104 // application. That could either mean looking for the platform-specific dll 105 // application. That could either mean looking for the platform-specific dll
105 // header, or looking for some specific mojo signature prepended to the 106 // header, or looking for some specific mojo signature prepended to the
106 // library. 107 // library.
107 108
108 AsPath(context_->task_runners()->blocking_pool(), 109 AsPath(context_->task_runners()->blocking_pool(),
109 base::Bind(&Loader::RunLibrary, weak_ptr_factory_.GetWeakPtr())); 110 base::Bind(&Loader::RunLibrary, weak_ptr_factory_.GetWeakPtr()));
110 } 111 }
111 112
112 void ReportComplete() { loader_complete_callback_.Run(this); } 113 virtual void ReportComplete() { loader_complete_callback_.Run(this); }
113 114
114 private: 115 private:
115 bool PeekContentHandler(std::string* mojo_shebang, 116 bool PeekContentHandler(std::string* mojo_shebang,
116 GURL* mojo_content_handler_url) { 117 GURL* mojo_content_handler_url) {
117 std::string shebang; 118 std::string shebang;
118 if (HasMojoMagic() && PeekFirstLine(&shebang)) { 119 if (HasMojoMagic() && PeekFirstLine(&shebang)) {
119 GURL url(shebang.substr(arraysize(kMojoMagic) - 1, std::string::npos)); 120 GURL url(shebang.substr(arraysize(kMojoMagic) - 1, std::string::npos));
120 if (url.is_valid()) { 121 if (url.is_valid()) {
121 *mojo_shebang = shebang; 122 *mojo_shebang = shebang;
122 *mojo_content_handler_url = url; 123 *mojo_content_handler_url = url;
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 } 283 }
283 284
284 void AsPath( 285 void AsPath(
285 base::TaskRunner* task_runner, 286 base::TaskRunner* task_runner,
286 base::Callback<void(const base::FilePath&, bool)> callback) override { 287 base::Callback<void(const base::FilePath&, bool)> callback) override {
287 if (!path_.empty() || !response_) { 288 if (!path_.empty() || !response_) {
288 base::MessageLoop::current()->PostTask( 289 base::MessageLoop::current()->PostTask(
289 FROM_HERE, base::Bind(callback, path_, base::PathExists(path_))); 290 FROM_HERE, base::Bind(callback, path_, base::PathExists(path_)));
290 return; 291 return;
291 } 292 }
293 // We don't use the created file, just want the directory and random name.
292 base::CreateTemporaryFile(&path_); 294 base::CreateTemporaryFile(&path_);
293 // This is used to extract symbols on android. 295 base::DeleteFile(path_, false);
294 LOG(INFO) << "Caching mojo app " << url_ << " at " << path_.value(); 296 path_ = path_.AddExtension(".mojo"); // Make libraries easy to spot.
295 common::CopyToFile(response_->body.Pass(), path_, task_runner, 297 common::CopyToFile(response_->body.Pass(), path_, task_runner,
296 base::Bind(callback, path_)); 298 base::Bind(callback, path_));
299
300 // This is used to extract symbols on android.
301 // TODO(eseidel): All users of this log should move to using the map file.
302 LOG(INFO) << "Caching mojo app " << url_ << " at " << path_.value();
303
304 // Record the URL -> temp-file mapping for debugging tools.
305 base::FilePath temp_dir;
306 GetTempDir(&temp_dir);
307 base::ProcessId pid = base::Process::Current().pid();
308 std::string map_name = base::StringPrintf("mojo_shell.%d.maps", pid);
309 base::FilePath map_path = temp_dir.Append(map_name);
310
311 std::string map_entry = base::StringPrintf("%s %s\n",
312 path_.value().data(), url_.spec().data());
313 // TODO(eseidel): AppendToFile is missing O_CREAT, crbug.com/450696
314 if (!PathExists(map_path))
315 base::WriteFile(map_path, map_entry.data(), map_entry.length());
316 else
317 base::AppendToFile(map_path, map_entry.data(), map_entry.length());
297 } 318 }
298 319
299 std::string MimeType() override { 320 std::string MimeType() override {
300 DCHECK(response_); 321 DCHECK(response_);
301 return response_->mime_type; 322 return response_->mime_type;
302 } 323 }
303 324
304 bool HasMojoMagic() override { 325 bool HasMojoMagic() override {
305 std::string magic; 326 std::string magic;
306 return BlockingPeekNBytes(response_->body.get(), &magic, strlen(kMojoMagic), 327 return BlockingPeekNBytes(response_->body.get(), &magic, strlen(kMojoMagic),
(...skipping 27 matching lines...) Expand all
334 LOG(ERROR) << "Error (" << response->error->code << ": " 355 LOG(ERROR) << "Error (" << response->error->code << ": "
335 << response->error->description << ") while fetching " 356 << response->error->description << ") while fetching "
336 << response->url; 357 << response->url;
337 ReportComplete(); 358 ReportComplete();
338 return; 359 return;
339 } 360 }
340 response_ = response.Pass(); 361 response_ = response.Pass();
341 Load(); 362 Load();
342 } 363 }
343 364
365 void ReportComplete() override {
366 LOG(INFO) << "ReportComplete";
jamesr 2015/01/21 22:23:04 too spammy
eseidel 2015/01/21 22:44:42 Oops! Was a debug log. Thx!
367 Loader::ReportComplete();
jamesr 2015/01/21 22:23:04 relying on implementation inheritance here seems p
eseidel 2015/01/21 22:44:42 Oh? I just want to call super().
368 // As soon as we've loaded the library we can delete the tmp file.
369 // Tools can read the mojo_shell.PID.maps file to find the original library.
370 if (!path_.empty())
371 DeleteFile(path_, false);
372 }
373
374
344 const GURL url_; 375 const GURL url_;
345 URLLoaderPtr url_loader_; 376 URLLoaderPtr url_loader_;
346 URLResponsePtr response_; 377 URLResponsePtr response_;
347 base::FilePath path_; 378 base::FilePath path_;
348 base::WeakPtrFactory<NetworkLoader> weak_ptr_factory_; 379 base::WeakPtrFactory<NetworkLoader> weak_ptr_factory_;
349 380
350 DISALLOW_COPY_AND_ASSIGN(NetworkLoader); 381 DISALLOW_COPY_AND_ASSIGN(NetworkLoader);
351 }; 382 };
352 383
353 DynamicApplicationLoader::DynamicApplicationLoader( 384 DynamicApplicationLoader::DynamicApplicationLoader(
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 // TODO(darin): What should we do about service errors? This implies that 432 // TODO(darin): What should we do about service errors? This implies that
402 // the app closed its handle to the service manager. Maybe we don't care? 433 // the app closed its handle to the service manager. Maybe we don't care?
403 } 434 }
404 435
405 void DynamicApplicationLoader::LoaderComplete(Loader* loader) { 436 void DynamicApplicationLoader::LoaderComplete(Loader* loader) {
406 loaders_.erase(std::find(loaders_.begin(), loaders_.end(), loader)); 437 loaders_.erase(std::find(loaders_.begin(), loaders_.end(), loader));
407 } 438 }
408 439
409 } // namespace shell 440 } // namespace shell
410 } // namespace mojo 441 } // namespace mojo
OLDNEW
« no previous file with comments | « no previous file | sky/tools/debugger/prompt/prompt.cc » ('j') | sky/tools/debugger/prompt/prompt.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698