| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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.chrome.browser; | 5 package org.chromium.chrome.browser; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 import android.content.SharedPreferences; | 8 import android.content.SharedPreferences; |
| 9 import android.os.AsyncTask; | 9 import android.os.AsyncTask; |
| 10 import android.os.Looper; | 10 import android.os.Looper; |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 | 327 |
| 328 // Crash reports can be uploaded as part of a background service
even while the main | 328 // Crash reports can be uploaded as part of a background service
even while the main |
| 329 // Chrome activity is not running, and hence regular metrics rep
orting is not | 329 // Chrome activity is not running, and hence regular metrics rep
orting is not |
| 330 // possible. Instead, metrics are temporarily written to prefs;
export those prefs | 330 // possible. Instead, metrics are temporarily written to prefs;
export those prefs |
| 331 // to UMA metrics here. | 331 // to UMA metrics here. |
| 332 MinidumpUploadService.storeBreakpadUploadStatsInUma( | 332 MinidumpUploadService.storeBreakpadUploadStatsInUma( |
| 333 ChromePreferenceManager.getInstance()); | 333 ChromePreferenceManager.getInstance()); |
| 334 | 334 |
| 335 // Likewise, this is a good time to process and clean up any pen
ding or stale crash | 335 // Likewise, this is a good time to process and clean up any pen
ding or stale crash |
| 336 // reports left behind by previous runs. | 336 // reports left behind by previous runs. |
| 337 CrashFileManager crashFileManager = | 337 CrashFileManager crashFileManager = new CrashFileManager(mAppCon
text.getCacheDir()); |
| 338 new CrashFileManager(ContextUtils.getApplicationContext(
).getCacheDir()); | |
| 339 crashFileManager.cleanOutAllNonFreshMinidumpFiles(); | 338 crashFileManager.cleanOutAllNonFreshMinidumpFiles(); |
| 340 | 339 |
| 341 // Finally, uploading any pending crash reports. | 340 // Finally, uploading any pending crash reports. |
| 342 File[] minidumps = crashFileManager.getAllMinidumpFiles( | 341 File[] minidumps = crashFileManager.getAllMinidumpFiles( |
| 343 MinidumpUploadService.MAX_TRIES_ALLOWED); | 342 MinidumpUploadService.MAX_TRIES_ALLOWED); |
| 344 int numMinidumpsSansLogcat = 0; | 343 int numMinidumpsSansLogcat = 0; |
| 345 for (File minidump : minidumps) { | 344 for (File minidump : minidumps) { |
| 346 if (CrashFileManager.isMinidumpMIMEFirstTry(minidump.getName
())) { | 345 if (CrashFileManager.isMinidumpMIMEFirstTry(minidump.getName
())) { |
| 347 ++numMinidumpsSansLogcat; | 346 ++numMinidumpsSansLogcat; |
| 348 } | 347 } |
| 349 } | 348 } |
| 350 // TODO(isherman): These two histograms are intended to be tempo
rary, and can | 349 // TODO(isherman): These two histograms are intended to be tempo
rary, and can |
| 351 // probably be removed around the M60 timeframe: http://crbug.co
m/699785 | 350 // probably be removed around the M60 timeframe: http://crbug.co
m/699785 |
| 352 RecordHistogram.recordSparseSlowlyHistogram( | 351 RecordHistogram.recordSparseSlowlyHistogram( |
| 353 "Stability.Android.PendingMinidumpsOnStartup", minidumps
.length); | 352 "Stability.Android.PendingMinidumpsOnStartup", minidumps
.length); |
| 354 RecordHistogram.recordSparseSlowlyHistogram( | 353 RecordHistogram.recordSparseSlowlyHistogram( |
| 355 "Stability.Android.PendingMinidumpsOnStartup.SansLogcat"
, | 354 "Stability.Android.PendingMinidumpsOnStartup.SansLogcat"
, |
| 356 numMinidumpsSansLogcat); | 355 numMinidumpsSansLogcat); |
| 357 if (minidumps.length == 0) return; | 356 if (minidumps.length == 0) return; |
| 358 | 357 |
| 359 Log.i(TAG, "Attempting to upload %d accumulated crash dumps.", m
inidumps.length); | 358 Log.i(TAG, "Attempting to upload %d accumulated crash dumps.", m
inidumps.length); |
| 360 File mostRecentMinidump = minidumps[0]; | 359 File mostRecentMinidump = minidumps[0]; |
| 361 if (doesCrashMinidumpNeedLogcat(mostRecentMinidump)) { | 360 if (doesCrashMinidumpNeedLogcat(mostRecentMinidump)) { |
| 362 AsyncTask.THREAD_POOL_EXECUTOR.execute( | 361 AsyncTask.THREAD_POOL_EXECUTOR.execute( |
| 363 new LogcatExtractionRunnable(mostRecentMinidump)); | 362 new LogcatExtractionRunnable(mAppContext, mostRecent
Minidump)); |
| 364 | 363 |
| 365 // The JobScheduler will schedule uploads for all of the ava
ilable minidumps | 364 // The JobScheduler will schedule uploads for all of the ava
ilable minidumps |
| 366 // once the logcat is attached. But if the JobScheduler API
is not being used, | 365 // once the logcat is attached. But if the JobScheduler API
is not being used, |
| 367 // then the logcat extraction process will only initiate an
upload for the first | 366 // then the logcat extraction process will only initiate an
upload for the first |
| 368 // minidump; it's required to manually initiate uploads for
all of the remaining | 367 // minidump; it's required to manually initiate uploads for
all of the remaining |
| 369 // minidumps. | 368 // minidumps. |
| 370 if (!MinidumpUploadService.shouldUseJobSchedulerForUploads()
) { | 369 if (!MinidumpUploadService.shouldUseJobSchedulerForUploads()
) { |
| 371 List<File> remainingMinidumps = | 370 List<File> remainingMinidumps = |
| 372 Arrays.asList(minidumps).subList(1, minidumps.le
ngth); | 371 Arrays.asList(minidumps).subList(1, minidumps.le
ngth); |
| 373 for (File minidump : remainingMinidumps) { | 372 for (File minidump : remainingMinidumps) { |
| 374 MinidumpUploadService.tryUploadCrashDump(minidump); | 373 MinidumpUploadService.tryUploadCrashDump(mAppContext
, minidump); |
| 375 } | 374 } |
| 376 } | 375 } |
| 377 } else if (MinidumpUploadService.shouldUseJobSchedulerForUploads
()) { | 376 } else if (MinidumpUploadService.shouldUseJobSchedulerForUploads
()) { |
| 378 MinidumpUploadService.scheduleUploadJob(); | 377 MinidumpUploadService.scheduleUploadJob(mAppContext); |
| 379 } else { | 378 } else { |
| 380 MinidumpUploadService.tryUploadAllCrashDumps(); | 379 MinidumpUploadService.tryUploadAllCrashDumps(mAppContext); |
| 381 } | 380 } |
| 382 } | 381 } |
| 383 | 382 |
| 384 /** | 383 /** |
| 385 * Returns whether or not it's appropriate to try to extract recent
logcat output and | 384 * Returns whether or not it's appropriate to try to extract recent
logcat output and |
| 386 * include that logcat output alongside the given {@param minidump}
in a crash report. | 385 * include that logcat output alongside the given {@param minidump}
in a crash report. |
| 387 * Logcat output should only be extracted if (a) it hasn't already b
een extracted for | 386 * Logcat output should only be extracted if (a) it hasn't already b
een extracted for |
| 388 * this minidump file, and (b) the minidump is fairly fresh. The fre
shness check is | 387 * this minidump file, and (b) the minidump is fairly fresh. The fre
shness check is |
| 389 * important for two reasons: (1) First of all, it helps avoid inclu
ding irrelevant | 388 * important for two reasons: (1) First of all, it helps avoid inclu
ding irrelevant |
| 390 * logcat output for a crash report. (2) Secondly, it provides an es
cape hatch that can | 389 * logcat output for a crash report. (2) Secondly, it provides an es
cape hatch that can |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 } | 456 } |
| 458 | 457 |
| 459 /** | 458 /** |
| 460 * @return Whether deferred startup has been completed. | 459 * @return Whether deferred startup has been completed. |
| 461 */ | 460 */ |
| 462 @VisibleForTesting | 461 @VisibleForTesting |
| 463 public boolean isDeferredStartupCompleteForApp() { | 462 public boolean isDeferredStartupCompleteForApp() { |
| 464 return mDeferredStartupCompletedForApp; | 463 return mDeferredStartupCompletedForApp; |
| 465 } | 464 } |
| 466 } | 465 } |
| OLD | NEW |