Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
If ledger not enabled, honor settings for clearing history
Browse files Browse the repository at this point in the history
Fixes #8495
  • Loading branch information
mrose17 authored and NejcZdovc committed Apr 26, 2017
1 parent 814f6f7 commit 1f0d260
Show file tree
Hide file tree
Showing 3 changed files with 210 additions and 66 deletions.
85 changes: 40 additions & 45 deletions app/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
module entry points:
init() - called by app/index.js to start module
quit() - .. .. .. .. prior to browser quitting
boot() - .. .. .. .. to create wallet
boot() - .. .. .. .. to create wallet
reset() - .. .. .. .. to remove state
IPC entry point:
LEDGER_PUBLISHER - called synchronously by app/extensions/brave/content/scripts/pageInformation.js
CHANGE_SETTING - called asynchronously to record a settings change
LEDGER_PUBLISHER - called synchronously by app/extensions/brave/content/scripts/pageInformation.js
CHANGE_SETTING - called asynchronously to record a settings change
eventStore entry point:
addChangeListener - called when tabs render or gain focus
Expand Down Expand Up @@ -105,6 +106,7 @@ const clientOptions = {
}

var doneTimer
var quitP

var v2RulesetDB
const v2RulesetPath = 'ledger-rulesV2.leveldb'
Expand Down Expand Up @@ -165,6 +167,10 @@ const doAction = (action) => {
quit()
break

case appConstants.APP_CLEAR_HISTORY:
if (!getSetting(settings.PAYMENTS_ENABLED)) reset(true)
break

case appConstants.APP_IDLE_STATE_CHANGED:
visit('NOOP', underscore.now(), null)
break
Expand Down Expand Up @@ -263,19 +269,23 @@ const doAction = (action) => {
/*
* module entry points
*/

var init = () => {
try {
appDispatcher.register(doAction)
initialize(getSetting(settings.PAYMENTS_ENABLED))

doneTimer = setInterval(doneWriter, 1 * msecs.hour)
doneTimer = setInterval(doneWriter, 1 * msecs.minute)
} catch (ex) { console.log('ledger.js initialization failed: ' + ex.toString() + '\n' + ex.stack) }
}

var quit = () => {
quitP = true
visit('NOOP', underscore.now(), null)
clearInterval(doneTimer)
doneWriter()

if ((!getSetting(settings.PAYMENTS_ENABLED)) && (getSetting(settings.SHUTDOWN_CLEAR_HISTORY))) reset(true)
}

var boot = () => {
Expand Down Expand Up @@ -305,6 +315,17 @@ var boot = () => {
})
}

var reset = (doneP) => {
var files = [ logPath, publisherPath, scoresPath, synopsisPath ]

if (!doneP) files.push(statePath)
files.forEach((file) => {
fs.unlink(pathName(file), (err) => {
if ((err) && (err.code !== 'ENOENT')) console.log(err)
})
})
}

/*
* Print or Save Recovery Keys
*/
Expand Down Expand Up @@ -811,29 +832,8 @@ var enable = (paymentsEnabled) => {
// change undefined include publishers to include publishers
appActions.enableUndefinedPublishers(synopsis.publishers)

fs.readFile(pathName(publisherPath), (err, data) => {
if (err) {
if (err.code !== 'ENOENT') console.log('publisherPath read error: ' + err.toString())
return
}

if (publisherInfo._internal.verboseP) console.log('\nfound ' + pathName(publisherPath))
try {
data = JSON.parse(data)
underscore.keys(data).sort().forEach((publisher) => {
var entries = data[publisher]

publishers[publisher] = {}
entries.forEach((entry) => {
locations[entry.location] = entry
publishers[publisher][entry.location] = { timestamp: entry.when, tabIds: [] }
updateLocation(entry.location, publisher)
})
})
} catch (ex) {
console.log('publishersPath parse error: ' + ex.toString())
}
})
fs.unlink(pathName(publisherPath), (err) => { if ((err) && (err.code !== 'ENOENT')) console.log(err) })
fs.unlink(pathName(scoresPath), (err) => { if ((err) && (err.code !== 'ENOENT')) console.log(err) })
})
}

Expand Down Expand Up @@ -978,22 +978,7 @@ const fetchFavIcon = (entry, url, redirects) => {
}

var updatePublisherInfo = (changedPublisher) => {
var data = {}
var then = underscore.now() - msecs.week

underscore.keys(publishers).sort().forEach((publisher) => {
var entries = []

underscore.keys(publishers[publisher]).forEach((location) => {
var when = publishers[publisher][location].timestamp

if (when > then) entries.push({ location: location, when: when })
})

if (entries.length > 0) data[publisher] = entries
})
atomicWriter(pathName(publisherPath), data, () => {})
atomicWriter(pathName(scoresPath), synopsis.allN(), () => {})
var data

atomicWriter(pathName(synopsisPath), synopsis, () => {})
if (!publisherInfo._internal.enabled) return
Expand Down Expand Up @@ -2144,6 +2129,15 @@ var atomicWriter = (path, obj, options, cb) => {
return cb(err)
}

if ((quitP) && (!getSetting(settings.PAYMENTS_ENABLED)) && (getSetting(settings.SHUTDOWN_CLEAR_HISTORY))) {
if (ledgerInfo._internal.debugP) console.log('\ndeleting ' + path + suffix)
fs.unlink(path + suffix, (err) => {
if (err) console.log('unlink error: ' + err.toString())
cb(err)
})
return
}

if (ledgerInfo._internal.debugP) console.log('\nrenaming ' + path + suffix)
fs.rename(path + suffix, path, (err) => {
if (err) console.log('rename error: ' + err.toString())
Expand Down Expand Up @@ -2171,7 +2165,7 @@ var pathName = (name) => {
return path.join(app.getPath('userData'), parts.name + parts.ext)
}

/**
/*
* UI controller functionality
*/

Expand Down Expand Up @@ -2314,5 +2308,6 @@ module.exports = {
recoverKeys: recoverKeys,
backupKeys: backupKeys,
quit: quit,
boot: boot
boot: boot,
reset: reset
}
2 changes: 1 addition & 1 deletion js/about/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ class SecurityTab extends ImmutableComponent {
return <div>
<DefaultSectionTitle data-l10n-id='privateData' />
<SettingsList dataL10nId='privateDataMessage'>
<SettingCheckbox dataL10nId='browsingHistory' prefKey={settings.SHUTDOWN_CLEAR_HISTORY} settings={this.props.settings} onChangeSetting={this.props.onChangeSetting} />
<SettingCheckbox dataTestId='clearBrowsingHistory' dataL10nId='browsingHistory' prefKey={settings.SHUTDOWN_CLEAR_HISTORY} settings={this.props.settings} onChangeSetting={this.props.onChangeSetting} />
<SettingCheckbox dataL10nId='downloadHistory' prefKey={settings.SHUTDOWN_CLEAR_DOWNLOADS} settings={this.props.settings} onChangeSetting={this.props.onChangeSetting} />
<SettingCheckbox dataL10nId='cachedImagesAndFiles' prefKey={settings.SHUTDOWN_CLEAR_CACHE} settings={this.props.settings} onChangeSetting={this.props.onChangeSetting} />
<SettingCheckbox dataL10nId='allSiteCookies' prefKey={settings.SHUTDOWN_CLEAR_ALL_SITE_COOKIES} settings={this.props.settings} onChangeSetting={this.props.onChangeSetting} />
Expand Down
Loading

0 comments on commit 1f0d260

Please sign in to comment.