Skip to content

Commit 9e4064a

Browse files
committed
Migrate user-agent to DatabaseProvider
1 parent 57780b3 commit 9e4064a

File tree

5 files changed

+25
-15
lines changed

5 files changed

+25
-15
lines changed

user-agent/user-agent-impl/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ dependencies {
3030
implementation project(':di')
3131
implementation project(':common-utils')
3232
implementation project(':browser-api')
33+
implementation project(':data-store-api')
3334
implementation project(':feature-toggles-api')
3435
implementation project(':privacy-config-api')
3536
implementation project(':app-build-config-api')

user-agent/user-agent-impl/src/main/java/com/duckduckgo/user/agent/impl/di/ClientBrandHintModule.kt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
package com.duckduckgo.user.agent.impl.di
1818

19-
import android.content.Context
20-
import androidx.room.Room
19+
import com.duckduckgo.data.store.api.DatabaseProvider
20+
import com.duckduckgo.data.store.api.RoomDatabaseConfig
2121
import com.duckduckgo.di.scopes.AppScope
2222
import com.duckduckgo.user.agent.impl.store.ALL_MIGRATIONS
2323
import com.duckduckgo.user.agent.impl.store.ClientBrandHintDatabase
@@ -32,10 +32,14 @@ class ClientBrandHintModule {
3232

3333
@Provides
3434
@SingleInstanceIn(AppScope::class)
35-
fun provideClientHintDatabase(context: Context): ClientBrandHintDatabase {
36-
return Room.databaseBuilder(context, ClientBrandHintDatabase::class.java, "clientbrandhints.db")
37-
.fallbackToDestructiveMigration()
38-
.addMigrations(*ALL_MIGRATIONS)
39-
.build()
35+
fun provideClientBrandHintDatabase(databaseProvider: DatabaseProvider): ClientBrandHintDatabase {
36+
return databaseProvider.buildRoomDatabase(
37+
ClientBrandHintDatabase::class.java,
38+
"client_brand_hint.db",
39+
config = RoomDatabaseConfig(
40+
fallbackToDestructiveMigration = true,
41+
migrations = ALL_MIGRATIONS,
42+
),
43+
)
4044
}
4145
}

user-agent/user-agent-impl/src/main/java/com/duckduckgo/user/agent/impl/di/UserAgentModule.kt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ package com.duckduckgo.user.agent.impl.di
1818

1919
import android.content.Context
2020
import android.webkit.WebSettings
21-
import androidx.room.Room
2221
import com.duckduckgo.app.di.AppCoroutineScope
2322
import com.duckduckgo.app.di.IsMainProcess
2423
import com.duckduckgo.common.utils.DispatcherProvider
24+
import com.duckduckgo.data.store.api.DatabaseProvider
25+
import com.duckduckgo.data.store.api.RoomDatabaseConfig
2526
import com.duckduckgo.di.scopes.AppScope
2627
import com.duckduckgo.user.agent.impl.RealUserAgentProvider
2728
import com.duckduckgo.user.agent.store.ALL_MIGRATIONS
@@ -85,10 +86,14 @@ class UserAgentModule {
8586

8687
@SingleInstanceIn(AppScope::class)
8788
@Provides
88-
fun provideDatabase(context: Context): UserAgentDatabase {
89-
return Room.databaseBuilder(context, UserAgentDatabase::class.java, "user_agent.db")
90-
.fallbackToDestructiveMigration()
91-
.addMigrations(*ALL_MIGRATIONS)
92-
.build()
89+
fun provideUserAgentDatabase(databaseProvider: DatabaseProvider): UserAgentDatabase {
90+
return databaseProvider.buildRoomDatabase(
91+
UserAgentDatabase::class.java,
92+
"user_agent.db",
93+
config = RoomDatabaseConfig(
94+
fallbackToDestructiveMigration = true,
95+
migrations = ALL_MIGRATIONS,
96+
),
97+
)
9398
}
9499
}

user-agent/user-agent-impl/src/main/java/com/duckduckgo/user/agent/impl/store/ClientBrandHintDatabase.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ abstract class ClientBrandHintDatabase : RoomDatabase() {
3232
abstract fun clientBrandHintDao(): ClientBrandHintDao
3333
}
3434

35-
val ALL_MIGRATIONS = emptyArray<Migration>()
35+
val ALL_MIGRATIONS = emptyList<Migration>()

user-agent/user-agent-store/src/main/java/com/duckduckgo/user/agent/store/UserAgentDatabase.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ abstract class UserAgentDatabase : RoomDatabase() {
3131
abstract fun userAgentExceptionsDao(): UserAgentExceptionsDao
3232
}
3333

34-
val ALL_MIGRATIONS = emptyArray<Migration>()
34+
val ALL_MIGRATIONS = emptyList<Migration>()

0 commit comments

Comments
 (0)