Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/crash/MinidumpDirectoryObserver.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/crash/MinidumpDirectoryObserver.java b/chrome/android/java/src/org/chromium/chrome/browser/crash/MinidumpDirectoryObserver.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8c256b00726255f4864eda309818cd7b2465087e |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/crash/MinidumpDirectoryObserver.java |
| @@ -0,0 +1,57 @@ |
| +// 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.chrome.browser.crash; |
| + |
| +import android.content.Context; |
| +import android.content.Intent; |
| +import android.os.FileObserver; |
| + |
| +import org.chromium.base.ApplicationStatus; |
| +import org.chromium.base.Log; |
| +import org.chromium.base.ThreadUtils; |
| +import org.chromium.base.metrics.RecordUserAction; |
| + |
| +import java.io.File; |
| + |
| +/** |
| + * This class is a singleton that holds utilities for observer to monitor the minidump directory. |
| + */ |
| +public final class MinidumpDirectoryObserver extends FileObserver { |
| + |
| + private static final String TAG = "MinidumpDirObserver"; |
| + |
| + private static MinidumpDirectoryObserver sMinidumpDirectoryObserver; |
| + private static Context sContext = ApplicationStatus.getApplicationContext(); |
| + |
| + public static final String MINIDUMP_EXPERIMENT_NAME = "AddMinidumpDirObserver"; |
| + |
| + public static void startObserverWatching() { |
| + ThreadUtils.assertOnUiThread(); |
|
Yaron
2016/02/01 20:22:40
why? Do you just need a stable thread to avoid loc
Menglin
2016/02/02 02:11:29
Done.
Yaron
2016/02/03 21:51:42
Does this really need to be a singleton and have t
Menglin
2016/02/04 00:17:23
I was not sure so I manually tested on both.
cas
Yaron
2016/02/04 01:50:26
IT really shouldn't. Can you upload a patchset wit
Menglin
2016/02/04 21:54:45
Now MinidumpDirectoryObserver is not a singleton,
|
| + if (sMinidumpDirectoryObserver == null) { |
| + sMinidumpDirectoryObserver = new MinidumpDirectoryObserver(); |
| + } |
| + sMinidumpDirectoryObserver.startWatching(); |
| + } |
| + |
| + private MinidumpDirectoryObserver() { |
| + // The file observer detects MOVED_TO for child processes. |
| + super(new File(sContext.getCacheDir(), CrashFileManager.CRASH_DUMP_DIR).toString(), |
|
Yaron
2016/02/01 20:22:40
This can cause a StrictMode violation since intern
Menglin
2016/02/02 02:11:29
I removed the assertOnUiThread(), does that resolv
Yaron
2016/02/03 21:51:42
No, because it's still called from the UI thread.
Menglin
2016/02/04 00:17:23
Done.
|
| + FileObserver.MOVED_TO); |
|
Yaron
2016/02/01 20:22:40
Is this CL description out of date? I don't see a
Menglin
2016/02/02 02:11:29
Done.
|
| + } |
| + |
| + /** |
| + * When a miniudump is detected, upload it to Google crash server |
|
Yaron
2016/02/01 20:22:40
minidump
Menglin
2016/02/02 02:11:30
Done.
|
| + */ |
| + @Override |
| + public void onEvent(int event, String path) { |
| + // This is happening on an off-thread. |
|
Yaron
2016/02/01 20:22:40
What's an "off-thread"? How about:
"This is execut
Menglin
2016/02/02 02:11:30
Done.
|
| + if (CrashFileManager.isMinidumpMIMEFirstTry(path)) { |
| + Intent intent = MinidumpUploadService.createFindAndUploadLastCrashIntent(sContext); |
| + sContext.startService(intent); |
|
Yaron
2016/02/01 20:22:40
You should try/catch this for a security exception
Menglin
2016/02/02 02:11:30
Done.
|
| + Log.i(TAG, "Detects a new minidump %s sending intent to MinidumpUploadService", path); |
| + RecordUserAction.record("MobileBreakpadUploadAttempt"); |
| + } |
| + } |
| +} |