| OLD | NEW |
| 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.components.minidump_uploader; | 5 package org.chromium.components.minidump_uploader; |
| 6 | 6 |
| 7 import android.content.SharedPreferences; | 7 import android.content.SharedPreferences; |
| 8 import android.support.annotation.IntDef; | 8 import android.support.annotation.IntDef; |
| 9 | 9 |
| 10 import org.chromium.base.ContextUtils; | 10 import org.chromium.base.ContextUtils; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 @VisibleForTesting | 47 @VisibleForTesting |
| 48 protected static final String CRASH_URL_STRING = "https://clients2.google.co
m/cr/report"; | 48 protected static final String CRASH_URL_STRING = "https://clients2.google.co
m/cr/report"; |
| 49 | 49 |
| 50 @VisibleForTesting | 50 @VisibleForTesting |
| 51 protected static final String CONTENT_TYPE_TMPL = "multipart/form-data; boun
dary=%s"; | 51 protected static final String CONTENT_TYPE_TMPL = "multipart/form-data; boun
dary=%s"; |
| 52 | 52 |
| 53 @IntDef({ | 53 @IntDef({ |
| 54 UPLOAD_SUCCESS, | 54 UPLOAD_SUCCESS, |
| 55 UPLOAD_FAILURE, | 55 UPLOAD_FAILURE, |
| 56 UPLOAD_USER_DISABLED, | 56 UPLOAD_USER_DISABLED, |
| 57 UPLOAD_COMMANDLINE_DISABLED, | |
| 58 UPLOAD_DISABLED_BY_SAMPLING | 57 UPLOAD_DISABLED_BY_SAMPLING |
| 59 }) | 58 }) |
| 60 public @interface MinidumpUploadStatus {} | 59 public @interface MinidumpUploadStatus {} |
| 61 public static final int UPLOAD_SUCCESS = 0; | 60 public static final int UPLOAD_SUCCESS = 0; |
| 62 public static final int UPLOAD_FAILURE = 1; | 61 public static final int UPLOAD_FAILURE = 1; |
| 63 public static final int UPLOAD_USER_DISABLED = 2; | 62 public static final int UPLOAD_USER_DISABLED = 2; |
| 64 public static final int UPLOAD_COMMANDLINE_DISABLED = 3; | 63 public static final int UPLOAD_DISABLED_BY_SAMPLING = 3; |
| 65 public static final int UPLOAD_DISABLED_BY_SAMPLING = 4; | |
| 66 | 64 |
| 67 private final File mFileToUpload; | 65 private final File mFileToUpload; |
| 68 private final File mLogfile; | 66 private final File mLogfile; |
| 69 private final HttpURLConnectionFactory mHttpURLConnectionFactory; | 67 private final HttpURLConnectionFactory mHttpURLConnectionFactory; |
| 70 private final CrashReportingPermissionManager mPermManager; | 68 private final CrashReportingPermissionManager mPermManager; |
| 71 | 69 |
| 72 public MinidumpUploadCallable( | 70 public MinidumpUploadCallable( |
| 73 File fileToUpload, File logfile, CrashReportingPermissionManager per
missionManager) { | 71 File fileToUpload, File logfile, CrashReportingPermissionManager per
missionManager) { |
| 74 this(fileToUpload, logfile, new HttpURLConnectionFactoryImpl(), permissi
onManager); | 72 this(fileToUpload, logfile, new HttpURLConnectionFactoryImpl(), permissi
onManager); |
| 75 removeOutdatedPrefs(ContextUtils.getAppSharedPreferences()); | 73 removeOutdatedPrefs(ContextUtils.getAppSharedPreferences()); |
| 76 } | 74 } |
| 77 | 75 |
| 78 public MinidumpUploadCallable(File fileToUpload, File logfile, | 76 public MinidumpUploadCallable(File fileToUpload, File logfile, |
| 79 HttpURLConnectionFactory httpURLConnectionFactory, | 77 HttpURLConnectionFactory httpURLConnectionFactory, |
| 80 CrashReportingPermissionManager permissionManager) { | 78 CrashReportingPermissionManager permissionManager) { |
| 81 mFileToUpload = fileToUpload; | 79 mFileToUpload = fileToUpload; |
| 82 mLogfile = logfile; | 80 mLogfile = logfile; |
| 83 mHttpURLConnectionFactory = httpURLConnectionFactory; | 81 mHttpURLConnectionFactory = httpURLConnectionFactory; |
| 84 mPermManager = permissionManager; | 82 mPermManager = permissionManager; |
| 85 } | 83 } |
| 86 | 84 |
| 87 @Override | 85 @Override |
| 88 public Integer call() { | 86 public Integer call() { |
| 89 // TODO(jchinlee): address proper cleanup procedures for command line fl
ag-disabled uploads. | |
| 90 if (mPermManager.isCrashUploadDisabledByCommandLine()) { | |
| 91 Log.i(TAG, "Minidump upload is disabled by command line flag. Retain
ing file."); | |
| 92 return UPLOAD_COMMANDLINE_DISABLED; | |
| 93 } | |
| 94 | |
| 95 if (mPermManager.isUploadEnabledForTests()) { | 87 if (mPermManager.isUploadEnabledForTests()) { |
| 96 Log.i(TAG, "Minidump upload enabled for tests, skipping other checks
."); | 88 Log.i(TAG, "Minidump upload enabled for tests, skipping other checks
."); |
| 97 } else if (!CrashFileManager.isForcedUpload(mFileToUpload)) { | 89 } else if (!CrashFileManager.isForcedUpload(mFileToUpload)) { |
| 98 if (!mPermManager.isUsageAndCrashReportingPermittedByUser()) { | 90 if (!mPermManager.isUsageAndCrashReportingPermittedByUser()) { |
| 99 Log.i(TAG, "Minidump upload is not permitted by user. Marking fi
le as skipped for " | 91 Log.i(TAG, "Minidump upload is not permitted by user. Marking fi
le as skipped for " |
| 100 + "cleanup to prevent future uploads."); | 92 + "cleanup to prevent future uploads."); |
| 101 CrashFileManager.markUploadSkipped(mFileToUpload); | 93 CrashFileManager.markUploadSkipped(mFileToUpload); |
| 102 return UPLOAD_USER_DISABLED; | 94 return UPLOAD_USER_DISABLED; |
| 103 } | 95 } |
| 104 | 96 |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 // TODO(gayane): Remove this function and unused prefs in M51. crbug.com/555
022 | 301 // TODO(gayane): Remove this function and unused prefs in M51. crbug.com/555
022 |
| 310 private void removeOutdatedPrefs(SharedPreferences sharedPreferences) { | 302 private void removeOutdatedPrefs(SharedPreferences sharedPreferences) { |
| 311 SharedPreferences.Editor editor = sharedPreferences.edit(); | 303 SharedPreferences.Editor editor = sharedPreferences.edit(); |
| 312 editor.remove(PREF_DAY_UPLOAD_COUNT) | 304 editor.remove(PREF_DAY_UPLOAD_COUNT) |
| 313 .remove(PREF_LAST_UPLOAD_DAY) | 305 .remove(PREF_LAST_UPLOAD_DAY) |
| 314 .remove(PREF_LAST_UPLOAD_WEEK) | 306 .remove(PREF_LAST_UPLOAD_WEEK) |
| 315 .remove(PREF_WEEK_UPLOAD_SIZE) | 307 .remove(PREF_WEEK_UPLOAD_SIZE) |
| 316 .apply(); | 308 .apply(); |
| 317 } | 309 } |
| 318 } | 310 } |
| OLD | NEW |