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" |
12 #include "base/memory/ref_counted_memory.h" | |
11 #include "content/public/browser/tracing_controller.h" | 13 #include "content/public/browser/tracing_controller.h" |
12 #include "jni/TracingControllerAndroid_jni.h" | 14 #include "jni/TracingControllerAndroid_jni.h" |
13 | 15 |
14 namespace content { | 16 namespace content { |
15 | 17 |
16 static jlong Init(JNIEnv* env, jobject obj) { | 18 static jlong Init(JNIEnv* env, jobject obj) { |
17 TracingControllerAndroid* profiler = new TracingControllerAndroid(env, obj); | 19 TracingControllerAndroid* profiler = new TracingControllerAndroid(env, obj); |
18 return reinterpret_cast<intptr_t>(profiler); | 20 return reinterpret_cast<intptr_t>(profiler); |
19 } | 21 } |
20 | 22 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
69 } | 71 } |
70 | 72 |
71 void TracingControllerAndroid::OnTracingStopped( | 73 void TracingControllerAndroid::OnTracingStopped( |
72 const base::FilePath& file_path) { | 74 const base::FilePath& file_path) { |
73 JNIEnv* env = base::android::AttachCurrentThread(); | 75 JNIEnv* env = base::android::AttachCurrentThread(); |
74 base::android::ScopedJavaLocalRef<jobject> obj = weak_java_object_.get(env); | 76 base::android::ScopedJavaLocalRef<jobject> obj = weak_java_object_.get(env); |
75 if (obj.obj()) | 77 if (obj.obj()) |
76 Java_TracingControllerAndroid_onTracingStopped(env, obj.obj()); | 78 Java_TracingControllerAndroid_onTracingStopped(env, obj.obj()); |
77 } | 79 } |
78 | 80 |
81 bool TracingControllerAndroid::GetKnownCategoryGroupsAsync(JNIEnv* env, | |
82 jobject obj) { | |
83 if (!TracingController::GetInstance()->GetCategories( | |
84 base::Bind(&TracingControllerAndroid::OnKnownCategoriesReceived, | |
85 weak_factory_.GetWeakPtr()))) { | |
86 return false; | |
87 } | |
88 return true; | |
89 } | |
90 | |
91 void TracingControllerAndroid::OnKnownCategoriesReceived( | |
92 const std::set<std::string>& categories_received) { | |
Xianzhu
2014/05/05 16:32:21
As the Java side doesn't actually need the categor
r.kasibhatla
2014/05/06 11:04:06
Done.
| |
93 JNIEnv* env = base::android::AttachCurrentThread(); | |
94 | |
95 scoped_ptr<base::ListValue> category_list(new base::ListValue()); | |
96 for (std::set<std::string>::const_iterator it = categories_received.begin(); | |
97 it != categories_received.end(); | |
98 ++it) { | |
99 category_list->AppendString(*it); | |
100 } | |
101 base::RefCountedString* res = new base::RefCountedString(); | |
102 base::JSONWriter::Write(category_list.get(), &res->data()); | |
103 | |
104 std::string received_category_list = res->data(); | |
105 jstring category_list_as_json_string = base::android::ConvertUTF8ToJavaString( | |
106 env, received_category_list).Release(); | |
107 base::android::ScopedJavaLocalRef<jobject> obj = weak_java_object_.get(env); | |
108 if (obj.obj()) | |
109 Java_TracingControllerAndroid_onCategoryGroupsReceived( | |
110 env, obj.obj(), category_list_as_json_string); | |
111 } | |
112 | |
79 static jstring GetDefaultCategories(JNIEnv* env, jobject obj) { | 113 static jstring GetDefaultCategories(JNIEnv* env, jobject obj) { |
80 return base::android::ConvertUTF8ToJavaString(env, | 114 return base::android::ConvertUTF8ToJavaString(env, |
81 base::debug::CategoryFilter::kDefaultCategoryFilterString).Release(); | 115 base::debug::CategoryFilter::kDefaultCategoryFilterString).Release(); |
82 } | 116 } |
83 | 117 |
84 bool RegisterTracingControllerAndroid(JNIEnv* env) { | 118 bool RegisterTracingControllerAndroid(JNIEnv* env) { |
85 return RegisterNativesImpl(env); | 119 return RegisterNativesImpl(env); |
86 } | 120 } |
87 | 121 |
88 } // namespace content | 122 } // namespace content |
OLD | NEW |