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.support.annotation.Nullable; | 7 import android.support.annotation.Nullable; |
8 | 8 |
9 import org.chromium.base.Log; | 9 import org.chromium.base.Log; |
10 import org.chromium.base.VisibleForTesting; | 10 import org.chromium.base.VisibleForTesting; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
42 public static final String CRASH_DUMP_DIR = "Crash Reports"; | 42 public static final String CRASH_DUMP_DIR = "Crash Reports"; |
43 | 43 |
44 // This should mirror the C++ CrashUploadList::kReporterLogFilename variable . | 44 // This should mirror the C++ CrashUploadList::kReporterLogFilename variable . |
45 @VisibleForTesting | 45 @VisibleForTesting |
46 public static final String CRASH_DUMP_LOGFILE = "uploads.log"; | 46 public static final String CRASH_DUMP_LOGFILE = "uploads.log"; |
47 | 47 |
48 private static final Pattern MINIDUMP_MIME_FIRST_TRY_PATTERN = | 48 private static final Pattern MINIDUMP_MIME_FIRST_TRY_PATTERN = |
49 Pattern.compile("\\.dmp([0-9]+)$\\z"); | 49 Pattern.compile("\\.dmp([0-9]+)$\\z"); |
50 | 50 |
51 private static final Pattern MINIDUMP_PATTERN = | 51 private static final Pattern MINIDUMP_PATTERN = |
52 Pattern.compile("\\.dmp([0-9]*)(\\.try([0-9]+))?\\z"); | 52 Pattern.compile("\\.(dmp|forced)([0-9]*)(\\.try([0-9]+))?\\z"); |
53 | 53 |
54 // TODO(isherman): Is this pattern incorrect? Typical uploaded filenames inc lude a ".tryN" | |
55 // suffix... | |
Ilya Sherman
2017/03/14 02:22:03
By the way, Gustav, I noticed that uploaded files
gsennton
2017/03/14 18:17:28
Huh, that would indeed be important to fix for 58
Ilya Sherman
2017/03/15 02:13:35
One better: I sent you a CL =) https://codereview.
gsennton
2017/03/15 12:57:43
Awesome, thanks a lot! :)
(you can remove this com
Ilya Sherman
2017/03/16 01:36:57
Done.
| |
54 private static final Pattern UPLOADED_MINIDUMP_PATTERN = Pattern.compile("\\ .up([0-9]*)\\z"); | 56 private static final Pattern UPLOADED_MINIDUMP_PATTERN = Pattern.compile("\\ .up([0-9]*)\\z"); |
55 | 57 |
56 private static final String NOT_YET_UPLOADED_MINIDUMP_SUFFIX = ".dmp"; | 58 private static final String NOT_YET_UPLOADED_MINIDUMP_SUFFIX = ".dmp"; |
57 | 59 |
58 private static final String UPLOADED_MINIDUMP_SUFFIX = ".up"; | 60 private static final String UPLOADED_MINIDUMP_SUFFIX = ".up"; |
59 | 61 |
60 private static final String UPLOAD_SKIPPED_MINIDUMP_SUFFIX = ".skipped"; | 62 private static final String UPLOAD_SKIPPED_MINIDUMP_SUFFIX = ".skipped"; |
61 | 63 |
62 private static final String UPLOAD_FORCED_MINIDUMP_SUFFIX = ".forced"; | 64 private static final String UPLOAD_FORCED_MINIDUMP_SUFFIX = ".forced"; |
63 | 65 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
130 public static String tryIncrementAttemptNumber(File mFileToUpload) { | 132 public static String tryIncrementAttemptNumber(File mFileToUpload) { |
131 String newName = filenameWithIncrementedAttemptNumber(mFileToUpload.getP ath()); | 133 String newName = filenameWithIncrementedAttemptNumber(mFileToUpload.getP ath()); |
132 return mFileToUpload.renameTo(new File(newName)) ? newName : null; | 134 return mFileToUpload.renameTo(new File(newName)) ? newName : null; |
133 } | 135 } |
134 | 136 |
135 /** | 137 /** |
136 * @return The file name to rename to after an addition attempt to upload | 138 * @return The file name to rename to after an addition attempt to upload |
137 */ | 139 */ |
138 @VisibleForTesting | 140 @VisibleForTesting |
139 public static String filenameWithIncrementedAttemptNumber(String filename) { | 141 public static String filenameWithIncrementedAttemptNumber(String filename) { |
140 int numTried = readAttemptNumber(filename); | 142 int numTried = readAttemptNumberInternal(filename); |
141 if (numTried >= 0) { | 143 if (numTried >= 0) { |
142 int newCount = numTried + 1; | 144 int newCount = numTried + 1; |
143 return filename.replace( | 145 return filename.replace( |
144 UPLOAD_ATTEMPT_DELIMITER + numTried, UPLOAD_ATTEMPT_DELIMITE R + newCount); | 146 UPLOAD_ATTEMPT_DELIMITER + numTried, UPLOAD_ATTEMPT_DELIMITE R + newCount); |
145 } else { | 147 } else { |
146 // readAttemptNumber returning -1 means there is no UPLOAD_ATTEMPT_D ELIMITER in the file | 148 // readAttemptNumberInternal returning -1 means there is no UPLOAD_A TTEMPT_DELIMITER in |
147 // name (or that there is a delimiter but no attempt number). So, we have to add the | 149 // the file name (or that there is a delimiter but no attempt number ). So, we have to |
148 // delimiter and attempt number ourselves. | 150 // add the delimiter and attempt number ourselves. |
149 return filename + UPLOAD_ATTEMPT_DELIMITER + "1"; | 151 return filename + UPLOAD_ATTEMPT_DELIMITER + "1"; |
150 } | 152 } |
151 } | 153 } |
152 | 154 |
153 /** | 155 /** |
154 * Attempts to rename the given file to mark it as a forced upload. This is useful for allowing | 156 * Attempts to rename the given file to mark it as a forced upload. This is useful for allowing |
155 * users to manually initiate previously skipped uploads. | 157 * users to manually initiate previously skipped uploads. |
156 * | 158 * |
157 * @return The renamed file, or null if renaming failed. | 159 * @return The renamed file, or null if renaming failed. |
158 */ | 160 */ |
(...skipping 25 matching lines...) Expand all Loading... | |
184 filename = filename.replace( | 186 filename = filename.replace( |
185 UPLOAD_ATTEMPT_DELIMITER + numTried, UPLOAD_ATTEMPT_DELIMITE R + 0); | 187 UPLOAD_ATTEMPT_DELIMITER + numTried, UPLOAD_ATTEMPT_DELIMITE R + 0); |
186 } | 188 } |
187 filename = filename.replace(UPLOAD_SKIPPED_MINIDUMP_SUFFIX, UPLOAD_FORCE D_MINIDUMP_SUFFIX); | 189 filename = filename.replace(UPLOAD_SKIPPED_MINIDUMP_SUFFIX, UPLOAD_FORCE D_MINIDUMP_SUFFIX); |
188 return filename.replace(NOT_YET_UPLOADED_MINIDUMP_SUFFIX, UPLOAD_FORCED_ MINIDUMP_SUFFIX); | 190 return filename.replace(NOT_YET_UPLOADED_MINIDUMP_SUFFIX, UPLOAD_FORCED_ MINIDUMP_SUFFIX); |
189 } | 191 } |
190 | 192 |
191 /** | 193 /** |
192 * Returns how many times we've tried to upload a certain Minidump file. | 194 * Returns how many times we've tried to upload a certain Minidump file. |
193 * @return the number of attempts to upload the given Minidump file, parsed from its file name, | 195 * @return the number of attempts to upload the given Minidump file, parsed from its file name, |
194 * returns -1 if an attempt-number cannot be parsed from the file-name. | 196 * returns -1 if an attempt-number cannot be parsed from the file-name. |
gsennton
2017/03/14 18:17:28
Update comment please ;)
Ilya Sherman
2017/03/15 02:13:35
Done.
| |
195 */ | 197 */ |
196 @VisibleForTesting | 198 @VisibleForTesting |
197 public static int readAttemptNumber(String filename) { | 199 public static int readAttemptNumber(String filename) { |
200 int numTries = readAttemptNumberInternal(filename); | |
201 return numTries >= 0 ? numTries : 0; | |
202 } | |
203 | |
204 /** | |
205 * Returns how many times we've tried to upload a certain Minidump file. | |
206 * @return the number of attempts to upload the given Minidump file, parsed from its file name, | |
207 * returns -1 if an attempt-number cannot be parsed from the file-name. | |
208 */ | |
209 @VisibleForTesting | |
210 public static int readAttemptNumberInternal(String filename) { | |
Maria
2017/03/14 19:03:32
can this be package-visible instead?
Ilya Sherman
2017/03/15 02:13:35
Done.
| |
198 int tryIndex = filename.lastIndexOf(UPLOAD_ATTEMPT_DELIMITER); | 211 int tryIndex = filename.lastIndexOf(UPLOAD_ATTEMPT_DELIMITER); |
199 if (tryIndex >= 0) { | 212 if (tryIndex >= 0) { |
200 tryIndex += UPLOAD_ATTEMPT_DELIMITER.length(); | 213 tryIndex += UPLOAD_ATTEMPT_DELIMITER.length(); |
201 String numTriesString = filename.substring(tryIndex); | 214 String numTriesString = filename.substring(tryIndex); |
202 Scanner numTriesScanner = new Scanner(numTriesString).useDelimiter(" [^0-9]+"); | 215 Scanner numTriesScanner = new Scanner(numTriesString).useDelimiter(" [^0-9]+"); |
203 try { | 216 try { |
204 int nextInt = numTriesScanner.nextInt(); | 217 int nextInt = numTriesScanner.nextInt(); |
205 // Only return the number if it occurs just after the UPLOAD_ATT EMPT_DELIMITER. | 218 // Only return the number if it occurs just after the UPLOAD_ATT EMPT_DELIMITER. |
206 return numTriesString.indexOf(Integer.toString(nextInt)) == 0 ? nextInt : -1; | 219 return numTriesString.indexOf(Integer.toString(nextInt)) == 0 ? nextInt : -1; |
207 } catch (NoSuchElementException e) { | 220 } catch (NoSuchElementException e) { |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
566 /** | 579 /** |
567 * Create a temporary file to store a minidump in before renaming it with a real minidump name. | 580 * Create a temporary file to store a minidump in before renaming it with a real minidump name. |
568 * @return a new temporary file with prefix {@param prefix} stored in the di rectory | 581 * @return a new temporary file with prefix {@param prefix} stored in the di rectory |
569 * {@param directory}. | 582 * {@param directory}. |
570 * | 583 * |
571 */ | 584 */ |
572 private static File createMinidumpTmpFile(File directory) throws IOException { | 585 private static File createMinidumpTmpFile(File directory) throws IOException { |
573 return File.createTempFile("webview_minidump", TMP_SUFFIX, directory); | 586 return File.createTempFile("webview_minidump", TMP_SUFFIX, directory); |
574 } | 587 } |
575 } | 588 } |
OLD | NEW |