Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | package org.mozilla.gecko.fxa.receivers; |
michael@0 | 6 | |
michael@0 | 7 | import org.mozilla.gecko.background.common.log.Logger; |
michael@0 | 8 | import org.mozilla.gecko.fxa.FxAccountConstants; |
michael@0 | 9 | import org.mozilla.gecko.sync.config.AccountPickler; |
michael@0 | 10 | |
michael@0 | 11 | import android.app.IntentService; |
michael@0 | 12 | import android.content.Context; |
michael@0 | 13 | import android.content.Intent; |
michael@0 | 14 | |
michael@0 | 15 | /** |
michael@0 | 16 | * A background service to clean up after a Firefox Account is deleted. |
michael@0 | 17 | * <p> |
michael@0 | 18 | * Note that we specifically handle deleting the pickle file using a Service and a |
michael@0 | 19 | * BroadcastReceiver, rather than a background thread, to allow channels sharing a Firefox account |
michael@0 | 20 | * to delete their respective pickle files (since, if one remains, the account will be restored |
michael@0 | 21 | * when that channel is used). |
michael@0 | 22 | */ |
michael@0 | 23 | public class FxAccountDeletedService extends IntentService { |
michael@0 | 24 | public static final String LOG_TAG = FxAccountDeletedService.class.getSimpleName(); |
michael@0 | 25 | |
michael@0 | 26 | public FxAccountDeletedService() { |
michael@0 | 27 | super(LOG_TAG); |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | @Override |
michael@0 | 31 | protected void onHandleIntent(final Intent intent) { |
michael@0 | 32 | // Intent can, in theory, be null. Bug 1025937. |
michael@0 | 33 | if (intent == null) { |
michael@0 | 34 | Logger.debug(LOG_TAG, "Short-circuiting on null intent."); |
michael@0 | 35 | return; |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | final Context context = this; |
michael@0 | 39 | |
michael@0 | 40 | long intentVersion = intent.getLongExtra( |
michael@0 | 41 | FxAccountConstants.ACCOUNT_DELETED_INTENT_VERSION_KEY, 0); |
michael@0 | 42 | long expectedVersion = FxAccountConstants.ACCOUNT_DELETED_INTENT_VERSION; |
michael@0 | 43 | if (intentVersion != expectedVersion) { |
michael@0 | 44 | Logger.warn(LOG_TAG, "Intent malformed: version " + intentVersion + " given but " + |
michael@0 | 45 | "version " + expectedVersion + "expected. Not cleaning up after deleted Account."); |
michael@0 | 46 | return; |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | // Android Account name, not Sync encoded account name. |
michael@0 | 50 | final String accountName = intent.getStringExtra( |
michael@0 | 51 | FxAccountConstants.ACCOUNT_DELETED_INTENT_ACCOUNT_KEY); |
michael@0 | 52 | if (accountName == null) { |
michael@0 | 53 | Logger.warn(LOG_TAG, "Intent malformed: no account name given. Not cleaning up after " + |
michael@0 | 54 | "deleted Account."); |
michael@0 | 55 | return; |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | Logger.info(LOG_TAG, "Firefox account named " + accountName + " being removed; " + |
michael@0 | 59 | "deleting saved pickle file '" + FxAccountConstants.ACCOUNT_PICKLE_FILENAME + "'."); |
michael@0 | 60 | deletePickle(context); |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | public static void deletePickle(final Context context) { |
michael@0 | 64 | try { |
michael@0 | 65 | AccountPickler.deletePickle(context, FxAccountConstants.ACCOUNT_PICKLE_FILENAME); |
michael@0 | 66 | } catch (Exception e) { |
michael@0 | 67 | // This should never happen, but we really don't want to die in a background thread. |
michael@0 | 68 | Logger.warn(LOG_TAG, "Got exception deleting saved pickle file; ignoring.", e); |
michael@0 | 69 | } |
michael@0 | 70 | } |
michael@0 | 71 | } |