|
16 | 16 |
|
17 | 17 | #include "firestore/src/include/firebase/firestore/settings.h"
|
18 | 18 |
|
| 19 | +#include <memory> |
19 | 20 | #include <ostream>
|
20 | 21 | #include <sstream>
|
21 | 22 |
|
| 23 | +#include "Firestore/core/src/api/settings.h" |
| 24 | +#include "Firestore/core/src/util/hard_assert.h" |
22 | 25 | #include "app/meta/move.h"
|
| 26 | +#include "firebase/firestore/local_cache_settings.h" |
23 | 27 |
|
24 | 28 | #if !defined(__ANDROID__)
|
25 | 29 | #include "Firestore/core/src/util/executor.h"
|
@@ -51,12 +55,46 @@ void Settings::set_host(std::string host) { host_ = firebase::Move(host); }
|
51 | 55 |
|
52 | 56 | void Settings::set_ssl_enabled(bool enabled) { ssl_enabled_ = enabled; }
|
53 | 57 |
|
| 58 | +std::shared_ptr<LocalCacheSettings> Settings::local_cache_settings() const { |
| 59 | + if (used_legacy_cache_settings_) { |
| 60 | + if (is_persistence_enabled()) { |
| 61 | + return std::make_shared<PersistentCacheSettings>( |
| 62 | + *PersistentCacheSettings::Create() |
| 63 | + .WithSizeBytes(cache_size_bytes()) |
| 64 | + .settings_internal_); |
| 65 | + } else { |
| 66 | + return std::make_shared<MemoryCacheSettings>( |
| 67 | + *MemoryCacheSettings::Create().settings_internal_); |
| 68 | + } |
| 69 | + } else if (local_cache_settings_ != nullptr) { |
| 70 | + return local_cache_settings_; |
| 71 | + } |
| 72 | + |
| 73 | + return std::make_shared<PersistentCacheSettings>( |
| 74 | + *PersistentCacheSettings::Create().settings_internal_); |
| 75 | +} |
| 76 | + |
| 77 | +void Settings::set_local_cache_settings(const LocalCacheSettings& cache) { |
| 78 | + HARD_ASSERT(!used_legacy_cache_settings_, ""); |
| 79 | + if (cache.kind() == api::LocalCacheSettings::Kind::kPersistent) { |
| 80 | + local_cache_settings_ = std::make_shared<PersistentCacheSettings>( |
| 81 | + *static_cast<const PersistentCacheSettings&>(cache).settings_internal_); |
| 82 | + } else { |
| 83 | + local_cache_settings_ = std::make_shared<MemoryCacheSettings>( |
| 84 | + *static_cast<const MemoryCacheSettings&>(cache).settings_internal_); |
| 85 | + } |
| 86 | +} |
| 87 | + |
54 | 88 | void Settings::set_persistence_enabled(bool enabled) {
|
| 89 | + HARD_ASSERT(local_cache_settings() == nullptr, ""); |
55 | 90 | persistence_enabled_ = enabled;
|
| 91 | + used_legacy_cache_settings_ = true; |
56 | 92 | }
|
57 | 93 |
|
58 | 94 | void Settings::set_cache_size_bytes(int64_t value) {
|
| 95 | + HARD_ASSERT(local_cache_settings() == nullptr, ""); |
59 | 96 | cache_size_bytes_ = value;
|
| 97 | + used_legacy_cache_settings_ = true; |
60 | 98 | }
|
61 | 99 |
|
62 | 100 | std::string Settings::ToString() const {
|
|
0 commit comments