зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1241685 - Hook up TelemetryPreferences for telemetry server url. r=ahunt
In this patch, I move the telemetry server preference from app preferences to per-profile preferences. We never allowed the user to set the preference so this should cause no issues. MozReview-Commit-ID: 7D5y58R2ejd --HG-- extra : rebase_source : 3b4214968cac48150f6a3f873967cb43c7952b1b
This commit is contained in:
Родитель
dbd6e16080
Коммит
8de14c09db
|
@ -40,6 +40,8 @@ public class TelemetryCorePingDelegate extends BrowserAppDelegateWithReference
|
|||
|
||||
@Override
|
||||
public void onStart(final BrowserApp browserApp) {
|
||||
TelemetryPreferences.initPreferenceObserver(browserApp, browserApp.getProfile().getName());
|
||||
|
||||
// We don't upload in onCreate because that's only called when the Activity needs to be instantiated
|
||||
// and it's possible the system will never free the Activity from memory.
|
||||
//
|
||||
|
@ -93,8 +95,10 @@ public class TelemetryCorePingDelegate extends BrowserAppDelegateWithReference
|
|||
@WorkerThread // via constructor
|
||||
private TelemetryDispatcher getTelemetryDispatcher(final BrowserApp browserApp) {
|
||||
if (telemetryDispatcher == null) {
|
||||
final String profilePath = browserApp.getProfile().getDir().getAbsolutePath();
|
||||
telemetryDispatcher = new TelemetryDispatcher(profilePath);
|
||||
final GeckoProfile profile = browserApp.getProfile();
|
||||
final String profilePath = profile.getDir().getAbsolutePath();
|
||||
final String profileName = profile.getName();
|
||||
telemetryDispatcher = new TelemetryDispatcher(profilePath, profileName);
|
||||
}
|
||||
return telemetryDispatcher;
|
||||
}
|
||||
|
|
|
@ -58,13 +58,13 @@ public class TelemetryDispatcher {
|
|||
private final TelemetryUploadAllPingsImmediatelyScheduler uploadAllPingsImmediatelyScheduler;
|
||||
|
||||
@WorkerThread // via TelemetryJSONFilePingStore
|
||||
public TelemetryDispatcher(final String profilePath) {
|
||||
public TelemetryDispatcher(final String profilePath, final String profileName) {
|
||||
final String storePath = profilePath + File.separator + STORE_CONTAINER_DIR_NAME;
|
||||
|
||||
// There are measurements in the core ping (e.g. seq #) that would ideally be atomically updated
|
||||
// when the ping is stored. However, for simplicity, we use the json store and accept the possible
|
||||
// loss of data (see bug 1243585 comment 16+ for more).
|
||||
coreStore = new TelemetryJSONFilePingStore(new File(storePath, CORE_STORE_DIR_NAME));
|
||||
coreStore = new TelemetryJSONFilePingStore(new File(storePath, CORE_STORE_DIR_NAME), profileName);
|
||||
|
||||
uploadAllPingsImmediatelyScheduler = new TelemetryUploadAllPingsImmediatelyScheduler();
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ package org.mozilla.gecko.telemetry;
|
|||
import android.app.IntentService;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.util.Log;
|
||||
import ch.boye.httpclientandroidlib.HttpHeaders;
|
||||
import ch.boye.httpclientandroidlib.HttpResponse;
|
||||
|
@ -15,7 +14,6 @@ import ch.boye.httpclientandroidlib.client.ClientProtocolException;
|
|||
import ch.boye.httpclientandroidlib.client.methods.HttpRequestBase;
|
||||
import ch.boye.httpclientandroidlib.impl.client.DefaultHttpClient;
|
||||
import org.mozilla.gecko.GeckoProfile;
|
||||
import org.mozilla.gecko.GeckoSharedPrefs;
|
||||
import org.mozilla.gecko.preferences.GeckoPreferences;
|
||||
import org.mozilla.gecko.restrictions.Restrictable;
|
||||
import org.mozilla.gecko.restrictions.Restrictions;
|
||||
|
@ -102,7 +100,7 @@ public class TelemetryUploadService extends IntentService {
|
|||
return true;
|
||||
}
|
||||
|
||||
final String serverSchemeHostPort = getServerSchemeHostPort(context);
|
||||
final String serverSchemeHostPort = TelemetryPreferences.getServerSchemeHostPort(context, store.getProfileName());
|
||||
final HashSet<String> successfulUploadIDs = new HashSet<>(pingsToUpload.size()); // used for side effects.
|
||||
final PingResultDelegate delegate = new PingResultDelegate(successfulUploadIDs);
|
||||
for (final TelemetryPing ping : pingsToUpload) {
|
||||
|
@ -126,14 +124,6 @@ public class TelemetryUploadService extends IntentService {
|
|||
return wereAllUploadsSuccessful;
|
||||
}
|
||||
|
||||
private static String getServerSchemeHostPort(final Context context) {
|
||||
// TODO (bug 1241685): Sync this preference with the gecko preference or a Java-based pref.
|
||||
// We previously had this synced with profile prefs with no way to change it in the client, so
|
||||
// we don't have to worry about losing data by switching it to app prefs, which is more convenient for now.
|
||||
final SharedPreferences sharedPrefs = GeckoSharedPrefs.forApp(context);
|
||||
return sharedPrefs.getString(TelemetryConstants.PREF_SERVER_URL, TelemetryConstants.DEFAULT_SERVER_URL);
|
||||
}
|
||||
|
||||
private static void uploadPayload(final String url, final ExtendedJSONObject payload, final ResultDelegate delegate) {
|
||||
final BaseResource resource;
|
||||
try {
|
||||
|
|
|
@ -61,7 +61,7 @@ import java.util.TreeSet;
|
|||
* * no locking: {@link #onUploadAttemptComplete(Set)} deletes the given pings, none of which should be
|
||||
* currently written
|
||||
*/
|
||||
public class TelemetryJSONFilePingStore implements TelemetryPingStore {
|
||||
public class TelemetryJSONFilePingStore extends TelemetryPingStore {
|
||||
private static final String LOGTAG = StringUtils.safeSubstring(
|
||||
"Gecko" + TelemetryJSONFilePingStore.class.getSimpleName(), 0, 23);
|
||||
|
||||
|
@ -76,7 +76,8 @@ public class TelemetryJSONFilePingStore implements TelemetryPingStore {
|
|||
private final FileLastModifiedComparator fileLastModifiedComparator = new FileLastModifiedComparator();
|
||||
|
||||
@WorkerThread // Writes to disk
|
||||
public TelemetryJSONFilePingStore(final File storeDir) {
|
||||
public TelemetryJSONFilePingStore(final File storeDir, final String profileName) {
|
||||
super(profileName);
|
||||
this.storeDir = storeDir;
|
||||
this.storeDir.mkdirs();
|
||||
uuidFilenameFilter = new FilenameRegexFilter(UUIDUtil.UUID_PATTERN);
|
||||
|
@ -243,7 +244,8 @@ public class TelemetryJSONFilePingStore implements TelemetryPingStore {
|
|||
@Override
|
||||
public TelemetryJSONFilePingStore createFromParcel(final Parcel source) {
|
||||
final String storeDirPath = source.readString();
|
||||
return new TelemetryJSONFilePingStore(new File(storeDirPath));
|
||||
final String profileName = source.readString();
|
||||
return new TelemetryJSONFilePingStore(new File(storeDirPath), profileName);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -260,5 +262,6 @@ public class TelemetryJSONFilePingStore implements TelemetryPingStore {
|
|||
@Override
|
||||
public void writeToParcel(final Parcel dest, final int flags) {
|
||||
dest.writeString(storeDir.getAbsolutePath());
|
||||
dest.writeString(getProfileName());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,12 +23,24 @@ import java.util.Set;
|
|||
* The pings in {@link #getAllPings()} and {@link #maybePrunePings()} are returned in the
|
||||
* same order in order to guarantee consistent results.
|
||||
*/
|
||||
public interface TelemetryPingStore extends Parcelable {
|
||||
public abstract class TelemetryPingStore implements Parcelable {
|
||||
private final String profileName;
|
||||
|
||||
public TelemetryPingStore(final String profileName) {
|
||||
this.profileName = profileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the profile name associated with this store.
|
||||
*/
|
||||
public String getProfileName() {
|
||||
return profileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a list of all the telemetry pings in the store that are ready for upload, ascending oldest to newest.
|
||||
*/
|
||||
List<TelemetryPing> getAllPings();
|
||||
public abstract List<TelemetryPing> getAllPings();
|
||||
|
||||
/**
|
||||
* Save a ping to the store.
|
||||
|
@ -36,13 +48,13 @@ public interface TelemetryPingStore extends Parcelable {
|
|||
* @param ping the ping to store
|
||||
* @throws IOException for underlying store access errors
|
||||
*/
|
||||
void storePing(TelemetryPing ping) throws IOException;
|
||||
public abstract void storePing(TelemetryPing ping) throws IOException;
|
||||
|
||||
/**
|
||||
* Removes telemetry pings from the store if there are too many pings or they take up too much space.
|
||||
* Pings should be removed from oldest to newest.
|
||||
*/
|
||||
void maybePrunePings();
|
||||
public abstract void maybePrunePings();
|
||||
|
||||
/**
|
||||
* Removes the successfully uploaded pings from the database and performs another other actions necessary
|
||||
|
@ -50,5 +62,5 @@ public interface TelemetryPingStore extends Parcelable {
|
|||
*
|
||||
* @param successfulRemoveIDs doc ids of pings that were successfully uploaded
|
||||
*/
|
||||
void onUploadAttemptComplete(Set<String> successfulRemoveIDs);
|
||||
public abstract void onUploadAttemptComplete(Set<String> successfulRemoveIDs);
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ public class TestTelemetryJSONFilePingStore {
|
|||
@Before
|
||||
public void setUp() throws Exception {
|
||||
testDir = tempDir.newFolder();
|
||||
testStore = new TelemetryJSONFilePingStore(testDir);
|
||||
testStore = new TelemetryJSONFilePingStore(testDir, "");
|
||||
}
|
||||
|
||||
private ExtendedJSONObject generateTelemetryPayload() {
|
||||
|
|
Загрузка…
Ссылка в новой задаче