| 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/logging.h" | 10 #include "base/logging.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 weak_factory_(this) {} | 23 weak_factory_(this) {} |
| 24 | 24 |
| 25 TracingControllerAndroid::~TracingControllerAndroid() {} | 25 TracingControllerAndroid::~TracingControllerAndroid() {} |
| 26 | 26 |
| 27 void TracingControllerAndroid::Destroy(JNIEnv* env, jobject obj) { | 27 void TracingControllerAndroid::Destroy(JNIEnv* env, jobject obj) { |
| 28 delete this; | 28 delete this; |
| 29 } | 29 } |
| 30 | 30 |
| 31 bool TracingControllerAndroid::StartTracing(JNIEnv* env, | 31 bool TracingControllerAndroid::StartTracing(JNIEnv* env, |
| 32 jobject obj, | 32 jobject obj, |
| 33 jstring jfilename, | |
| 34 jstring jcategories, | 33 jstring jcategories, |
| 35 jboolean record_continuously) { | 34 jboolean record_continuously) { |
| 36 file_path_ = base::FilePath( | |
| 37 base::android::ConvertJavaStringToUTF8(env, jfilename)); | |
| 38 std::string categories = | 35 std::string categories = |
| 39 base::android::ConvertJavaStringToUTF8(env, jcategories); | 36 base::android::ConvertJavaStringToUTF8(env, jcategories); |
| 40 | 37 |
| 41 // This log is required by adb_profile_chrome.py. | 38 // This log is required by adb_profile_chrome.py. |
| 42 LOG(WARNING) << "Logging performance trace to file: " << file_path_.value(); | 39 LOG(WARNING) << "Logging performance trace to file"; |
| 43 | 40 |
| 44 return TracingController::GetInstance()->EnableRecording( | 41 return TracingController::GetInstance()->EnableRecording( |
| 45 categories, | 42 categories, |
| 46 record_continuously ? TracingController::RECORD_CONTINUOUSLY | 43 record_continuously ? TracingController::RECORD_CONTINUOUSLY |
| 47 : TracingController::DEFAULT_OPTIONS, | 44 : TracingController::DEFAULT_OPTIONS, |
| 48 TracingController::EnableRecordingDoneCallback()); | 45 TracingController::EnableRecordingDoneCallback()); |
| 49 } | 46 } |
| 50 | 47 |
| 51 void TracingControllerAndroid::StopTracing(JNIEnv* env, jobject obj) { | 48 void TracingControllerAndroid::StopTracing(JNIEnv* env, |
| 49 jobject obj, |
| 50 jstring jfilepath) { |
| 51 base::FilePath file_path( |
| 52 base::android::ConvertJavaStringToUTF8(env, jfilepath)); |
| 52 if (!TracingController::GetInstance()->DisableRecording( | 53 if (!TracingController::GetInstance()->DisableRecording( |
| 53 file_path_, | 54 file_path, |
| 54 base::Bind(&TracingControllerAndroid::OnTracingStopped, | 55 base::Bind(&TracingControllerAndroid::OnTracingStopped, |
| 55 weak_factory_.GetWeakPtr()))) { | 56 weak_factory_.GetWeakPtr()))) { |
| 56 LOG(ERROR) << "EndTracingAsync failed, forcing an immediate stop"; | 57 LOG(ERROR) << "EndTracingAsync failed, forcing an immediate stop"; |
| 57 OnTracingStopped(file_path_); | 58 OnTracingStopped(file_path); |
| 58 } | 59 } |
| 59 } | 60 } |
| 60 | 61 |
| 62 void TracingControllerAndroid::GenerateTracingFilePath( |
| 63 base::FilePath* file_path) { |
| 64 JNIEnv* env = base::android::AttachCurrentThread(); |
| 65 ScopedJavaLocalRef<jstring> jfilename = |
| 66 Java_TracingControllerAndroid_generateTracingFilePath(env); |
| 67 *file_path = base::FilePath( |
| 68 base::android::ConvertJavaStringToUTF8(env, jfilename.obj())); |
| 69 } |
| 70 |
| 61 void TracingControllerAndroid::OnTracingStopped( | 71 void TracingControllerAndroid::OnTracingStopped( |
| 62 const base::FilePath& file_path) { | 72 const base::FilePath& file_path) { |
| 63 JNIEnv* env = base::android::AttachCurrentThread(); | 73 JNIEnv* env = base::android::AttachCurrentThread(); |
| 64 base::android::ScopedJavaLocalRef<jobject> obj = weak_java_object_.get(env); | 74 base::android::ScopedJavaLocalRef<jobject> obj = weak_java_object_.get(env); |
| 65 if (obj.obj()) | 75 if (obj.obj()) |
| 66 Java_TracingControllerAndroid_onTracingStopped(env, obj.obj()); | 76 Java_TracingControllerAndroid_onTracingStopped(env, obj.obj()); |
| 67 } | 77 } |
| 68 | 78 |
| 69 static jstring GetDefaultCategories(JNIEnv* env, jobject obj) { | 79 static jstring GetDefaultCategories(JNIEnv* env, jobject obj) { |
| 70 return base::android::ConvertUTF8ToJavaString(env, | 80 return base::android::ConvertUTF8ToJavaString(env, |
| 71 base::debug::CategoryFilter::kDefaultCategoryFilterString).Release(); | 81 base::debug::CategoryFilter::kDefaultCategoryFilterString).Release(); |
| 72 } | 82 } |
| 73 | 83 |
| 74 bool RegisterTracingControllerAndroid(JNIEnv* env) { | 84 bool RegisterTracingControllerAndroid(JNIEnv* env) { |
| 75 return RegisterNativesImpl(env); | 85 return RegisterNativesImpl(env); |
| 76 } | 86 } |
| 77 | 87 |
| 78 } // namespace content | 88 } // namespace content |
| OLD | NEW |