Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(836)

Unified Diff: base/android/java/src/org/chromium/base/LeakCanaryUtil.java

Issue 1697603002: Use LeakCanary for all Android Service instances Base URL: https://chromium.googlesource.com/chromium/src.git@leak-canary-3
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/BUILD.gn ('k') | base/base.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/android/java/src/org/chromium/base/LeakCanaryUtil.java
diff --git a/base/android/java/src/org/chromium/base/LeakCanaryUtil.java b/base/android/java/src/org/chromium/base/LeakCanaryUtil.java
new file mode 100644
index 0000000000000000000000000000000000000000..de539da659884f8f5148ffd41089e57f5826a862
--- /dev/null
+++ b/base/android/java/src/org/chromium/base/LeakCanaryUtil.java
@@ -0,0 +1,44 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.base;
+
+import android.app.Application;
+
+import com.squareup.leakcanary.LeakCanary;
+import com.squareup.leakcanary.RefWatcher;
+
+import org.chromium.base.annotations.RemovableInRelease;
+
+/**
+ * Wrapper functions for LeakCanary, which makes sure that all LeakCanary-related calls are
+ * able to be stripped by Proguard.
+ */
+public final class LeakCanaryUtil {
+ private static final String TAG = "LeakCanaryUtil";
+ private static RefWatcher sRefWatcher;
+
+ private LeakCanaryUtil() {
+ // Static only access
+ }
+
+ @RemovableInRelease
+ public static void initialize(Application appContext) {
+ if (sRefWatcher != null) {
+ throw new IllegalStateException("LeakCanaryUtil.initialize() called multiple times.");
+ }
+ Log.d(TAG, "LeakCanary initialized.");
+ // Watch that Activity objects are not retained after their onDestroy() has been called.
+ // This is a no-op in release builds.
+ sRefWatcher = LeakCanary.install(appContext);
+ }
+
+ @RemovableInRelease
+ public static void watch(Object obj) {
+ if (sRefWatcher == null) {
+ throw new IllegalStateException("LeakCanaryUtil.initialize() not yet called.");
+ }
+ sRefWatcher.watch(obj);
+ }
+}
« no previous file with comments | « base/BUILD.gn ('k') | base/base.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698