Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(220)

Unified Diff: sync/internal_api/model_type_store_backend.cc

Issue 2077713002: [USS] Store supports hosting multiple datatypes per database (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove includes Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | sync/internal_api/model_type_store_backend_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sync/internal_api/model_type_store_backend.cc
diff --git a/sync/internal_api/model_type_store_backend.cc b/sync/internal_api/model_type_store_backend.cc
index cba6731d98c9ecff9a1ecbfdeb7307d55d32a4e9..bc90607ee8fb2079b6d18cdbc01433c468a483fd 100644
--- a/sync/internal_api/model_type_store_backend.cc
+++ b/sync/internal_api/model_type_store_backend.cc
@@ -20,23 +20,48 @@
namespace syncer_v2 {
-ModelTypeStoreBackend::ModelTypeStoreBackend() {
-}
+// static
+base::LazyInstance<ModelTypeStoreBackend::BackendMap>
+ ModelTypeStoreBackend::backend_map_ = LAZY_INSTANCE_INITIALIZER;
+
+ModelTypeStoreBackend::ModelTypeStoreBackend(const std::string& path)
+ : path_(path) {}
ModelTypeStoreBackend::~ModelTypeStoreBackend() {
+ backend_map_.Get().erase(path_);
}
std::unique_ptr<leveldb::Env> ModelTypeStoreBackend::CreateInMemoryEnv() {
return base::WrapUnique(leveldb::NewMemEnv(leveldb::Env::Default()));
}
-void ModelTypeStoreBackend::TakeEnvOwnership(
- std::unique_ptr<leveldb::Env> env) {
- env_ = std::move(env);
+// static
+scoped_refptr<ModelTypeStoreBackend> ModelTypeStoreBackend::GetOrCreateBackend(
+ const std::string& path,
+ std::unique_ptr<leveldb::Env> env,
+ ModelTypeStore::Result* result) {
+ if (backend_map_.Get().find(path) != backend_map_.Get().end()) {
+ *result = ModelTypeStore::Result::SUCCESS;
+ return make_scoped_refptr(backend_map_.Get()[path]);
+ }
+
+ scoped_refptr<ModelTypeStoreBackend> backend =
+ new ModelTypeStoreBackend(path);
+
+ *result = backend->Init(path, std::move(env));
+
+ if (*result == ModelTypeStore::Result::SUCCESS) {
+ backend_map_.Get()[path] = backend.get();
+ } else {
+ backend = nullptr;
+ }
+
+ return backend;
}
-ModelTypeStore::Result ModelTypeStoreBackend::Init(const std::string& path,
- leveldb::Env* env) {
+ModelTypeStore::Result ModelTypeStoreBackend::Init(
+ const std::string& path,
+ std::unique_ptr<leveldb::Env> env) {
DFAKE_SCOPED_LOCK(push_pop_);
leveldb::DB* db_raw = nullptr;
@@ -44,8 +69,11 @@ ModelTypeStore::Result ModelTypeStoreBackend::Init(const std::string& path,
options.create_if_missing = true;
options.reuse_logs = leveldb_env::kDefaultLogReuseOptionValue;
options.paranoid_checks = true;
- if (env)
- options.env = env;
+ if (env.get()) {
+ options.env = env.get();
+ env_ = std::move(env);
+ }
+
leveldb::Status status = leveldb::DB::Open(options, path, &db_raw);
if (!status.ok()) {
DCHECK(db_raw == nullptr);
« no previous file with comments | « no previous file | sync/internal_api/model_type_store_backend_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698