Skip to content

Commit

Permalink
[No Bug]: Ancient Migrations - Unused Preference Cleanup (brave/brave…
Browse files Browse the repository at this point in the history
  • Loading branch information
soner-yuksel authored Nov 14, 2023
1 parent c8f90c0 commit a2fc416
Show file tree
Hide file tree
Showing 15 changed files with 1 addition and 405 deletions.
9 changes: 0 additions & 9 deletions App/iOS/Delegates/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

// Set the Safari UA for browsing.
setUserAgent()

// Moving Brave VPN v1 users to v2 type of credentials.
// This is a light operation, can be called at every launch without troubles.
BraveVPN.migrateV1Credentials()

// Fetching details of GRDRegion for Automatic Region selection
BraveVPN.fetchLastUsedRegionDetail()
Expand Down Expand Up @@ -186,11 +182,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
AppState.shared.profile.searchEngines.searchEngineSetup()
}

// Migration of Yahoo Search Engines
if !Preferences.Search.yahooEngineMigrationCompleted.value {
AppState.shared.profile.searchEngines.migrateDefaultYahooSearchEngines()
}

if isFirstLaunch {
Preferences.DAU.installationDate.value = Date()

Expand Down
5 changes: 0 additions & 5 deletions Sources/Brave/Frontend/Browser/Search/OpenSearch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ class OpenSearchEngine: NSObject, NSSecureCoding {

static let defaultSearchClientName = "brave"

// This Identifier is defined to distinguish migrated Open Search Engine
// It is used while filtering out Custom Engines for Private Mode
// All Custom SE's will be filtered out except the one with this identifier
static let migratedYahooEngineID = "yahoo-migrated"

let shortName: String
let referenceURL: String?

Expand Down
90 changes: 0 additions & 90 deletions Sources/Brave/Frontend/Browser/Search/SearchEngines.swift
Original file line number Diff line number Diff line change
Expand Up @@ -347,96 +347,6 @@ public class SearchEngines {
return index1! < index2!
}
}

/// Function for Yahoo Search Engine Migration
/// If Default Search Engine is Yahoo or Yahoo! JAPAN,
/// the engine will be migrated as Custom Search Engine and set as default
/// In Private Mode the default engine will be set as Brave Search
public func migrateDefaultYahooSearchEngines() {
// Checking Standard Tab Engine is Yahoo and create a new custom engine for it
let standardTabEngineName = Preferences.Search.defaultEngineName.value
let privateTabEngineName = Preferences.Search.defaultPrivateEngineName.value

if standardTabEngineName == OpenSearchEngine.EngineNames.yahoo {
createDefaultYahooCustomEngine(isJapan: false, forType: .standard)
} else if standardTabEngineName == OpenSearchEngine.EngineNames.yahooJP {
createDefaultYahooCustomEngine(isJapan: true, forType: .standard)
}

if privateTabEngineName == OpenSearchEngine.EngineNames.yahoo {
createDefaultYahooCustomEngine(isJapan: false, forType: .privateMode)
} else if privateTabEngineName == OpenSearchEngine.EngineNames.yahooJP {
createDefaultYahooCustomEngine(isJapan: true, forType: .privateMode)
}

// Marking Migration completed
Preferences.Search.yahooEngineMigrationCompleted.value = true
}

/// Function for creating Yahoo / Yahoo JAPAN as OpenSearchEngine and setting as default
/// - Parameter isJapan: The boolean to determine Yahoo Engine for JP locale
private func createDefaultYahooCustomEngine(isJapan: Bool, forType type: DefaultEngineType) {

// MARK: SearchEngineDetails

enum SearchEngineDetails {
case yahoo, yahooJapan

var engineName: String {
switch self {
case .yahooJapan:
return "Yahoo! JAPAN"
case .yahoo:
return "Yahoo"
}
}

var engineTemplate: String {
switch self {
case .yahooJapan:
return "https://search.yahoo.co.jp/search?p={searchTerms}"
case .yahoo:
return "https://search.yahoo.com/search?q={searchTerms}"
}
}

var searchEngineImage: UIImage {
switch self {
case .yahooJapan:
return UIImage(named: "faviconYahoo", in: .module, compatibleWith: nil)!
case .yahoo:
return UIImage(named: "faviconYahooJP", in: .module, compatibleWith: nil)!
}
}
}

var engineDetails = SearchEngineDetails.yahoo

if isJapan {
engineDetails = SearchEngineDetails.yahooJapan
}

let searchEngine = OpenSearchEngine(
engineID: OpenSearchEngine.migratedYahooEngineID,
shortName: engineDetails.engineName,
image: engineDetails.searchEngineImage,
searchTemplate: engineDetails.engineTemplate,
isCustomEngine: true)

let customMigrationEngineCreated = customEngines.first(where: {
$0.shortName == searchEngine.shortName
})

if customMigrationEngineCreated == nil {
do {
try addSearchEngine(searchEngine)
} catch {
Logger.module.error("Search Engine migration Failed for \(engineDetails.engineName, privacy: .public)")
}
}

updateDefaultEngine(engineDetails.engineName, forType: type)
}

// MARK: - P3A

Expand Down
35 changes: 0 additions & 35 deletions Sources/Brave/Frontend/Browser/TabManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -875,41 +875,6 @@ class TabManager: NSObject {
return URL(fileURLWithPath: profilePath).appendingPathComponent("tabsState.archive").path
}

static fileprivate func migrateTabsStateArchive() {
guard let oldPath = try? FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false).appendingPathComponent("tabsState.archive").path, FileManager.default.fileExists(atPath: oldPath) else {
return
}

Logger.module.info("Migrating tabsState.archive from ~/Documents to shared container")

guard let profilePath = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: AppInfo.sharedContainerIdentifier)?.appendingPathComponent("profile.profile").path else {
Logger.module.error("Unable to get profile path in shared container to move tabsState.archive")
return
}

