Bug 1651672 - Clear and remove DataStorageClass::TRRBlacklist r=kershaw,necko-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D86520
This commit is contained in:
Valentin Gosu 2020-08-10 09:46:32 +00:00
Родитель d177afdd2a
Коммит 5e3e1f6296
3 изменённых файлов: 44 добавлений и 1 удалений

Просмотреть файл

@ -8271,6 +8271,14 @@
value: true
mirror: always
# If this pref is false, a task will be dispatched to remove the file from the
# disk and the pref will be set to true.
# It can probably be removed after a few releases.
- name: network.trr.blocklist_cleanup_done
type: RelaxedAtomicBool
value: false
mirror: always
# Allow the network changed event to get sent when a network topology or setup
# change is noticed while running.
- name: network.notify.changed

Просмотреть файл

@ -3,6 +3,7 @@
* 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/. */
#include "nsAppDirectoryServiceDefs.h"
#include "nsCharSeparatedTokenizer.h"
#include "nsComponentManagerUtils.h"
#include "nsICaptivePortalService.h"
@ -119,6 +120,32 @@ const nsCString& TRRService::AutoDetectedKey() {
return kTRRNotAutoDetectedKey.AsString();
}
static void RemoveTRRBlocklistFile() {
MOZ_ASSERT(NS_IsMainThread(), "Getting the profile dir on the main thread");
nsCOMPtr<nsIFile> file;
nsresult rv =
NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(file));
if (NS_FAILED(rv)) {
return;
}
rv = file->AppendNative("TRRBlacklist.txt"_ns);
if (NS_FAILED(rv)) {
return;
}
// Dispatch an async task that removes the blocklist file from the profile.
rv = NS_DispatchBackgroundTask(
NS_NewRunnableFunction("RemoveTRRBlocklistFile::Remove",
[file] { file->Remove(false); }),
NS_DISPATCH_EVENT_MAY_BLOCK);
if (NS_FAILED(rv)) {
return;
}
Preferences::SetBool("network.trr.blocklist_cleanup_done", true);
}
nsresult TRRService::Init() {
MOZ_ASSERT(NS_IsMainThread(), "wrong thread");
if (mInitialized) {
@ -163,6 +190,15 @@ nsresult TRRService::Init() {
}
sTRRBackgroundThread = thread;
if (!StaticPrefs::network_trr_blocklist_cleanup_done()) {
// Dispatch an idle task to the main thread that gets the profile dir
// then attempts to delete the blocklist file on a background thread.
Unused << NS_DispatchToMainThreadQueue(
NS_NewCancelableRunnableFunction("RemoveTRRBlocklistFile::GetDir",
[] { RemoveTRRBlocklistFile(); }),
EventQueuePriority::Idle);
}
}
LOG(("Initialized TRRService\n"));

Просмотреть файл

@ -17,4 +17,3 @@ DATA_STORAGE(AlternateServices)
DATA_STORAGE(ClientAuthRememberList)
DATA_STORAGE(SecurityPreloadState)
DATA_STORAGE(SiteSecurityServiceState)
DATA_STORAGE(TRRBlacklist)