summaryrefslogtreecommitdiffstats
path: root/mojo
diff options
context:
space:
mode:
authorerg <erg@chromium.org>2015-11-18 14:46:57 -0800
committerCommit bot <commit-bot@chromium.org>2015-11-18 22:47:32 +0000
commit8d23e41bbc4bdeebffe51784d483afb95f4be714 (patch)
tree79654466331b4d22b57285c76e3271651951049e /mojo
parentb4a8cf7a82ae168ea915d44f5997a7e756eca6c6 (diff)
downloadchromium_src-8d23e41bbc4bdeebffe51784d483afb95f4be714.zip
chromium_src-8d23e41bbc4bdeebffe51784d483afb95f4be714.tar.gz
chromium_src-8d23e41bbc4bdeebffe51784d483afb95f4be714.tar.bz2
mojo_runner: Get --trace-start working with generic mojo_runner.
Android didn't like our magic to automatically include a connection to mojo:tracing in ApplicationImpl. This does things the explicit way: including a mojo:TracingImpl in each and every mojo application package. BUG=534895 Review URL: https://codereview.chromium.org/1459453003 Cr-Commit-Position: refs/heads/master@{#360434}
Diffstat (limited to 'mojo')
-rw-r--r--mojo/runner/desktop/launcher_process.cc3
-rw-r--r--mojo/services/network/BUILD.gn1
-rw-r--r--mojo/services/network/network_service_delegate.cc1
-rw-r--r--mojo/services/network/network_service_delegate.h2
-rw-r--r--mojo/services/tracing/public/cpp/tracing_impl.cc30
-rw-r--r--mojo/services/tracing/public/cpp/tracing_impl.h10
6 files changed, 47 insertions, 0 deletions
diff --git a/mojo/runner/desktop/launcher_process.cc b/mojo/runner/desktop/launcher_process.cc
index 4fa6956..b55953c 100644
--- a/mojo/runner/desktop/launcher_process.cc
+++ b/mojo/runner/desktop/launcher_process.cc
@@ -15,6 +15,7 @@
#include "base/message_loop/message_loop.h"
#include "base/path_service.h"
#include "base/synchronization/waitable_event.h"
+#include "base/threading/platform_thread.h"
#include "mojo/runner/context.h"
#include "mojo/runner/switches.h"
#include "mojo/shell/switches.h"
@@ -31,6 +32,8 @@ int LauncherProcessMain(const GURL& mojo_url, const base::Closure& callback) {
// http://crbug.com/546644
command_line->AppendSwitch(switches::kMojoNoSandbox);
+ base::PlatformThread::SetName("mojo_runner");
+
// We want the shell::Context to outlive the MessageLoop so that pipes are
// all gracefully closed / error-out before we try to shut the Context down.
Context shell_context;
diff --git a/mojo/services/network/BUILD.gn b/mojo/services/network/BUILD.gn
index 6b20a9b..76d6bdc 100644
--- a/mojo/services/network/BUILD.gn
+++ b/mojo/services/network/BUILD.gn
@@ -100,6 +100,7 @@ source_set("lib") {
"//mojo/public/cpp/system:system",
"//mojo/services/network/public/cpp",
"//mojo/services/network/public/interfaces",
+ "//mojo/services/tracing/public/cpp",
"//net",
"//net:extras",
"//net:http_server",
diff --git a/mojo/services/network/network_service_delegate.cc b/mojo/services/network/network_service_delegate.cc
index 14e642b..0a43964 100644
--- a/mojo/services/network/network_service_delegate.cc
+++ b/mojo/services/network/network_service_delegate.cc
@@ -129,6 +129,7 @@ void NetworkServiceDelegate::Initialize(ApplicationImpl* app) {
worker_thread = io_worker_thread_->task_runner();
#endif
context_.reset(new NetworkContext(base_path, worker_thread, this));
+ tracing_.Initialize(app);
}
bool NetworkServiceDelegate::ConfigureIncomingConnection(
diff --git a/mojo/services/network/network_service_delegate.h b/mojo/services/network/network_service_delegate.h
index 216f961..16b2f96 100644
--- a/mojo/services/network/network_service_delegate.h
+++ b/mojo/services/network/network_service_delegate.h
@@ -16,6 +16,7 @@
#include "mojo/services/network/public/interfaces/network_service.mojom.h"
#include "mojo/services/network/public/interfaces/url_loader_factory.mojom.h"
#include "mojo/services/network/public/interfaces/web_socket_factory.mojom.h"
+#include "mojo/services/tracing/public/cpp/tracing_impl.h"
namespace sql {
class ScopedMojoFilesystemVFS;
@@ -69,6 +70,7 @@ class NetworkServiceDelegate : public ApplicationDelegate,
private:
ApplicationImpl* app_;
+ mojo::TracingImpl tracing_;
// Observers that want notifications that our worker thread is going away.
base::ObserverList<NetworkServiceDelegateObserver> observers_;
diff --git a/mojo/services/tracing/public/cpp/tracing_impl.cc b/mojo/services/tracing/public/cpp/tracing_impl.cc
index 788cd31..1cffe03 100644
--- a/mojo/services/tracing/public/cpp/tracing_impl.cc
+++ b/mojo/services/tracing/public/cpp/tracing_impl.cc
@@ -4,6 +4,9 @@
#include "mojo/services/tracing/public/cpp/tracing_impl.h"
+#include "base/lazy_instance.h"
+#include "base/synchronization/lock.h"
+#include "base/threading/platform_thread.h"
#include "base/trace_event/trace_event_impl.h"
#include "mojo/application/public/cpp/application_impl.h"
@@ -13,6 +16,22 @@
#endif
namespace mojo {
+namespace {
+
+// Controls access to |g_tracing_singleton_created|, which can be accessed from
+// different threads.
+base::LazyInstance<base::Lock>::Leaky g_singleton_lock =
+ LAZY_INSTANCE_INITIALIZER;
+
+// Whether we are the first TracingImpl to be created in this mojo
+// application. The first TracingImpl in a physical mojo application connects
+// to the mojo:tracing service.
+//
+// If this is a ContentHandler, it will outlive all its served Applications. If
+// this is a raw mojo application, it is the only Application served.
+bool g_tracing_singleton_created = false;
+
+}
TracingImpl::TracingImpl() {
}
@@ -21,6 +40,17 @@ TracingImpl::~TracingImpl() {
}
void TracingImpl::Initialize(ApplicationImpl* app) {
+ {
+ base::AutoLock lock(g_singleton_lock.Get());
+ if (g_tracing_singleton_created)
+ return;
+ g_tracing_singleton_created = true;
+ }
+
+ // This will only set the name for the first app in a loaded mojo file. It's
+ // up to something like CoreServices to name its own child threads.
+ base::PlatformThread::SetName(app->url());
+
mojo::URLRequestPtr request(mojo::URLRequest::New());
request->url = mojo::String::From("mojo:tracing");
connection_ = app->ConnectToApplication(request.Pass());
diff --git a/mojo/services/tracing/public/cpp/tracing_impl.h b/mojo/services/tracing/public/cpp/tracing_impl.h
index 648023f..b832ef49 100644
--- a/mojo/services/tracing/public/cpp/tracing_impl.h
+++ b/mojo/services/tracing/public/cpp/tracing_impl.h
@@ -15,6 +15,16 @@ namespace mojo {
class ApplicationConnection;
class ApplicationImpl;
+// Connects to mojo:tracing during your Application's Initialize() call once
+// per process.
+//
+// We need to deal with multiple ways of packaging mojo applications
+// together. We'll need to deal with packages that use the mojo.ContentHandler
+// interface to bundle several Applciations into a single physical on disk
+// mojo binary, and with those same services each in their own mojo binary.
+//
+// Have your bundle ContentHandler own a TracingImpl, and each Application own
+// a TracingImpl. In bundles, the second TracingImpl will be a no-op.
class TracingImpl : public InterfaceFactory<tracing::TraceProvider> {
public:
TracingImpl();