1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-09-27 03:52:57 +02:00

PM-1271 Removed StorageMediatorOptions and go to a plain parameters based approach (#2397)

This commit is contained in:
Federico Maccaroni 2023-03-02 19:06:38 -03:00 committed by GitHub
parent a81dfc271c
commit 3f86bb0cd7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 21 deletions

View File

@ -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);
}
}

View File

@ -1,8 +0,0 @@
namespace Bit.Core.Services
{
public struct StorageMediatorOptions
{
public bool UseSecureStorage { get; set; }
public bool AllowSaveNull { get; set; }
}
}

View File

@ -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;
}
}
}