diff --git a/firestore/src/common/local_cache_settings.cc b/firestore/src/common/local_cache_settings.cc index c1b897b865..b5ea995ed1 100644 --- a/firestore/src/common/local_cache_settings.cc +++ b/firestore/src/common/local_cache_settings.cc @@ -17,7 +17,6 @@ #include "firestore/src/include/firebase/firestore/local_cache_settings.h" #include -#include "Firestore/core/src/api/settings.h" #include "firestore/src/common/hard_assert_common.h" #if defined(__ANDROID__) #else @@ -27,55 +26,44 @@ namespace firebase { namespace firestore { -namespace { -using CoreCacheSettings = api::LocalCacheSettings; -using CorePersistentSettings = api::PersistentCacheSettings; -using CoreMemorySettings = api::MemoryCacheSettings; -using CoreMemoryGarbageCollectorSettings = api::MemoryGargabeCollectorSettings; -using CoreMemoryEagerGcSettings = api::MemoryEagerGcSettings; -using CoreMemoryLruGcSettings = api::MemoryLruGcSettings; -} // namespace - PersistentCacheSettings PersistentCacheSettings::Create() { return {}; } PersistentCacheSettings::PersistentCacheSettings() { - settings_internal_ = std::make_shared( - CorePersistentSettings{}); + settings_internal_ = std::make_shared(); } PersistentCacheSettings PersistentCacheSettings::WithSizeBytes( int64_t size) const { - PersistentCacheSettings new_settings{*this}; - new_settings.settings_internal_->set_core_settings( - new_settings.settings_internal_->core_settings().WithSizeBytes(size)); + PersistentCacheSettings new_settings; + new_settings.settings_internal_ = + std::make_shared( + this->settings_internal_->WithSizeBytes(size)); return new_settings; } int64_t PersistentCacheSettings::size_bytes() const { - return settings_internal_->core_settings().size_bytes(); + return settings_internal_->size_bytes(); } -const CoreCacheSettings& PersistentCacheSettings::core_settings() const { - return settings_internal_->core_settings(); +const LocalCacheSettingsInternal& PersistentCacheSettings::internal() const { + return *settings_internal_; } MemoryEagerGCSettings MemoryEagerGCSettings::Create() { return {}; } MemoryEagerGCSettings::MemoryEagerGCSettings() { - settings_internal_ = std::make_shared( - CoreMemoryEagerGcSettings{}); + settings_internal_ = std::make_shared(); } -const CoreMemoryGarbageCollectorSettings& MemoryEagerGCSettings::core_settings() +const MemoryGarbageCollectorSettingsInternal& MemoryEagerGCSettings::internal() const { - return settings_internal_->core_settings(); + return *settings_internal_; } MemoryLruGCSettings MemoryLruGCSettings::Create() { return {}; } MemoryLruGCSettings::MemoryLruGCSettings() { - settings_internal_ = - std::make_shared(CoreMemoryLruGcSettings{}); + settings_internal_ = std::make_shared(); } MemoryLruGCSettings::MemoryLruGCSettings( @@ -84,42 +72,41 @@ MemoryLruGCSettings::MemoryLruGCSettings( } MemoryLruGCSettings MemoryLruGCSettings::WithSizeBytes(int64_t size) { - return {MemoryLruGCSettingsInternal{ - settings_internal_->core_settings().WithSizeBytes(size)}}; + MemoryLruGCSettings result; + result.settings_internal_ = std::make_shared( + this->settings_internal_->WithSizeBytes(size)); + return result; } int64_t MemoryLruGCSettings::size_bytes() const { - return settings_internal_->core_settings().size_bytes(); + return settings_internal_->size_bytes(); } -const CoreMemoryGarbageCollectorSettings& MemoryLruGCSettings::core_settings() +const MemoryGarbageCollectorSettingsInternal& MemoryLruGCSettings::internal() const { - return settings_internal_->core_settings(); + return *settings_internal_; } MemoryCacheSettings MemoryCacheSettings::Create() { return {}; } MemoryCacheSettings::MemoryCacheSettings() { - settings_internal_ = - std::make_shared(CoreMemorySettings{}); + settings_internal_ = std::make_shared(); } MemoryCacheSettings MemoryCacheSettings::WithGarbageCollectorSettings( const MemoryGarbageCollectorSettings& settings) const { - MemoryCacheSettings result{*this}; - CoreMemorySettings core_settings = result.settings_internal_->core_settings(); - result.settings_internal_->set_core_settings( - core_settings.WithMemoryGarbageCollectorSettings( - settings.core_settings())); + MemoryCacheSettings result; + result.settings_internal_ = std::make_shared( + this->settings_internal_->WithGarbageCollectorSettings(settings)); return result; } -const CoreCacheSettings& MemoryCacheSettings::core_settings() const { - return settings_internal_->core_settings(); +const LocalCacheSettingsInternal& MemoryCacheSettings::internal() const { + return *settings_internal_; } bool operator==(const LocalCacheSettings& lhs, const LocalCacheSettings& rhs) { - return lhs.kind() == rhs.kind() && lhs.core_settings() == rhs.core_settings(); + return lhs.kind() == rhs.kind() && lhs.internal() == rhs.internal(); } bool operator==(const MemoryCacheSettings& lhs, @@ -134,7 +121,7 @@ bool operator==(const PersistentCacheSettings& lhs, bool operator==(const MemoryGarbageCollectorSettings& lhs, const MemoryGarbageCollectorSettings& rhs) { - return lhs.core_settings() == rhs.core_settings(); + return lhs.internal() == rhs.internal(); } bool operator==(const MemoryEagerGCSettings& lhs, diff --git a/firestore/src/common/settings.cc b/firestore/src/common/settings.cc index ea2ba0f62e..06edbc57d0 100644 --- a/firestore/src/common/settings.cc +++ b/firestore/src/common/settings.cc @@ -20,7 +20,6 @@ #include #include -#include "Firestore/core/src/api/settings.h" #include "Firestore/core/src/util/hard_assert.h" #include "app/meta/move.h" #include "firebase/firestore/local_cache_settings.h" diff --git a/firestore/src/include/firebase/firestore/local_cache_settings.h b/firestore/src/include/firebase/firestore/local_cache_settings.h index 5a5b86e04f..b7d4a5eaa8 100644 --- a/firestore/src/include/firebase/firestore/local_cache_settings.h +++ b/firestore/src/include/firebase/firestore/local_cache_settings.h @@ -24,15 +24,13 @@ namespace firebase { namespace firestore { -namespace api { -class LocalCacheSettings; -class MemoryGargabeCollectorSettings; -} // namespace api +class LocalCacheSettingsInternal; class PersistentCacheSettingsInternal; class MemoryCacheSettingsInternal; class MemoryLruGCSettingsInternal; class MemoryEagerGCSettingsInternal; +class MemoryGarbageCollectorSettingsInternal; /** * Abstract class implemented by all supported cache settings. @@ -42,15 +40,16 @@ class MemoryEagerGCSettingsInternal; */ class LocalCacheSettings { public: + enum class Kind { kMemory, kPersistent }; + virtual ~LocalCacheSettings() = default; + virtual Kind kind() const = 0; + /** Equality function. */ friend bool operator==(const LocalCacheSettings& lhs, const LocalCacheSettings& rhs); - protected: - enum class Kind { kMemory, kPersistent }; - private: friend class FirestoreInternal; friend class Settings; @@ -59,8 +58,7 @@ class LocalCacheSettings { LocalCacheSettings() = default; - virtual Kind kind() const = 0; - virtual const api::LocalCacheSettings& core_settings() const = 0; + virtual const LocalCacheSettingsInternal& internal() const = 0; }; /** @@ -114,7 +112,7 @@ class PersistentCacheSettings final : public LocalCacheSettings { } // Get the corresponding settings object from the core sdk. - const api::LocalCacheSettings& core_settings() const override; + const LocalCacheSettingsInternal& internal() const override; std::shared_ptr settings_internal_; }; @@ -155,7 +153,7 @@ class MemoryCacheSettings final : public LocalCacheSettings { return LocalCacheSettings::Kind::kMemory; } - const api::LocalCacheSettings& core_settings() const override; + const LocalCacheSettingsInternal& internal() const override; std::shared_ptr settings_internal_; }; @@ -178,10 +176,11 @@ class MemoryGarbageCollectorSettings { friend class MemoryCacheSettings; friend class MemoryEagerGCSettings; friend class MemoryLruGCSettings; + friend class MemoryCacheSettingsInternal; MemoryGarbageCollectorSettings() = default; - virtual const api::MemoryGargabeCollectorSettings& core_settings() const = 0; + virtual const MemoryGarbageCollectorSettingsInternal& internal() const = 0; }; /** @@ -211,7 +210,7 @@ class MemoryEagerGCSettings final : public MemoryGarbageCollectorSettings { private: friend class MemoryCacheSettings; MemoryEagerGCSettings(); - const api::MemoryGargabeCollectorSettings& core_settings() const override; + const MemoryGarbageCollectorSettingsInternal& internal() const override; std::shared_ptr settings_internal_; }; @@ -267,7 +266,7 @@ class MemoryLruGCSettings final : public MemoryGarbageCollectorSettings { MemoryLruGCSettings(); MemoryLruGCSettings(const MemoryLruGCSettingsInternal& other); - const api::MemoryGargabeCollectorSettings& core_settings() const override; + const MemoryGarbageCollectorSettingsInternal& internal() const override; std::shared_ptr settings_internal_; }; diff --git a/firestore/src/main/firestore_main.cc b/firestore/src/main/firestore_main.cc index dd49b80c03..d40469e9e6 100644 --- a/firestore/src/main/firestore_main.cc +++ b/firestore/src/main/firestore_main.cc @@ -221,7 +221,7 @@ void FirestoreInternal::set_settings(Settings from) { // this special logic should go away when legacy cache config is removed. if (from.cache_settings_source_ == Settings::CacheSettingsSource::kNew) { settings.set_local_cache_settings( - from.local_cache_settings().core_settings()); + from.local_cache_settings().internal().core_settings()); } else { settings.set_persistence_enabled(from.is_persistence_enabled()); settings.set_cache_size_bytes(from.cache_size_bytes()); diff --git a/firestore/src/main/local_cache_settings_main.h b/firestore/src/main/local_cache_settings_main.h index 88817f6b8b..7d23ad5068 100644 --- a/firestore/src/main/local_cache_settings_main.h +++ b/firestore/src/main/local_cache_settings_main.h @@ -21,27 +21,39 @@ #include #include "Firestore/core/src/api/settings.h" +#include "firebase/firestore/local_cache_settings.h" namespace firebase { namespace firestore { class LocalCacheSettingsInternal { public: + friend bool operator==(const LocalCacheSettingsInternal& lhs, + const LocalCacheSettingsInternal& rhs) { + return &lhs == &rhs || lhs.core_settings() == rhs.core_settings(); + } + virtual const api::LocalCacheSettings& core_settings() const = 0; }; class PersistentCacheSettingsInternal final : public LocalCacheSettingsInternal { public: - explicit PersistentCacheSettingsInternal( - const api::PersistentCacheSettings& core_settings) - : settings_(std::move(core_settings)) {} + explicit PersistentCacheSettingsInternal() = default; friend bool operator==(const PersistentCacheSettingsInternal& lhs, const PersistentCacheSettingsInternal& rhs) { return &lhs == &rhs || lhs.settings_ == rhs.settings_; } + PersistentCacheSettingsInternal WithSizeBytes(int64_t size) { + PersistentCacheSettingsInternal result; + result.set_core_settings(this->core_settings().WithSizeBytes(size)); + return result; + } + + int64_t size_bytes() const { return settings_.size_bytes(); } + const api::PersistentCacheSettings& core_settings() const override { return settings_; } @@ -55,15 +67,18 @@ class PersistentCacheSettingsInternal final class MemoryGarbageCollectorSettingsInternal { public: + friend bool operator==(const MemoryGarbageCollectorSettingsInternal& lhs, + const MemoryGarbageCollectorSettingsInternal& rhs) { + return &lhs == &rhs || lhs.core_settings() == rhs.core_settings(); + } + virtual const api::MemoryGargabeCollectorSettings& core_settings() const = 0; }; class MemoryEagerGCSettingsInternal final : public MemoryGarbageCollectorSettingsInternal { public: - explicit MemoryEagerGCSettingsInternal( - const api::MemoryEagerGcSettings& core_settings) - : settings_(std::move(core_settings)) {} + explicit MemoryEagerGCSettingsInternal() = default; friend bool operator==(const MemoryEagerGCSettingsInternal& lhs, const MemoryEagerGCSettingsInternal& rhs) { @@ -84,15 +99,21 @@ class MemoryEagerGCSettingsInternal final class MemoryLruGCSettingsInternal final : public MemoryGarbageCollectorSettingsInternal { public: - explicit MemoryLruGCSettingsInternal( - const api::MemoryLruGcSettings& core_settings) - : settings_(std::move(core_settings)) {} + explicit MemoryLruGCSettingsInternal() = default; friend bool operator==(const MemoryLruGCSettingsInternal& lhs, const MemoryLruGCSettingsInternal& rhs) { return &lhs == &rhs || lhs.settings_ == rhs.settings_; } + MemoryLruGCSettingsInternal WithSizeBytes(int64_t size) { + MemoryLruGCSettingsInternal result; + result.set_core_settings(this->core_settings().WithSizeBytes(size)); + return result; + } + + int64_t size_bytes() const { return settings_.size_bytes(); } + const api::MemoryLruGcSettings& core_settings() const override { return settings_; } @@ -106,23 +127,27 @@ class MemoryLruGCSettingsInternal final class MemoryCacheSettingsInternal final : public LocalCacheSettingsInternal { public: - explicit MemoryCacheSettingsInternal( - const api::MemoryCacheSettings& core_settings) - : settings_(std::move(core_settings)) {} + explicit MemoryCacheSettingsInternal() = default; friend bool operator==(const MemoryCacheSettingsInternal& lhs, const MemoryCacheSettingsInternal& rhs) { return &lhs == &rhs || lhs.settings_ == rhs.settings_; } + MemoryCacheSettingsInternal WithGarbageCollectorSettings( + const MemoryGarbageCollectorSettings& gc_settings) { + return MemoryCacheSettingsInternal( + api::MemoryCacheSettings().WithMemoryGarbageCollectorSettings( + gc_settings.internal().core_settings())); + } + const api::MemoryCacheSettings& core_settings() const override { return settings_; } - void set_core_settings(const api::MemoryCacheSettings& settings) { - settings_ = settings; - } private: + explicit MemoryCacheSettingsInternal(const api::MemoryCacheSettings& settings) + : settings_(settings) {} api::MemoryCacheSettings settings_; };