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

Unified Diff: mojo/services/tracing/public/cpp/tracing_impl.cc

Issue 1459453003: mandoline: write this after lunch. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add TracingImpls to mus and mash, fix naming. Created 5 years, 1 month 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 | « mojo/services/tracing/public/cpp/tracing_impl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/services/tracing/public/cpp/tracing_impl.cc
diff --git a/mojo/services/tracing/public/cpp/tracing_impl.cc b/mojo/services/tracing/public/cpp/tracing_impl.cc
index 788cd313ccd5fd872f964e32ef3975db11b84ab8..1cffe036d16ced3362bb767e527b71410ff80148 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());
« no previous file with comments | « mojo/services/tracing/public/cpp/tracing_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698