| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/android/tracing_controller_android.h" | 5 #include "content/browser/android/tracing_controller_android.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
| 9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "content/public/browser/tracing_controller.h" | 12 #include "content/browser/tracing/tracing_controller_impl.h" |
| 13 #include "jni/TracingControllerAndroid_jni.h" | 13 #include "jni/TracingControllerAndroid_jni.h" |
| 14 | 14 |
| 15 namespace content { | 15 namespace content { |
| 16 | 16 |
| 17 static jlong Init(JNIEnv* env, jobject obj) { | 17 static jlong Init(JNIEnv* env, jobject obj) { |
| 18 TracingControllerAndroid* profiler = new TracingControllerAndroid(env, obj); | 18 TracingControllerAndroid* profiler = new TracingControllerAndroid(env, obj); |
| 19 return reinterpret_cast<intptr_t>(profiler); | 19 return reinterpret_cast<intptr_t>(profiler); |
| 20 } | 20 } |
| 21 | 21 |
| 22 TracingControllerAndroid::TracingControllerAndroid(JNIEnv* env, jobject obj) | 22 TracingControllerAndroid::TracingControllerAndroid(JNIEnv* env, jobject obj) |
| (...skipping 24 matching lines...) Expand all Loading... |
| 47 trace_options, | 47 trace_options, |
| 48 TracingController::EnableRecordingDoneCallback()); | 48 TracingController::EnableRecordingDoneCallback()); |
| 49 } | 49 } |
| 50 | 50 |
| 51 void TracingControllerAndroid::StopTracing(JNIEnv* env, | 51 void TracingControllerAndroid::StopTracing(JNIEnv* env, |
| 52 jobject obj, | 52 jobject obj, |
| 53 jstring jfilepath) { | 53 jstring jfilepath) { |
| 54 base::FilePath file_path( | 54 base::FilePath file_path( |
| 55 base::android::ConvertJavaStringToUTF8(env, jfilepath)); | 55 base::android::ConvertJavaStringToUTF8(env, jfilepath)); |
| 56 if (!TracingController::GetInstance()->DisableRecording( | 56 if (!TracingController::GetInstance()->DisableRecording( |
| 57 file_path, | 57 TracingControllerImpl::CreateFileSink(file_path, |
| 58 base::Bind(&TracingControllerAndroid::OnTracingStopped, | 58 base::Bind(&TracingControllerAndroid::OnTracingStopped, |
| 59 weak_factory_.GetWeakPtr()))) { | 59 weak_factory_.GetWeakPtr())))) { |
| 60 LOG(ERROR) << "EndTracingAsync failed, forcing an immediate stop"; | 60 LOG(ERROR) << "EndTracingAsync failed, forcing an immediate stop"; |
| 61 OnTracingStopped(file_path); | 61 OnTracingStopped(); |
| 62 } | 62 } |
| 63 } | 63 } |
| 64 | 64 |
| 65 void TracingControllerAndroid::GenerateTracingFilePath( | 65 void TracingControllerAndroid::GenerateTracingFilePath( |
| 66 base::FilePath* file_path) { | 66 base::FilePath* file_path) { |
| 67 JNIEnv* env = base::android::AttachCurrentThread(); | 67 JNIEnv* env = base::android::AttachCurrentThread(); |
| 68 ScopedJavaLocalRef<jstring> jfilename = | 68 ScopedJavaLocalRef<jstring> jfilename = |
| 69 Java_TracingControllerAndroid_generateTracingFilePath(env); | 69 Java_TracingControllerAndroid_generateTracingFilePath(env); |
| 70 *file_path = base::FilePath( | 70 *file_path = base::FilePath( |
| 71 base::android::ConvertJavaStringToUTF8(env, jfilename.obj())); | 71 base::android::ConvertJavaStringToUTF8(env, jfilename.obj())); |
| 72 } | 72 } |
| 73 | 73 |
| 74 void TracingControllerAndroid::OnTracingStopped( | 74 void TracingControllerAndroid::OnTracingStopped() { |
| 75 const base::FilePath& file_path) { | |
| 76 JNIEnv* env = base::android::AttachCurrentThread(); | 75 JNIEnv* env = base::android::AttachCurrentThread(); |
| 77 base::android::ScopedJavaLocalRef<jobject> obj = weak_java_object_.get(env); | 76 base::android::ScopedJavaLocalRef<jobject> obj = weak_java_object_.get(env); |
| 78 if (obj.obj()) | 77 if (obj.obj()) |
| 79 Java_TracingControllerAndroid_onTracingStopped(env, obj.obj()); | 78 Java_TracingControllerAndroid_onTracingStopped(env, obj.obj()); |
| 80 } | 79 } |
| 81 | 80 |
| 82 bool TracingControllerAndroid::GetKnownCategoryGroupsAsync(JNIEnv* env, | 81 bool TracingControllerAndroid::GetKnownCategoryGroupsAsync(JNIEnv* env, |
| 83 jobject obj) { | 82 jobject obj) { |
| 84 if (!TracingController::GetInstance()->GetCategories( | 83 if (!TracingController::GetInstance()->GetCategories( |
| 85 base::Bind(&TracingControllerAndroid::OnKnownCategoriesReceived, | 84 base::Bind(&TracingControllerAndroid::OnKnownCategoriesReceived, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 107 static jstring GetDefaultCategories(JNIEnv* env, jobject obj) { | 106 static jstring GetDefaultCategories(JNIEnv* env, jobject obj) { |
| 108 return base::android::ConvertUTF8ToJavaString(env, | 107 return base::android::ConvertUTF8ToJavaString(env, |
| 109 base::debug::CategoryFilter::kDefaultCategoryFilterString).Release(); | 108 base::debug::CategoryFilter::kDefaultCategoryFilterString).Release(); |
| 110 } | 109 } |
| 111 | 110 |
| 112 bool RegisterTracingControllerAndroid(JNIEnv* env) { | 111 bool RegisterTracingControllerAndroid(JNIEnv* env) { |
| 113 return RegisterNativesImpl(env); | 112 return RegisterNativesImpl(env); |
| 114 } | 113 } |
| 115 | 114 |
| 116 } // namespace content | 115 } // namespace content |
| OLD | NEW |