let newPath = URL(fileURLWithPath: profilePath).appendingPathComponent("tabsState.archive").path

do {
try FileManager.default.createDirectory(atPath: profilePath, withIntermediateDirectories: true, attributes: nil)
try FileManager.default.moveItem(atPath: oldPath, toPath: newPath)

Logger.module.info("Migrated tabsState.archive to shared container successfully")
} catch let error as NSError {
Logger.module.error("Unable to move tabsState.archive to shared container: \(error.localizedDescription)")
}
}

static func tabArchiveData() -> Data? {
migrateTabsStateArchive()

let tabStateArchivePath = tabsStateArchivePath()
if FileManager.default.fileExists(atPath: tabStateArchivePath) {
return (try? Data(contentsOf: URL(fileURLWithPath: tabStateArchivePath)))
} else {
return nil
}
}

private func preserveScreenshot(for tab: Tab) {
assert(Thread.isMainThread)
if isRestoring { return }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@ class BookmarksViewController: SiteTableViewController, ToolbarUrlActionsProtoco
var items: [UIBarButtonItem?] = [.fixedSpace(5)]
if currentFolder == nil {
items.append(importExportButton)

// Unlike Chromium, old CoreData implementation did not have permanent folders
if !Preferences.Chromium.syncV2BookmarksMigrationCompleted.value {
items.append(.fixedSpace(16))
items.append(addFolderButton)
}
} else {
items.append(addFolderButton)
}
Expand Down
2 changes: 0 additions & 2 deletions Sources/Brave/Frontend/ClientPreferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ extension Preferences {
/// How many times Brave Search websites has asked the user to check whether Brave Search can be set as a default
static let braveSearchDefaultBrowserPromptCount =
Option<Int>(key: "search.brave-search-default-website-prompt", default: 0)
/// Determines Yahoo Search Engine is migration is done
public static let yahooEngineMigrationCompleted = Option<Bool>(key: "search-yahoo-engine-migration-completed", default: false)
}

final public class BraveSearch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ class SearchSettingsTableViewController: UITableViewController {
return SearchEnginePicker(type: type, showCancel: false).then {
// Order alphabetically, so that picker is always consistently ordered.
// Every engine is a valid choice for the default engine, even the current default engine.
// In private mode only custom engines will not be shown excluding migrated Yahoo Search Engine
$0.engines = searchPickerEngines(type: type)
$0.delegate = self
$0.selectedSearchEngineName = searchEngines.defaultEngine(forType: type).shortName
Expand Down
29 changes: 1 addition & 28 deletions Sources/Brave/Migration/Migration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ public class Migration {
Preferences.migratePreferences(keyPrefix: keyPrefix)
Preferences.migrateWalletPreferences()
Preferences.migrateAdAndTrackingProtection()

if !Preferences.Migration.documentsDirectoryCleanupCompleted.value {
documentsDirectoryCleanup()
Preferences.Migration.documentsDirectoryCleanupCompleted.value = true
}

if Preferences.General.isFirstLaunch.value {
if UIDevice.current.userInterfaceIdiom == .phone {
Expand Down Expand Up @@ -57,18 +52,6 @@ public class Migration {

braveCore.syncAPI.enableSyncTypes(syncProfileService: braveCore.syncProfileService)
}

/// Adblock files don't have to be moved, they now have a new directory and will be downloaded there.
/// Downloads folder was nefer used before, it's a leftover from FF.
private func documentsDirectoryCleanup() {
FileManager.default.removeFolder(withName: "abp-data", location: .documentDirectory)
FileManager.default.removeFolder(withName: "https-everywhere-data", location: .documentDirectory)

FileManager.default.moveFile(
sourceName: "CookiesData.json", sourceLocation: .documentDirectory,
destinationName: "CookiesData.json",
destinationLocation: .applicationSupportDirectory)
}

// Migrate from TabMO to SessionTab and SessionWindow
public static func migrateTabStateToWebkitState(diskImageStore: DiskImageStore?) {
Expand Down Expand Up @@ -170,9 +153,7 @@ public class Migration {
if Preferences.Migration.coreDataCompleted.value { return }

TabMO.deleteAllPrivateTabs()

Domain.migrateShieldOverrides()


Preferences.Migration.coreDataCompleted.value = true
}

Expand Down Expand Up @@ -214,11 +195,6 @@ fileprivate extension Preferences {
/// Migration preferences
final class Migration {
static let completed = Option<Bool>(key: "migration.completed", default: false)
/// Old app versions were using documents directory to store app files, database, adblock files.
/// These files are now moved to 'Application Support' folder, and documents directory is left
/// for user downloaded files.
static let documentsDirectoryCleanupCompleted =
Option<Bool>(key: "migration.documents-dir-completed", default: false)
// This is new preference introduced in iOS 1.32.3, tracks whether we should perform database migration.
// It should be called only for users who have not completed the migration beforehand.
// The reason for second migration flag is to first do file system migrations like moving database files,
Expand Down Expand Up @@ -296,9 +272,6 @@ fileprivate extension Preferences {
}
}

// Security
NSKeyedUnarchiver.setClass(AuthenticationKeychainInfo.self, forClassName: "AuthenticationKeychainInfo")

// Shields
migrate(key: "braveBlockAdsAndTracking", to: DeprecatedPreferences.blockAdsAndTracking)
migrate(key: "braveHttpsEverywhere", to: Preferences.Shields.httpsEverywhere)
Expand Down
38 changes: 0 additions & 38 deletions Sources/BraveStrings/BraveStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3310,10 +3310,6 @@ extension Strings {

extension Strings {
public struct Sync {
public static let syncV1DeprecationText =
NSLocalizedString("sync.syncV1DeprecationText", tableName: "BraveShared", bundle: .module,
value: "A new Brave Sync is coming and will affect your setup. Get ready for the upgrade.",
comment: "Text that informs a user about Brave Sync service deprecation.")
public static let bookmarksImportExportPopupTitle =
NSLocalizedString("sync.bookmarksImportPopupErrorTitle", tableName: "BraveShared", bundle: .module,
value: "Bookmarks",
Expand All @@ -3334,47 +3330,13 @@ extension Strings {
NSLocalizedString("sync.bookmarksImportPopupFailureMessage", tableName: "BraveShared", bundle: .module,
value: "Bookmark Import Failed",
comment: "Message of the popup if bookmark import fails.")
public static let v2MigrationInterstitialTitle =
NSLocalizedString("sync.v2MigrationInterstitialTitle", tableName: "BraveShared", bundle: .module,
value: "Bookmarks migration",
comment: "Bookmarks migration website title")
public static let v2MigrationInterstitialPageDescription =
NSLocalizedString("sync.v2MigrationInterstitialPageDescription", tableName: "BraveShared", bundle: .module,
value: "Some of your bookmarks failed to migrate. You can add them back manually.",
comment: "Bookmarks migration website page description")
/// Important: Do NOT change the `KEY` parameter without updating it in
/// BraveCore's brave_bookmarks_importer.mm file.
public static let importFolderName =
NSLocalizedString(
"SyncImportFolderName", tableName: "BraveShared", bundle: .module,
value: "Imported Bookmarks",
comment: "Folder name for where bookmarks are imported into when the root folder is not empty.")
public static let v2MigrationTitle =
NSLocalizedString(
"sync.v2MigrationTitle", tableName: "BraveShared", bundle: .module,
value: "Migration required",
comment: "Title for popup to inform the user that bookmarks migration is required for sync")
public static let v2MigrationMessage =
NSLocalizedString(
"sync.v2MigrationMessage", tableName: "BraveShared", bundle: .module,
value: "In order to use Brave Sync your existing bookmarks must be migrated to use the new system. This operation will not delete your bookmarks.",
comment: "Message for popup to inform the user that bookmarks migration is required for sync")
public static let v2MigrationOKButton =
NSLocalizedString(
"sync.v2MigrationOKButton", tableName: "BraveShared", bundle: .module,
value: "Migrate",
comment: "Button to perform bookmarks migration in order to support sync")
public static let v2MigrationErrorTitle =
NSLocalizedString(
"sync.v2MigrationErrorTitle", tableName: "BraveShared", bundle: .module,
value: "Error",
comment: "Title for popup when the bookmark migration fails")
public static let v2MigrationErrorMessage =
NSLocalizedString(
"sync.v2MigrationErrorMessage", tableName: "BraveShared", bundle: .module,
value: "Failed to migrate bookmarks. Please try again later.",
comment: "Message for popup when the bookmark migration fails")
/// History Migration localization text
public static let syncConfigurationInformationText =
NSLocalizedString(
"sync.syncConfigurationInformationText", tableName: "BraveShared", bundle: .module,
Expand Down
6 changes: 0 additions & 6 deletions Sources/BraveVPN/BraveVPN.swift
Original file line number Diff line number Diff line change
Expand Up @@ -671,10 +671,4 @@ public class BraveVPN {
}
}
}

// MARK: - Migration
public static func migrateV1Credentials() {
// Moving Brave VPN v1 users to v2 type of credentials.
GRDCredentialManager.migrateKeychainItemsToGRDCredential()
}
}
1 change: 0 additions & 1 deletion Sources/Data/models/DataController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public class DataController {

private var initializationCompleted = false

/// IMPORTANT: This must be called after pre 1.12 migration logic has been called.
/// Initialization logic will run only once, then do nothing on subsequent calls to this method.
public func initializeOnce() {
if initializationCompleted { return }
Expand Down
29 changes: 0 additions & 29 deletions Sources/Data/models/Domain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,35 +160,6 @@ public final class Domain: NSManagedObject, CRUD {
return considerAllShieldsOption ? !isAllShieldsOff && isSpecificShieldOn : isSpecificShieldOn
}

public static func migrateShieldOverrides() {
// 1.6 had an unfortunate bug that caused shield overrides to create new Domain objects using `http` regardless
// which would lead to a duplicated Domain object using http that held custom shield overides settings for that
// domain
//
// Therefore we need to migrate any `http` Domains shield overrides to its sibiling `https` domain if it exists
let allHttpPredicate = NSPredicate(format: "url BEGINSWITH[cd] 'http://'")

DataController.perform { context in
guard let httpDomains = Domain.all(where: allHttpPredicate, context: context) else {
return
}

for domain in httpDomains {
guard var urlComponents = domain.urlComponents else { continue }
urlComponents.scheme = "https"
guard let httpsUrl = urlComponents.url?.absoluteString else { continue }
if let httpsDomain = Domain.first(where: NSPredicate(format: "url == %@", httpsUrl), context: context) {
httpsDomain.shield_allOff = domain.shield_allOff
httpsDomain.shield_adblockAndTp = domain.shield_adblockAndTp
httpsDomain.shield_noScript = domain.shield_noScript
httpsDomain.shield_fpProtection = domain.shield_fpProtection
httpsDomain.shield_safeBrowsing = domain.shield_safeBrowsing
// Could call `domain.delete()` here (or add to batch to delete)
}
}
}
}

public static func clearInMemoryDomains() {
Domain.deleteAll(predicate: nil, context: .new(inMemory: true))
}
Expand Down
Loading

0 comments on commit a2fc416

Please sign in to comment.