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

Side by Side Diff: android_webview/java/src/org/chromium/android_webview/crash/CrashReceiverService.java

Issue 2737263006: [Android Crash Reporting] Allow uploading minidumps via the JobScheduler (Closed)
Patch Set: Assert that job scheduled successfully Created 3 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.android_webview.crash; 5 package org.chromium.android_webview.crash;
6 6
7 import android.annotation.TargetApi; 7 import android.annotation.TargetApi;
8 import android.app.Service; 8 import android.app.Service;
9 import android.app.job.JobInfo; 9 import android.app.job.JobInfo;
10 import android.app.job.JobScheduler;
11 import android.content.ComponentName; 10 import android.content.ComponentName;
12 import android.content.Context; 11 import android.content.Context;
13 import android.content.Intent; 12 import android.content.Intent;
14 import android.os.Binder; 13 import android.os.Binder;
15 import android.os.Build; 14 import android.os.Build;
16 import android.os.IBinder; 15 import android.os.IBinder;
17 import android.os.ParcelFileDescriptor; 16 import android.os.ParcelFileDescriptor;
18 17
19 import org.chromium.base.Log; 18 import org.chromium.base.Log;
20 import org.chromium.base.VisibleForTesting; 19 import org.chromium.base.VisibleForTesting;
20 import org.chromium.components.background_task_scheduler.TaskIds;
21 import org.chromium.components.minidump_uploader.CrashFileManager; 21 import org.chromium.components.minidump_uploader.CrashFileManager;
22 import org.chromium.components.minidump_uploader.MinidumpUploadJobService;
22 23
23 import java.io.File; 24 import java.io.File;
24 import java.io.IOException; 25 import java.io.IOException;
25 26
26 /** 27 /**
27 * Service that is responsible for receiving crash dumps from an application, fo r upload. 28 * Service that is responsible for receiving crash dumps from an application, fo r upload.
28 */ 29 */
29 @TargetApi(Build.VERSION_CODES.LOLLIPOP) 30 @TargetApi(Build.VERSION_CODES.LOLLIPOP)
30 public class CrashReceiverService extends Service { 31 public class CrashReceiverService extends Service {
31 private static final String TAG = "CrashReceiverService"; 32 private static final String TAG = "CrashReceiverService";
32 33
33 private static final String WEBVIEW_CRASH_DIR = "WebView_Crashes"; 34 private static final String WEBVIEW_CRASH_DIR = "WebView_Crashes";
34 private static final String WEBVIEW_TMP_CRASH_DIR = "WebView_Crashes_Tmp"; 35 private static final String WEBVIEW_TMP_CRASH_DIR = "WebView_Crashes_Tmp";
35 36
36 private static final int MINIDUMP_UPLOADING_JOB_ID = 42;
37 // Initial back-off time for upload-job, this is set to a fairly high number (30 minutes) to
38 // increase the chance of performing uploads in batches if the initial uploa d fails.
39 private static final int JOB_BACKOFF_TIME_IN_MS = 1000 * 60 * 30;
40 // Back-off policy for upload-job.
41 private static final int JOB_BACKOFF_POLICY = JobInfo.BACKOFF_POLICY_EXPONEN TIAL;
42
43 private final Object mCopyingLock = new Object(); 37 private final Object mCopyingLock = new Object();
44 private boolean mIsCopying = false; 38 private boolean mIsCopying = false;
45 39
46 @Override 40 @Override
47 public void onCreate() { 41 public void onCreate() {
48 super.onCreate(); 42 super.onCreate();
49 } 43 }
50 44
51 private final ICrashReceiverService.Stub mBinder = new ICrashReceiverService .Stub() { 45 private final ICrashReceiverService.Stub mBinder = new ICrashReceiverService .Stub() {
52 @Override 46 @Override
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 Log.e(TAG, "Was interrupted when waiting to copy minidumps", e); 92 Log.e(TAG, "Was interrupted when waiting to copy minidumps", e);
99 return false; 93 return false;
100 } 94 }
101 } 95 }
102 mIsCopying = true; 96 mIsCopying = true;
103 return true; 97 return true;
104 } 98 }
105 } 99 }
106 100
107 private void scheduleNewJob() { 101 private void scheduleNewJob() {
108 JobScheduler jobScheduler = (JobScheduler) getSystemService(Context.JOB_ SCHEDULER_SERVICE); 102 JobInfo.Builder builder =
109 JobInfo newJob = new JobInfo 103 new JobInfo
110 .Builder(MINIDUMP_UPLOADING_JOB_ID /* jobId */, 104 .Builder(TaskIds.WEBVIEW_MINIDUMP_UPLOADING_JOB_ID,
111 new ComponentName(this, AwMinidumpUploa dJobService.class)) 105 new ComponentName(this, AwMinidumpUploadJobServi ce.class))
112 .setRequiredNetworkType(JobInfo.NETWORK_TYPE_UN METERED) 106 .setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED);
113 // Minimum delay when a job is retried (a retry will happen when 107 MinidumpUploadJobService.scheduleUpload(this, builder);
114 // there are minidumps left after trying to upl oad all minidumps -
115 // this could e.g. happen if we add more minidu mps at the same time
116 // as uploading old ones).
117 .setBackoffCriteria(JOB_BACKOFF_TIME_IN_MS, JOB _BACKOFF_POLICY)
118 .build();
119 if (jobScheduler.schedule(newJob) == JobScheduler.RESULT_FAILURE) {
120 throw new RuntimeException("couldn't schedule " + newJob);
121 }
122 } 108 }
123 109
124 /** 110 /**
125 * Copy minidumps from the {@param fileDescriptors} to the directory where W ebView stores its 111 * Copy minidumps from the {@param fileDescriptors} to the directory where W ebView stores its
126 * minidump files. {@param context} is used to look up the directory in whic h the files will be 112 * minidump files. {@param context} is used to look up the directory in whic h the files will be
127 * saved. 113 * saved.
128 * @return whether any minidump was copied. 114 * @return whether any minidump was copied.
129 */ 115 */
130 @VisibleForTesting 116 @VisibleForTesting
131 public static boolean copyMinidumps( 117 public static boolean copyMinidumps(
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 @VisibleForTesting 199 @VisibleForTesting
214 public static File getWebViewTmpCrashDir(Context context) { 200 public static File getWebViewTmpCrashDir(Context context) {
215 return new File(context.getCacheDir(), WEBVIEW_TMP_CRASH_DIR); 201 return new File(context.getCacheDir(), WEBVIEW_TMP_CRASH_DIR);
216 } 202 }
217 203
218 @Override 204 @Override
219 public IBinder onBind(Intent intent) { 205 public IBinder onBind(Intent intent) {
220 return mBinder; 206 return mBinder;
221 } 207 }
222 } 208 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698