Remove PlatformFile from profile_browsertest
[chromium-blink-merge.git] / content / browser / android / tracing_controller_android.cc
blob75ac6d7c2385aaf4d7710990b9907b837683504e
1 // Copyright 2013 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.
5 #include "content/browser/android/tracing_controller_android.h"
7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h"
9 #include "base/debug/trace_event.h"
10 #include "base/logging.h"
11 #include "content/public/browser/tracing_controller.h"
12 #include "jni/TracingControllerAndroid_jni.h"
14 namespace content {
16 static jlong Init(JNIEnv* env, jobject obj) {
17 TracingControllerAndroid* profiler = new TracingControllerAndroid(env, obj);
18 return reinterpret_cast<intptr_t>(profiler);
21 TracingControllerAndroid::TracingControllerAndroid(JNIEnv* env, jobject obj)
22 : weak_java_object_(env, obj),
23 weak_factory_(this) {}
25 TracingControllerAndroid::~TracingControllerAndroid() {}
27 void TracingControllerAndroid::Destroy(JNIEnv* env, jobject obj) {
28 delete this;
31 bool TracingControllerAndroid::StartTracing(JNIEnv* env,
32 jobject obj,
33 jstring jfilename,
34 jstring jcategories,
35 jboolean record_continuously) {
36 file_path_ = base::FilePath(
37 base::android::ConvertJavaStringToUTF8(env, jfilename));
38 std::string categories =
39 base::android::ConvertJavaStringToUTF8(env, jcategories);
41 // This log is required by adb_profile_chrome.py.
42 LOG(WARNING) << "Logging performance trace to file: " << file_path_.value();
44 return TracingController::GetInstance()->EnableRecording(
45 categories,
46 record_continuously ? TracingController::RECORD_CONTINUOUSLY
47 : TracingController::DEFAULT_OPTIONS,
48 TracingController::EnableRecordingDoneCallback());
51 void TracingControllerAndroid::StopTracing(JNIEnv* env, jobject obj) {
52 if (!TracingController::GetInstance()->DisableRecording(
53 file_path_,
54 base::Bind(&TracingControllerAndroid::OnTracingStopped,
55 weak_factory_.GetWeakPtr()))) {
56 LOG(ERROR) << "EndTracingAsync failed, forcing an immediate stop";
57 OnTracingStopped(file_path_);
61 void TracingControllerAndroid::OnTracingStopped(
62 const base::FilePath& file_path) {
63 JNIEnv* env = base::android::AttachCurrentThread();
64 base::android::ScopedJavaLocalRef<jobject> obj = weak_java_object_.get(env);
65 if (obj.obj())
66 Java_TracingControllerAndroid_onTracingStopped(env, obj.obj());
69 static jstring GetDefaultCategories(JNIEnv* env, jobject obj) {
70 return base::android::ConvertUTF8ToJavaString(env,
71 base::debug::CategoryFilter::kDefaultCategoryFilterString).Release();
74 bool RegisterTracingControllerAndroid(JNIEnv* env) {
75 return RegisterNativesImpl(env);
78 } // namespace content