<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/. */

var EXPORTED_SYMBOLS = ["ComposeWindowGlobalCounter"];

const Cu = Components.utils;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this,
                                  "prefs",
                                  "resource://tb-bug766495-modules/lib/prefs.js");

var _oldPurgeAsk, _oldPurgeThresholdMB;
var ComposeWindowGlobalCounter = {
  _counter: 0,
  opened: function() {
    this._counter++;
    this.tryStoreOldPrefs();
    this.disableAutoCompaction();
  },
  closed: function() {
    this._counter--;
    this.tryRestoreOldPrefs();
  },
  clear: function() {
    this._counter = 0;
  },
  hasStoredPrefs: function() {
    return !(_oldPurgeAsk === undefined && _oldPurgeThresholdMB === undefined);
  },
  tryStoreOldPrefs: function() {
    if (this.hasStoredPrefs() || this._counter <= 0)
      return;

    _oldPurgeAsk = prefs.getPref("mail.purge.ask");
    _oldPurgeThresholdMB = prefs.getPref("mail.purge_threshhold_mb");
  },
  disableAutoCompaction: function() {
    prefs.setPref("mail.purge.ask", true);
    prefs.setPref("mail.purge_threshhold_mb", 1000 * 1000);
  },
  tryRestoreOldPrefs: function (){
    if (!this.hasStoredPrefs() || this._counter > 0)
      return;
<commit_msg>Use more meaningful names<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/. */

var EXPORTED_SYMBOLS = ["ComposeWindowGlobalCounter"];

const Cu = Components.utils;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this,
                                  "prefs",
                                  "resource://tb-bug766495-modules/lib/prefs.js");

var _oldPurgeAsk, _oldPurgeThresholdMB;
var ComposeWindowGlobalCounter = {
  _counter: 0,
  opened: function() {
    this._counter++;
    this.deactivateAutoCompaction();
  },
  closed: function() {
    this._counter--;
    this.activateAutoCompaction();
  },
  clear: function() {
    this._counter = 0;
  },
  hasStoredPrefs: function() {
    return !(_oldPurgeAsk === undefined && _oldPurgeThresholdMB === undefined);
  },
  deactivateAutoCompaction: function() {
    if (this.hasStoredPrefs() || this._counter <= 0)
      return;

    _oldPurgeAsk = prefs.getPref("mail.purge.ask");
    _oldPurgeThresholdMB = prefs.getPref("mail.purge_threshhold_mb");
    prefs.setPref("mail.purge.ask", true);
    prefs.setPref("mail.purge_threshhold_mb", 1000 * 1000);
  },
  activateAutoCompaction: function (){
    if (!this.hasStoredPrefs() || this._counter > 0)
      return;

{'fraction_non_alphanumeric': 0.13536966331135022, 'fraction_numerical': 0.015272474835126693, 'mean_word_length': 3.2507374631268435, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7577069', 'n_tokens_mistral': 990, 'n_tokens_neox': 929, 'n_words': 194}