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

Unified 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: Fixed per trung 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | sky/tools/debugger/prompt/prompt.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: shell/dynamic_application_loader.cc
diff --git a/shell/dynamic_application_loader.cc b/shell/dynamic_application_loader.cc
index e350b409dea92aff9168d654b726b6be3be3f4da..bd2b1bd199abe2cf9ab7217bcf9c26798168db4c 100644
--- a/shell/dynamic_application_loader.cc
+++ b/shell/dynamic_application_loader.cc
@@ -13,6 +13,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/message_loop/message_loop.h"
+#include "base/process/process.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
@@ -109,7 +110,7 @@ class DynamicApplicationLoader::Loader {
base::Bind(&Loader::RunLibrary, weak_ptr_factory_.GetWeakPtr()));
}
- void ReportComplete() { loader_complete_callback_.Run(this); }
+ virtual void ReportComplete() { loader_complete_callback_.Run(this); }
private:
bool PeekContentHandler(std::string* mojo_shebang,
@@ -281,6 +282,28 @@ class DynamicApplicationLoader::NetworkLoader : public Loader {
return response_.Pass();
}
+ static
viettrungluu 2015/01/21 23:32:50 nit: Probably the "canonical" way to format this w
+ void RecordCacheToURLMapping(const base::FilePath& path, const GURL& url) {
+ // This is used to extract symbols on android.
+ // TODO(eseidel): All users of this log should move to using the map file.
+ LOG(INFO) << "Caching mojo app " << url << " at " << path.value();
+
+ base::FilePath temp_dir;
+ base::GetTempDir(&temp_dir);
+ base::ProcessId pid = base::Process::Current().pid();
+ std::string map_name = base::StringPrintf("mojo_shell.%d.maps", pid);
+ base::FilePath map_path = temp_dir.Append(map_name);
+
+ // TODO(eseidel): Paths or URLs with spaces will need quoting.
+ std::string map_entry = base::StringPrintf("%s %s\n",
+ path.value().data(), url.spec().data());
+ // TODO(eseidel): AppendToFile is missing O_CREAT, crbug.com/450696
+ if (!PathExists(map_path))
+ base::WriteFile(map_path, map_entry.data(), map_entry.length());
+ else
+ base::AppendToFile(map_path, map_entry.data(), map_entry.length());
+ }
+
void AsPath(
base::TaskRunner* task_runner,
base::Callback<void(const base::FilePath&, bool)> callback) override {
@@ -289,11 +312,14 @@ class DynamicApplicationLoader::NetworkLoader : public Loader {
FROM_HERE, base::Bind(callback, path_, base::PathExists(path_)));
return;
}
+ // We don't use the created file, just want the directory and random name.
base::CreateTemporaryFile(&path_);
- // This is used to extract symbols on android.
- LOG(INFO) << "Caching mojo app " << url_ << " at " << path_.value();
+ base::DeleteFile(path_, false);
+ path_ = path_.AddExtension(".mojo"); // Make libraries easy to spot.
common::CopyToFile(response_->body.Pass(), path_, task_runner,
base::Bind(callback, path_));
+
+ RecordCacheToURLMapping(path_, url_);
}
std::string MimeType() override {
@@ -341,6 +367,14 @@ class DynamicApplicationLoader::NetworkLoader : public Loader {
Load();
}
+ void ReportComplete() override {
+ Loader::ReportComplete();
+ // As soon as we've loaded the library we can delete the cache file.
+ // Tools can read the mojo_shell.PID.maps file to find the original library.
+ if (!path_.empty())
+ DeleteFile(path_, false);
qsr 2015/01/22 16:29:07 I don't think this fix the issue with file leaks.
+ }
+
const GURL url_;
URLLoaderPtr url_loader_;
URLResponsePtr response_;
« no previous file with comments | « no previous file | sky/tools/debugger/prompt/prompt.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698