Home | History | Annotate | Download | only in android
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "content/browser/android/tracing_intent_handler.h"
      6 
      7 #include "base/android/jni_android.h"
      8 #include "base/android/jni_string.h"
      9 #include "base/files/file_path.h"
     10 #include "base/logging.h"
     11 #include "content/public/browser/trace_controller.h"
     12 #include "jni/TracingIntentHandler_jni.h"
     13 
     14 namespace content {
     15 
     16 TracingIntentHandler* g_trace_intent_handler = NULL;
     17 
     18 TracingIntentHandler::TracingIntentHandler(const base::FilePath& path)
     19     : TraceSubscriberStdio(path) {
     20   TraceController::GetInstance()->BeginTracing(
     21       this,
     22       std::string("-test*"),
     23       base::debug::TraceLog::RECORD_UNTIL_FULL);
     24 }
     25 
     26 TracingIntentHandler::~TracingIntentHandler() {
     27 }
     28 
     29 void TracingIntentHandler::OnEndTracingComplete() {
     30   TraceSubscriberStdio::OnEndTracingComplete();
     31   delete this;
     32 }
     33 
     34 void TracingIntentHandler::OnEndTracing() {
     35   if (!TraceController::GetInstance()->EndTracingAsync(this)) {
     36     delete this;
     37   }
     38 }
     39 
     40 static void BeginTracing(JNIEnv* env, jclass clazz, jstring jspath) {
     41   std::string path(base::android::ConvertJavaStringToUTF8(env, jspath));
     42   if (g_trace_intent_handler != NULL)
     43     return;
     44   g_trace_intent_handler = new TracingIntentHandler(base::FilePath(path));
     45 }
     46 
     47 static void EndTracing(JNIEnv* env, jclass clazz) {
     48   DCHECK(!g_trace_intent_handler);
     49   g_trace_intent_handler->OnEndTracing();
     50   g_trace_intent_handler = NULL;
     51 }
     52 
     53 bool RegisterTracingIntentHandler(JNIEnv* env) {
     54   return RegisterNativesImpl(env);
     55 }
     56 
     57 }  // namespace content
     58