Skip to content

Commit

Permalink
Reorganize classes
Browse files Browse the repository at this point in the history
  • Loading branch information
CrisBarreiro committed Dec 10, 2024
1 parent b313a61 commit 212e3b7
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ package com.duckduckgo.malicioussiteprotection.impl
import android.content.Context
import androidx.room.Room
import com.duckduckgo.di.scopes.AppScope
import com.duckduckgo.malicioussiteprotection.impl.MaliciousSitesDatabase.Companion.ALL_MIGRATIONS
import com.duckduckgo.malicioussiteprotection.impl.data.db.MaliciousSiteDao
import com.duckduckgo.malicioussiteprotection.impl.data.db.MaliciousSitesDatabase
import com.duckduckgo.malicioussiteprotection.impl.data.db.MaliciousSitesDatabase.Companion.ALL_MIGRATIONS
import com.squareup.anvil.annotations.ContributesTo
import dagger.Module
import dagger.Provides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@
* limitations under the License.
*/

package com.duckduckgo.malicioussiteprotection.impl
package com.duckduckgo.malicioussiteprotection.impl.data

import com.duckduckgo.app.di.AppCoroutineScope
import com.duckduckgo.app.di.IsMainProcess
import com.duckduckgo.common.utils.DispatcherProvider
import com.duckduckgo.di.scopes.AppScope
import com.duckduckgo.malicioussiteprotection.impl.MaliciousSiteProtectionFeature
import com.duckduckgo.malicioussiteprotection.impl.data.db.MaliciousSiteDao
import com.duckduckgo.malicioussiteprotection.impl.data.embedded.MaliciousSiteProtectionEmbeddedDataProvider
import com.squareup.anvil.annotations.ContributesBinding
import dagger.SingleInstanceIn
import javax.inject.Inject
Expand Down Expand Up @@ -69,9 +72,9 @@ class RealMaliciousSiteRepository @Inject constructor(
phishingHashPrefixesRevision = embeddedPhishingHashPrefixes?.revision,
malwareHashPrefixesRevision = embeddedMalwareHashPrefixes?.revision,
phishingHashPrefixes = embeddedPhishingHashPrefixes?.insert?.toSet() ?: setOf(),
phishingFilterSet = embeddedPhishingFilterSet?.insert?.map { FilterEntity(it.hash, it.regex, type = "phishing") }?.toSet() ?: setOf(),
phishingFilterSet = embeddedPhishingFilterSet?.insert ?: setOf(),
malwareHashPrefixes = embeddedMalwareHashPrefixes?.insert?.toSet() ?: setOf(),
malwareFilterSet = embeddedMalwareFilterSet?.insert?.map { FilterEntity(it.hash, it.regex, type = "malware") }?.toSet() ?: setOf(),
malwareFilterSet = embeddedMalwareFilterSet?.insert ?: setOf(),
)
}

Expand All @@ -85,3 +88,29 @@ class RealMaliciousSiteRepository @Inject constructor(
}
}
}

data class Match(
val hostname: String,
val url: String,
val regex: String,
val hash: String,
)

data class HashPrefixResponse(
val insert: Set<String>,
val delete: Set<String>,
val revision: Int,
val replace: Boolean,
)

data class FilterSetResponse(
val insert: Set<Filter>,
val delete: Set<Filter>,
val revision: Int,
val replace: Boolean,
)

data class Filter(
val hash: String,
val regex: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
* limitations under the License.
*/

package com.duckduckgo.malicioussiteprotection.impl
package com.duckduckgo.malicioussiteprotection.impl.data.db

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Transaction
import com.duckduckgo.malicioussiteprotection.impl.data.Filter
import kotlin.math.max

@Dao
Expand Down Expand Up @@ -76,9 +77,9 @@ interface MaliciousSiteDao {
phishingHashPrefixesRevision: Int?,
malwareHashPrefixesRevision: Int?,
phishingHashPrefixes: Set<String>,
phishingFilterSet: Set<FilterEntity>,
phishingFilterSet: Set<Filter>,
malwareHashPrefixes: Set<String>,
malwareFilterSet: Set<FilterEntity>,
malwareFilterSet: Set<Filter>,
) {
val lastRevision = getLatestRevision()
deleteRevisions()
Expand All @@ -92,8 +93,8 @@ interface MaliciousSiteDao {
),
)
insertHashPrefixes(phishingHashPrefixes.map { HashPrefixEntity(hashPrefix = it, type = "phishing") })
insertFilters(phishingFilterSet)
insertFilters(phishingFilterSet.map { FilterEntity(it.hash, it.regex, type = "phishing") }.toSet())
insertHashPrefixes(malwareHashPrefixes.map { HashPrefixEntity(hashPrefix = it, type = "malware") })
insertFilters(malwareFilterSet)
insertFilters(malwareFilterSet.map { FilterEntity(it.hash, it.regex, type = "malware") }.toSet())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.duckduckgo.malicioussiteprotection.impl
package com.duckduckgo.malicioussiteprotection.impl.data.db

import androidx.room.Entity
import androidx.room.PrimaryKey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.duckduckgo.malicioussiteprotection.impl
package com.duckduckgo.malicioussiteprotection.impl.data.db

import androidx.room.Database
import androidx.room.RoomDatabase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@
* limitations under the License.
*/

package com.duckduckgo.malicioussiteprotection.impl
package com.duckduckgo.malicioussiteprotection.impl.data.embedded

import android.content.Context
import androidx.annotation.RawRes
import com.duckduckgo.di.scopes.AppScope
import com.duckduckgo.malicioussiteprotection.impl.R
import com.duckduckgo.malicioussiteprotection.impl.data.FilterSetResponse
import com.duckduckgo.malicioussiteprotection.impl.data.HashPrefixResponse
import com.squareup.anvil.annotations.ContributesBinding
import com.squareup.moshi.Moshi
import javax.inject.Inject
Expand Down Expand Up @@ -84,29 +87,3 @@ class RealMaliciousSiteProtectionEmbeddedDataProvider @Inject constructor(
}
}
}

data class Match(
val hostname: String,
val url: String,
val regex: String,
val hash: String,
)

data class HashPrefixResponse(
val insert: Set<String>,
val delete: Set<String>,
val revision: Int,
val replace: Boolean,
)

data class FilterSetResponse(
val insert: Set<Filter>,
val delete: Set<Filter>,
val revision: Int,
val replace: Boolean,
)

data class Filter(
val hash: String,
val regex: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
* limitations under the License.
*/

package com.duckduckgo.malicioussiteprotection.impl
package com.duckduckgo.malicioussiteprotection.impl.domain

import android.net.Uri
import com.duckduckgo.app.di.AppCoroutineScope
import com.duckduckgo.app.di.IsMainProcess
import com.duckduckgo.common.utils.DispatcherProvider
import com.duckduckgo.di.scopes.AppScope
import com.duckduckgo.malicioussiteprotection.api.MaliciousSiteProtection
import com.duckduckgo.malicioussiteprotection.impl.MaliciousSiteProtectionFeature
import com.duckduckgo.privacy.config.api.PrivacyConfigCallbackPlugin
import com.squareup.anvil.annotations.ContributesBinding
import com.squareup.anvil.annotations.ContributesMultibinding
Expand Down

0 comments on commit 212e3b7

Please sign in to comment.