<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.mozstumbler.client.leaderboard;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.support.v4.content.LocalBroadcastManager;

import org.mozilla.mozstumbler.client.ClientPrefs;
import org.mozilla.mozstumbler.service.stumblerthread.Reporter;
import org.mozilla.mozstumbler.service.stumblerthread.datahandling.StumblerBundle;
import org.mozilla.mozstumbler.service.uploadthread.AsyncUploadParam;
import org.mozilla.mozstumbler.service.uploadthread.AsyncUploader;
import org.mozilla.mozstumbler.service.uploadthread.AsyncUploaderMLS;

public class LBStumblerBundleReceiver extends BroadcastReceiver {
    class UploadingOccurringReceiver extends BroadcastReceiver {
        LBUploadTask mUploadTask;

        @Override
        public void onReceive(Context context, Intent intent) {
            // start this upload
            if (mUploadTask != null &&
                    AsyncUploader.isUploading.get()) {
                return;
            }

            mUploadTask = new LBUploadTask(mStorage);
            boolean ignoredValue = false;
            AsyncUploadParam params = new AsyncUploadParam(ignoredValue, ignoredValue, null, null);
            mUploadTask.execute(params);
        }
    }

    final LBDataStorage mStorage;
    final UploadingOccurringReceiver mUploadTrigger = new UploadingOccurringReceiver();

    public LBStumblerBundleReceiver(Context c) {
        mStorage = new LBDataStorage(c);

        LocalBroadcastManager.getInstance(c).registerReceiver(this,
                new IntentFilter(Reporter.ACTION_NEW_BUNDLE));

        LocalBroadcastManager.getInstance(c).registerReceiver(mUploadTrigger,
                new IntentFilter(AsyncUploaderMLS.ACTION_MLS_UPLOAD_COMPLETED));

    }

    @Override
    public void onReceive(Context context, Intent intent) {
        final StumblerBundle bundle = intent.getParcelableExtra(Reporter.NEW_BUNDLE_ARG_BUNDLE);
        mStorage.insert(bundle.getGpsPosition());
    }
}<commit_msg>added guards around the leaderboard<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.mozstumbler.client.leaderboard;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.support.v4.content.LocalBroadcastManager;

import org.mozilla.mozstumbler.client.ClientPrefs;
import org.mozilla.mozstumbler.service.Prefs;
import org.mozilla.mozstumbler.service.stumblerthread.Reporter;
import org.mozilla.mozstumbler.service.stumblerthread.datahandling.StumblerBundle;
import org.mozilla.mozstumbler.service.uploadthread.AsyncUploadParam;
import org.mozilla.mozstumbler.service.uploadthread.AsyncUploader;
import org.mozilla.mozstumbler.service.uploadthread.AsyncUploaderMLS;

public class LBStumblerBundleReceiver extends BroadcastReceiver {
    class UploadingOccurringReceiver extends BroadcastReceiver {
        LBUploadTask mUploadTask;

        @Override
        public void onReceive(Context context, Intent intent) {
            // Guard against LeaderBoard intents when we're not logged into FxA
            if (Prefs.getInstance(context).getBearerToken() == null) {
                return;
            }

            // start this upload
            if (mUploadTask != null &&
                    AsyncUploader.isUploading.get()) {
                return;
            }

            mUploadTask = new LBUploadTask(mStorage);
            boolean ignoredValue = false;
            AsyncUploadParam params = new AsyncUploadParam(ignoredValue, ignoredValue, null, null);
            mUploadTask.execute(params);
        }
    }

    final LBDataStorage mStorage;
    final UploadingOccurringReceiver mUploadTrigger = new UploadingOccurringReceiver();

    public LBStumblerBundleReceiver(Context c) {
        mStorage = new LBDataStorage(c);

        LocalBroadcastManager.getInstance(c).registerReceiver(this,
                new IntentFilter(Reporter.ACTION_NEW_BUNDLE));

        LocalBroadcastManager.getInstance(c).registerReceiver(mUploadTrigger,
                new IntentFilter(AsyncUploaderMLS.ACTION_MLS_UPLOAD_COMPLETED));
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        // Guard against LeaderBoard intents when we're not logged into FxA
        if (Prefs.getInstance(context).getBearerToken() != null) {
            final StumblerBundle bundle = intent.getParcelableExtra(Reporter.NEW_BUNDLE_ARG_BUNDLE);
            mStorage.insert(bundle.getGpsPosition());
        }
    }
}
{'fraction_non_alphanumeric': 0.07811877241929055, 'fraction_numerical': 0.0019928258270227183, 'mean_word_length': 3.4026315789473682, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6101863', 'n_tokens_mistral': 1418, 'n_tokens_neox': 1360, 'n_words': 295}