summaryrefslogtreecommitdiff
path: root/chromium/content/browser/android/tracing_intent_handler.cc
blob: 324f8055cc177623964a419b6e631b42ad0c02fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// 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/tracing_intent_handler.h"

#include "base/android/jni_android.h"
#include "base/android/jni_string.h"
#include "base/files/file_path.h"
#include "base/logging.h"
#include "content/public/browser/trace_controller.h"
#include "jni/TracingIntentHandler_jni.h"

namespace content {

TracingIntentHandler* g_trace_intent_handler = NULL;

TracingIntentHandler::TracingIntentHandler(const base::FilePath& path)
    : TraceSubscriberStdio(path, FILE_TYPE_ARRAY, false) {
  TraceController::GetInstance()->BeginTracing(
      this,
      std::string("-test*"),
      base::debug::TraceLog::RECORD_UNTIL_FULL);
}

TracingIntentHandler::~TracingIntentHandler() {
}

void TracingIntentHandler::OnEndTracingComplete() {
  TraceSubscriberStdio::OnEndTracingComplete();
  delete this;
}

void TracingIntentHandler::OnEndTracing() {
  if (!TraceController::GetInstance()->EndTracingAsync(this)) {
    delete this;
  }
}

static void BeginTracing(JNIEnv* env, jclass clazz, jstring jspath) {
  std::string path(base::android::ConvertJavaStringToUTF8(env, jspath));
  if (g_trace_intent_handler != NULL)
    return;
  g_trace_intent_handler = new TracingIntentHandler(base::FilePath(path));
}

static void EndTracing(JNIEnv* env, jclass clazz) {
  DCHECK(!g_trace_intent_handler);
  g_trace_intent_handler->OnEndTracing();
  g_trace_intent_handler = NULL;
}

bool RegisterTracingIntentHandler(JNIEnv* env) {
  return RegisterNativesImpl(env);
}

}  // namespace content