Commit ba1bbee0 authored by Eric Seckler's avatar Eric Seckler Committed by Commit Bot

tracing: Update buffer usage in tracing notifications periodically.

Also fixes the ordering of entries in the NotificationPreferences.

TBR=twellington@chromium.org

Bug: 898512
Change-Id: I2ad01d04a517100b3b0629c053dcd215cd2f838a
Reviewed-on: https://chromium-review.googlesource.com/c/1346071Reviewed-by: default avatarEric Seckler <eseckler@chromium.org>
Reviewed-by: default avatarSami Kyöstilä <skyostil@chromium.org>
Commit-Queue: Eric Seckler <eseckler@chromium.org>
Cr-Commit-Position: refs/heads/master@{#610056}
parent 725a59b7
......@@ -3,22 +3,19 @@
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" android:orderingFromXml="true">
<Preference
android:fragment="org.chromium.chrome.browser.preferences.developer.TracingCategoriesPreferences"
android:key="default_categories"
android:title="@string/prefs_tracing_default_categories_title"
android:order="0"/>
android:title="@string/prefs_tracing_default_categories_title"/>
<Preference
android:fragment="org.chromium.chrome.browser.preferences.developer.TracingCategoriesPreferences"
android:key="non_default_categories"
android:title="@string/prefs_tracing_non_default_categories_title"
android:order="1"/>
android:title="@string/prefs_tracing_non_default_categories_title"/>
<org.chromium.chrome.browser.preferences.ChromeBaseListPreference
android:key="mode"
android:title="@string/prefs_tracing_mode_title"
android:persistent="false"
android:order="2"/>
android:persistent="false"/>
<org.chromium.chrome.browser.preferences.ButtonPreference
android:key="start_recording"/>
<org.chromium.chrome.browser.preferences.TextMessagePreference
......
......@@ -73,6 +73,7 @@ public class TracingController {
// Delete shared trace files after 1 hour.
private static final long DELETE_AFTER_SHARE_TIMEOUT_MILLIS = 60 * 60 * 1000;
private static final long UPDATE_BUFFER_USAGE_INTERVAL_MILLIS = 1000;
private static TracingController sInstance;
......@@ -220,6 +221,20 @@ public class TracingController {
}
setState(State.RECORDING);
updateBufferUsage();
}
private void updateBufferUsage() {
if (mState != State.RECORDING) return;
mNativeController.getTraceBufferUsage(pair -> {
if (mState != State.RECORDING) return;
TracingNotificationManager.updateTracingActiveNotification(pair.first);
ThreadUtils.postOnUiThreadDelayed(
() -> { updateBufferUsage(); }, UPDATE_BUFFER_USAGE_INTERVAL_MILLIS);
});
}
/**
......
......@@ -28,6 +28,7 @@ public class TracingNotificationManager {
private static final int TRACING_NOTIFICATION_ID = 100;
private static NotificationManagerProxy sNotificationManagerOverride;
private static ChromeNotificationBuilder sTracingActiveNotificationBuilder;
// TODO(eseckler): Consider recording UMAs, see e.g. IncognitoNotificationManager.
......@@ -85,12 +86,11 @@ public class TracingNotificationManager {
public static void showTracingActiveNotification() {
Context context = ContextUtils.getApplicationContext();
String title = context.getResources().getString(R.string.tracing_active_notification_title);
// TODO(eseckler): Update the buffer usage in the notification periodically.
int bufferUsagePercentage = 0;
String message = context.getResources().getString(
R.string.tracing_active_notification_message, bufferUsagePercentage);
ChromeNotificationBuilder builder =
sTracingActiveNotificationBuilder =
createNotificationBuilder()
.setContentTitle(title)
.setContentText(message)
......@@ -99,7 +99,25 @@ public class TracingNotificationManager {
ContextUtils.getApplicationContext().getResources().getString(
R.string.tracing_stop),
TracingNotificationService.getStopRecordingIntent(context));
showNotification(builder.build());
showNotification(sTracingActiveNotificationBuilder.build());
}
/**
* Update the tracing notification that is shown while a trace is being recorded with the
* current buffer utilization. Should only be called while the "tracing active" notification is
* shown.
*
* @param bufferUsagePercentage buffer utilization as float between 0 and 1.
*/
public static void updateTracingActiveNotification(float bufferUsagePercentage) {
assert (sTracingActiveNotificationBuilder != null);
Context context = ContextUtils.getApplicationContext();
String message =
context.getResources().getString(R.string.tracing_active_notification_message,
Math.round(bufferUsagePercentage * 100));
sTracingActiveNotificationBuilder.setContentText(message);
showNotification(sTracingActiveNotificationBuilder.build());
}
/**
......@@ -149,6 +167,7 @@ public class TracingNotificationManager {
NotificationManagerProxy manager =
getNotificationManager(ContextUtils.getApplicationContext());
manager.cancel(TRACING_NOTIFICATION_TAG, TRACING_NOTIFICATION_ID);
sTracingActiveNotificationBuilder = null;
}
private static ChromeNotificationBuilder createNotificationBuilder() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment