mirror of
https://github.com/bitwarden/android.git
synced 2024-10-31 07:05:35 +03:00
PM-1271 Removed StorageMediatorOptions and go to a plain parameters based approach (#2397)
This commit is contained in:
parent
a81dfc271c
commit
3f86bb0cd7
3 changed files with 13 additions and 21 deletions
|
@ -9,8 +9,8 @@ namespace Bit.Core.Abstractions
|
|||
void Save<T>(string key, T obj);
|
||||
void Remove(string key);
|
||||
|
||||
Task<T> GetAsync<T>(string key, StorageMediatorOptions options = default);
|
||||
Task SaveAsync<T>(string key, T obj, StorageMediatorOptions options = default);
|
||||
Task RemoveAsync(string key, StorageMediatorOptions options = default);
|
||||
Task<T> GetAsync<T>(string key, bool useSecureStorage = false);
|
||||
Task SaveAsync<T>(string key, T obj, bool useSecureStorage = false, bool allowSaveNull = false);
|
||||
Task RemoveAsync(string key, bool useSecureStorage = false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
namespace Bit.Core.Services
|
||||
{
|
||||
public struct StorageMediatorOptions
|
||||
{
|
||||
public bool UseSecureStorage { get; set; }
|
||||
public bool AllowSaveNull { get; set; }
|
||||
}
|
||||
}
|
|
@ -33,30 +33,30 @@ namespace Bit.Core.Services
|
|||
_synchronousStorageService.Remove(key);
|
||||
}
|
||||
|
||||
public Task<T> GetAsync<T>(string key, StorageMediatorOptions options = default)
|
||||
public Task<T> GetAsync<T>(string key, bool useSecureStorage = false)
|
||||
{
|
||||
return GetAsyncStorage(options).GetAsync<T>(key);
|
||||
return GetAsyncStorage(useSecureStorage).GetAsync<T>(key);
|
||||
}
|
||||
|
||||
public async Task SaveAsync<T>(string key, T obj, StorageMediatorOptions options = default)
|
||||
public async Task SaveAsync<T>(string key, T obj, bool useSecureStorage = false, bool allowSaveNull = false)
|
||||
{
|
||||
if (obj is null && !options.AllowSaveNull)
|
||||
if (obj is null && !allowSaveNull)
|
||||
{
|
||||
await GetAsyncStorage(options).RemoveAsync(key);
|
||||
await GetAsyncStorage(useSecureStorage).RemoveAsync(key);
|
||||
return;
|
||||
}
|
||||
|
||||
await GetAsyncStorage(options).SaveAsync<T>(key, obj);
|
||||
await GetAsyncStorage(useSecureStorage).SaveAsync<T>(key, obj);
|
||||
}
|
||||
|
||||
public Task RemoveAsync(string key, StorageMediatorOptions options = default)
|
||||
public Task RemoveAsync(string key, bool useSecureStorage = false)
|
||||
{
|
||||
return GetAsyncStorage(options).RemoveAsync(key);
|
||||
return GetAsyncStorage(useSecureStorage).RemoveAsync(key);
|
||||
}
|
||||
|
||||
IStorageService GetAsyncStorage(StorageMediatorOptions options)
|
||||
IStorageService GetAsyncStorage(bool useSecureStorage)
|
||||
{
|
||||
return options.UseSecureStorage ? _secureStorageService : _storageService;
|
||||
return useSecureStorage ? _secureStorageService : _storageService;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue