Bug 1246209 - Add getProfileCreationDate, implement from filestystem, & add stencil code. r=mfinkle

Retrieving the profile creation date from the filesystem is not strictly
necessary to upload this data and returns -1 until it is implemented. If the
decision is r+'d here, it will be implemented in bug 1246816.
This commit is contained in:
Michael Comella 2016-02-08 17:10:26 -08:00
parent 85c3cb6030
commit 59539bf626

View File

@ -51,6 +51,9 @@ public final class GeckoProfile {
// In the client ID file, the attribute title in the JSON object containing the client ID value.
private static final String CLIENT_ID_JSON_ATTR = "clientID";
private static final String TIMES_PATH = "times.json";
private static final String PROFILE_CREATION_DATE_JSON_ATTR = "created";
// Only tests should need to do this.
// We can default this to AppConstants.RELEASE_BUILD once we fix Bug 1069687.
private static volatile boolean sAcceptDirectoryChanges = true;
@ -622,6 +625,40 @@ public final class GeckoProfile {
}
}
/**
* @return the profile creation date in the format returned by {@link System#currentTimeMillis()} or -1 if the value
* was not found.
*/
@WorkerThread
public long getProfileCreationDate() {
try {
return getProfileCreationDateFromTimesFile();
} catch (final IOException e) {
return getAndPersistProfileCreationDateFromFilesystem();
}
}
@WorkerThread
private long getProfileCreationDateFromTimesFile() throws IOException {
final JSONObject obj = readJSONObjectFromFile(TIMES_PATH);
try {
return obj.getLong(PROFILE_CREATION_DATE_JSON_ATTR);
} catch (final JSONException e) {
// Don't log to avoid leaking data in JSONObject.
throw new IOException("Profile creation does not exist in JSONObject");
}
}
/**
* TODO (bug 1246816): Implement ProfileAge.jsm - getOldestProfileTimestamp. Persist results to times.json.
* Update comment in getProfileCreationDate too.
* @return -1 until implemented.
*/
@WorkerThread
private long getAndPersistProfileCreationDateFromFilesystem() {
return -1;
}
/**
* Moves the session file to the backup session file.
*