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

Side by Side Diff: components/minidump_uploader/android/java/src/org/chromium/components/minidump_uploader/MinidumpUploadJobService.java

Issue 2800833003: Revert of Android: Remove GetApplicationContext part 2 (Closed)
Patch Set: Created 3 years, 8 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 package org.chromium.components.minidump_uploader; 4 package org.chromium.components.minidump_uploader;
5 5
6 import android.annotation.TargetApi; 6 import android.annotation.TargetApi;
7 import android.app.job.JobInfo; 7 import android.app.job.JobInfo;
8 import android.app.job.JobParameters; 8 import android.app.job.JobParameters;
9 import android.app.job.JobScheduler; 9 import android.app.job.JobScheduler;
10 import android.app.job.JobService; 10 import android.app.job.JobService;
11 import android.content.Context; 11 import android.content.Context;
12 import android.os.Build; 12 import android.os.Build;
13 import android.os.PersistableBundle; 13 import android.os.PersistableBundle;
14 14
15 import org.chromium.base.ContextUtils;
16 import org.chromium.base.Log; 15 import org.chromium.base.Log;
17 16
18 /** 17 /**
19 * Class that interacts with the Android JobScheduler to upload Minidumps at app ropriate times. 18 * Class that interacts with the Android JobScheduler to upload Minidumps at app ropriate times.
20 */ 19 */
21 @TargetApi(Build.VERSION_CODES.LOLLIPOP) 20 @TargetApi(Build.VERSION_CODES.LOLLIPOP)
22 public abstract class MinidumpUploadJobService extends JobService { 21 public abstract class MinidumpUploadJobService extends JobService {
23 private static final String TAG = "MinidumpJobService"; 22 private static final String TAG = "MinidumpJobService";
24 23
25 // Initial back-off time for upload-job, i.e. the minimum delay when a job i s retried. A retry 24 // Initial back-off time for upload-job, i.e. the minimum delay when a job i s retried. A retry
26 // will happen when there are minidumps left after trying to upload all mini dumps. This could 25 // will happen when there are minidumps left after trying to upload all mini dumps. This could
27 // happen if an upload attempt fails, or if more minidumps are added at the same time as 26 // happen if an upload attempt fails, or if more minidumps are added at the same time as
28 // uploading old ones. The initial backoff is set to a fairly high number (3 0 minutes) to 27 // uploading old ones. The initial backoff is set to a fairly high number (3 0 minutes) to
29 // increase the chance of performing uploads in batches if the initial uploa d fails. 28 // increase the chance of performing uploads in batches if the initial uploa d fails.
30 private static final int JOB_INITIAL_BACKOFF_TIME_IN_MS = 1000 * 60 * 30; 29 private static final int JOB_INITIAL_BACKOFF_TIME_IN_MS = 1000 * 60 * 30;
31 30
32 // Back-off policy for upload-job. 31 // Back-off policy for upload-job.
33 private static final int JOB_BACKOFF_POLICY = JobInfo.BACKOFF_POLICY_EXPONEN TIAL; 32 private static final int JOB_BACKOFF_POLICY = JobInfo.BACKOFF_POLICY_EXPONEN TIAL;
34 33
35 private MinidumpUploader mMinidumpUploader; 34 private MinidumpUploader mMinidumpUploader;
36 35
37 // Used in Debug builds to assert that this job service never attempts to ru n more than one job 36 // Used in Debug builds to assert that this job service never attempts to ru n more than one job
38 // at a time: 37 // at a time:
39 private final Object mRunningLock = new Object(); 38 private final Object mRunningLock = new Object();
40 private boolean mRunningJob = false; 39 private boolean mRunningJob = false;
41 40
42 /** 41 /**
43 * Schedules uploading of all pending minidumps. 42 * Schedules uploading of all pending minidumps.
43 * @param context The application context, in which to schedule the crash re port uploads.
44 * @param jobInfoBuilder A job info builder that has been initialized with a ny embedder-specific 44 * @param jobInfoBuilder A job info builder that has been initialized with a ny embedder-specific
45 * requriements. This builder will be extended to include shared require ments, and then used 45 * requriements. This builder will be extended to include shared require ments, and then used
46 * to build an upload job for scheduling. 46 * to build an upload job for scheduling.
47 */ 47 */
48 public static void scheduleUpload(JobInfo.Builder jobInfoBuilder) { 48 public static void scheduleUpload(Context context, JobInfo.Builder jobInfoBu ilder) {
49 Log.i(TAG, "Scheduling upload of all pending minidumps."); 49 Log.i(TAG, "Scheduling upload of all pending minidumps.");
50 JobScheduler scheduler = 50 JobScheduler scheduler =
51 (JobScheduler) ContextUtils.getApplicationContext().getSystemSer vice( 51 (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SE RVICE);
52 Context.JOB_SCHEDULER_SERVICE);
53 JobInfo uploadJob = 52 JobInfo uploadJob =
54 jobInfoBuilder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMET ERED) 53 jobInfoBuilder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMET ERED)
55 .setBackoffCriteria(JOB_INITIAL_BACKOFF_TIME_IN_MS, JOB_ BACKOFF_POLICY) 54 .setBackoffCriteria(JOB_INITIAL_BACKOFF_TIME_IN_MS, JOB_ BACKOFF_POLICY)
56 .build(); 55 .build();
57 int result = scheduler.schedule(uploadJob); 56 int result = scheduler.schedule(uploadJob);
58 assert result == JobScheduler.RESULT_SUCCESS; 57 assert result == JobScheduler.RESULT_SUCCESS;
59 } 58 }
60 59
61 @Override 60 @Override
62 public boolean onStartJob(JobParameters params) { 61 public boolean onStartJob(JobParameters params) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 } 100 }
102 }; 101 };
103 } 102 }
104 103
105 /** 104 /**
106 * @param extras Any extra data persisted for this job. 105 * @param extras Any extra data persisted for this job.
107 * @return The minidump uploader that jobs should use. 106 * @return The minidump uploader that jobs should use.
108 */ 107 */
109 protected abstract MinidumpUploader createMinidumpUploader(PersistableBundle extras); 108 protected abstract MinidumpUploader createMinidumpUploader(PersistableBundle extras);
110 } 109 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698