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/logging.h" | 11 #include "base/logging.h" |
11 #include "content/public/browser/tracing_controller.h" | 12 #include "content/public/browser/tracing_controller.h" |
12 #include "jni/TracingControllerAndroid_jni.h" | 13 #include "jni/TracingControllerAndroid_jni.h" |
13 | 14 |
14 namespace content { | 15 namespace content { |
15 | 16 |
16 static jlong Init(JNIEnv* env, jobject obj) { | 17 static jlong Init(JNIEnv* env, jobject obj) { |
17 TracingControllerAndroid* profiler = new TracingControllerAndroid(env, obj); | 18 TracingControllerAndroid* profiler = new TracingControllerAndroid(env, obj); |
18 return reinterpret_cast<intptr_t>(profiler); | 19 return reinterpret_cast<intptr_t>(profiler); |
19 } | 20 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 } | 70 } |
70 | 71 |
71 void TracingControllerAndroid::OnTracingStopped( | 72 void TracingControllerAndroid::OnTracingStopped( |
72 const base::FilePath& file_path) { | 73 const base::FilePath& file_path) { |
73 JNIEnv* env = base::android::AttachCurrentThread(); | 74 JNIEnv* env = base::android::AttachCurrentThread(); |
74 base::android::ScopedJavaLocalRef<jobject> obj = weak_java_object_.get(env); | 75 base::android::ScopedJavaLocalRef<jobject> obj = weak_java_object_.get(env); |
75 if (obj.obj()) | 76 if (obj.obj()) |
76 Java_TracingControllerAndroid_onTracingStopped(env, obj.obj()); | 77 Java_TracingControllerAndroid_onTracingStopped(env, obj.obj()); |
77 } | 78 } |
78 | 79 |
| 80 bool TracingControllerAndroid::GetKnownCategoryGroupsAsync(JNIEnv* env, |
| 81 jobject obj) { |
| 82 if (!TracingController::GetInstance()->GetCategories( |
| 83 base::Bind(&TracingControllerAndroid::OnKnownCategoriesReceived, |
| 84 weak_factory_.GetWeakPtr()))) { |
| 85 return false; |
| 86 } |
| 87 return true; |
| 88 } |
| 89 |
| 90 void TracingControllerAndroid::OnKnownCategoriesReceived( |
| 91 const std::set<std::string>& categories_received) { |
| 92 scoped_ptr<base::ListValue> category_list(new base::ListValue()); |
| 93 for (std::set<std::string>::const_iterator it = categories_received.begin(); |
| 94 it != categories_received.end(); |
| 95 ++it) { |
| 96 category_list->AppendString(*it); |
| 97 } |
| 98 std::string received_category_list; |
| 99 base::JSONWriter::Write(category_list.get(), &received_category_list); |
| 100 |
| 101 // This log is required by adb_profile_chrome.py. |
| 102 LOG(WARNING) << "{\"traceCategoriesList\": " << received_category_list << "}"; |
| 103 } |
| 104 |
79 static jstring GetDefaultCategories(JNIEnv* env, jobject obj) { | 105 static jstring GetDefaultCategories(JNIEnv* env, jobject obj) { |
80 return base::android::ConvertUTF8ToJavaString(env, | 106 return base::android::ConvertUTF8ToJavaString(env, |
81 base::debug::CategoryFilter::kDefaultCategoryFilterString).Release(); | 107 base::debug::CategoryFilter::kDefaultCategoryFilterString).Release(); |
82 } | 108 } |
83 | 109 |
84 bool RegisterTracingControllerAndroid(JNIEnv* env) { | 110 bool RegisterTracingControllerAndroid(JNIEnv* env) { |
85 return RegisterNativesImpl(env); | 111 return RegisterNativesImpl(env); |
86 } | 112 } |
87 | 113 |
88 } // namespace content | 114 } // namespace content |
OLD | NEW |