Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors |
[email protected] | 43b74f0 | 2013-10-04 00:37:19 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CONTENT_BROWSER_ANDROID_TRACING_CONTROLLER_ANDROID_H_ |
| 6 | #define CONTENT_BROWSER_ANDROID_TRACING_CONTROLLER_ANDROID_H_ |
| 7 | |
[email protected] | 2cbd5ed2 | 2014-05-07 17:37:19 | [diff] [blame] | 8 | #include <set> |
| 9 | |
[email protected] | 6a718ab | 2014-04-23 20:01:20 | [diff] [blame] | 10 | #include "base/android/jni_weak_ref.h" |
[email protected] | 6174a36 | 2013-12-03 19:48:19 | [diff] [blame] | 11 | #include "base/files/file_path.h" |
| 12 | #include "base/memory/weak_ptr.h" |
[email protected] | 43b74f0 | 2013-10-04 00:37:19 | [diff] [blame] | 13 | |
| 14 | namespace content { |
| 15 | |
| 16 | // This class implements the native methods of TracingControllerAndroid.java |
| 17 | class TracingControllerAndroid { |
| 18 | public: |
Andrew Grieve | df3420a4e | 2024-08-30 21:02:48 | [diff] [blame] | 19 | TracingControllerAndroid(JNIEnv* env, const jni_zero::JavaRef<jobject>& obj); |
Peter Boström | 9b03653 | 2021-10-28 23:37:28 | [diff] [blame] | 20 | |
| 21 | TracingControllerAndroid(const TracingControllerAndroid&) = delete; |
| 22 | TracingControllerAndroid& operator=(const TracingControllerAndroid&) = delete; |
| 23 | |
Andrew Grieve | ab2c915 | 2025-07-02 19:53:13 | [diff] [blame] | 24 | void Destroy(JNIEnv* env); |
[email protected] | 43b74f0 | 2013-10-04 00:37:19 | [diff] [blame] | 25 | |
| 26 | bool StartTracing(JNIEnv* env, |
torne | e1bfee9 | 2015-12-01 14:05:01 | [diff] [blame] | 27 | const base::android::JavaParamRef<jstring>& categories, |
Sami Kyostila | ab4673c | 2020-07-30 18:32:33 | [diff] [blame] | 28 | const base::android::JavaParamRef<jstring>& trace_options, |
| 29 | bool use_protobuf); |
torne | e1bfee9 | 2015-12-01 14:05:01 | [diff] [blame] | 30 | void StopTracing(JNIEnv* env, |
Eric Seckler | a0353e80 | 2018-10-29 14:39:01 | [diff] [blame] | 31 | const base::android::JavaParamRef<jstring>& jfilepath, |
Sami Kyostila | ab4673c | 2020-07-30 18:32:33 | [diff] [blame] | 32 | bool compress_file, |
| 33 | bool use_protobuf, |
Eric Seckler | a0353e80 | 2018-10-29 14:39:01 | [diff] [blame] | 34 | const base::android::JavaParamRef<jobject>& callback); |
| 35 | bool GetKnownCategoriesAsync( |
torne | e1bfee9 | 2015-12-01 14:05:01 | [diff] [blame] | 36 | JNIEnv* env, |
Eric Seckler | a0353e80 | 2018-10-29 14:39:01 | [diff] [blame] | 37 | const base::android::JavaParamRef<jobject>& callback); |
| 38 | bool GetTraceBufferUsageAsync( |
| 39 | JNIEnv* env, |
Eric Seckler | a0353e80 | 2018-10-29 14:39:01 | [diff] [blame] | 40 | const base::android::JavaParamRef<jobject>& callback); |
Alexander Timin | 9419b1d5 | 2021-01-03 11:57:48 | [diff] [blame] | 41 | |
| 42 | // Locate the appropriate directory to write the trace to and use it to |
| 43 | // generate the path. |basename| might be empty, then TracingControllerAndroid |
| 44 | // will generate an appropriate one as well. |
| 45 | static base::FilePath GenerateTracingFilePath(const std::string& basename); |
[email protected] | 43b74f0 | 2013-10-04 00:37:19 | [diff] [blame] | 46 | |
| 47 | private: |
| 48 | ~TracingControllerAndroid(); |
Eric Seckler | a0353e80 | 2018-10-29 14:39:01 | [diff] [blame] | 49 | void OnTracingStopped( |
| 50 | const base::android::ScopedJavaGlobalRef<jobject>& callback); |
[email protected] | 2cbd5ed2 | 2014-05-07 17:37:19 | [diff] [blame] | 51 | void OnKnownCategoriesReceived( |
Eric Seckler | a0353e80 | 2018-10-29 14:39:01 | [diff] [blame] | 52 | const base::android::ScopedJavaGlobalRef<jobject>& callback, |
[email protected] | 2cbd5ed2 | 2014-05-07 17:37:19 | [diff] [blame] | 53 | const std::set<std::string>& categories_received); |
Eric Seckler | a0353e80 | 2018-10-29 14:39:01 | [diff] [blame] | 54 | void OnTraceBufferUsageReceived( |
| 55 | const base::android::ScopedJavaGlobalRef<jobject>& callback, |
| 56 | float percent_full, |
| 57 | size_t approximate_event_count); |
[email protected] | 43b74f0 | 2013-10-04 00:37:19 | [diff] [blame] | 58 | |
| 59 | JavaObjectWeakGlobalRef weak_java_object_; |
Jeremy Roman | 877cf8b4 | 2019-08-14 20:18:28 | [diff] [blame] | 60 | base::WeakPtrFactory<TracingControllerAndroid> weak_factory_{this}; |
[email protected] | 43b74f0 | 2013-10-04 00:37:19 | [diff] [blame] | 61 | }; |
| 62 | |
[email protected] | 43b74f0 | 2013-10-04 00:37:19 | [diff] [blame] | 63 | } // namespace content |
| 64 | |
| 65 | #endif // CONTENT_BROWSER_ANDROID_TRACING_CONTROLLER_ANDROID_H_ |