| 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);
|
| + }
|
| +}
|
|
|