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

Unified Diff: content/browser/android/trace_event_binding.cc

Issue 10377059: Android content shell bringup. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix deps so builds on clean machine Created 8 years, 7 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 | « content/browser/android/trace_event_binding.h ('k') | content/content.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/android/trace_event_binding.cc
diff --git a/content/browser/android/trace_event_binding.cc b/content/browser/android/trace_event_binding.cc
new file mode 100644
index 0000000000000000000000000000000000000000..712994682cb7295ff23cb23001d39c88667ffc2f
--- /dev/null
+++ b/content/browser/android/trace_event_binding.cc
@@ -0,0 +1,93 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/android/trace_event_binding.h"
+
+#include <jni.h>
+
+#include <set>
+
+#include "base/debug/trace_event.h"
+#include "base/lazy_instance.h"
+#include "jni/trace_event_jni.h"
+
+namespace {
+
+const char kJavaCategory[] = "Java";
+
+// Boilerplate for safely converting Java data to TRACE_EVENT data.
+class TraceEventDataConverter {
+ public:
+ TraceEventDataConverter(JNIEnv* env,
+ jstring jname,
+ jstring jarg)
+ : env_(env),
+ jname_(jname),
+ jarg_(jarg),
+ name_(env->GetStringUTFChars(jname, NULL)),
+ arg_(jarg ? env->GetStringUTFChars(jarg, NULL) : NULL) {
+ }
+ ~TraceEventDataConverter() {
+ env_->ReleaseStringUTFChars(jname_, name_);
+ if (jarg_)
+ env_->ReleaseStringUTFChars(jarg_, arg_);
+ }
+
+ // Return saves values to pass to TRACE_EVENT macros.
+ const char* name() { return name_; }
+ const char* arg_name() { return arg_ ? "arg" : NULL; }
+ const char* arg() { return arg_; }
+
+ private:
+ JNIEnv* env_;
+ jstring jname_;
+ jstring jarg_;
+ const char* name_;
+ const char* arg_;
+
+ DISALLOW_COPY_AND_ASSIGN(TraceEventDataConverter);
+};
+
+} // namespace
+
+static jboolean TraceEnabled(JNIEnv* env, jclass clazz) {
+ return base::debug::TraceLog::GetInstance()->IsEnabled();
+}
+
+static void Instant(JNIEnv* env, jclass clazz,
+ jstring jname, jstring jarg) {
+ TraceEventDataConverter converter(env, jname, jarg);
+ if (converter.arg()) {
+ TRACE_EVENT_COPY_INSTANT1(kJavaCategory, converter.name(),
+ converter.arg_name(), converter.arg());
+ } else {
+ TRACE_EVENT_COPY_INSTANT0(kJavaCategory, converter.name());
+ }
+}
+
+static void Begin(JNIEnv* env, jclass clazz,
+ jstring jname, jstring jarg) {
+ TraceEventDataConverter converter(env, jname, jarg);
+ if (converter.arg()) {
+ TRACE_EVENT_COPY_BEGIN1(kJavaCategory, converter.name(),
+ converter.arg_name(), converter.arg());
+ } else {
+ TRACE_EVENT_COPY_BEGIN0(kJavaCategory, converter.name());
+ }
+}
+
+static void End(JNIEnv* env, jclass clazz,
+ jstring jname, jstring jarg) {
+ TraceEventDataConverter converter(env, jname, jarg);
+ if (converter.arg()) {
+ TRACE_EVENT_COPY_END1(kJavaCategory, converter.name(),
+ converter.arg_name(), converter.arg());
+ } else {
+ TRACE_EVENT_COPY_END0(kJavaCategory, converter.name());
+ }
+}
+
+bool RegisterTraceEvent(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
« no previous file with comments | « content/browser/android/trace_event_binding.h ('k') | content/content.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698