| Index: components/sync/model_impl/model_type_store_backend.h
|
| diff --git a/components/sync/model_impl/model_type_store_backend.h b/components/sync/model_impl/model_type_store_backend.h
|
| index 4c99ad24bea51e434282809279e14fe4c1eefd83..0618432c4851c9e5c7b03cb7eb69c4c93946f741 100644
|
| --- a/components/sync/model_impl/model_type_store_backend.h
|
| +++ b/components/sync/model_impl/model_type_store_backend.h
|
| @@ -13,6 +13,7 @@
|
| #include "base/macros.h"
|
| #include "base/threading/thread_collision_warner.h"
|
| #include "components/sync/model/model_type_store.h"
|
| +#include "third_party/leveldatabase/src/include/leveldb/status.h"
|
|
|
| namespace leveldb {
|
| class DB;
|
| @@ -22,6 +23,32 @@ class WriteBatch;
|
|
|
| namespace syncer {
|
|
|
| +// Different reasons for ModelTypeStoreBackend initialization failure are mapped
|
| +// to these values. The enum is used for recording UMA histogram. Don't reorder,
|
| +// change or delete values.
|
| +enum StoreInitResultForHistogram {
|
| + STORE_INIT_RESULT_SUCCESS = 0,
|
| +
|
| + // Following values reflect leveldb initialization errors.
|
| + STORE_INIT_RESULT_NOT_FOUND,
|
| + STORE_INIT_RESULT_CORRUPTION,
|
| + STORE_INIT_RESULT_NOT_SUPPORTED,
|
| + STORE_INIT_RESULT_INVALID_ARGUMENT,
|
| + STORE_INIT_RESULT_IO_ERROR,
|
| +
|
| + // Issues encountered when reading or parsing schema descriptor.
|
| + STORE_INIT_RESULT_SCHEMA_DESCRIPTOR_ISSUE,
|
| +
|
| + // Database schema migration failed.
|
| + STORE_INIT_RESULT_MIGRATION,
|
| +
|
| + STORE_INIT_RESULT_UNKNOWN,
|
| +
|
| + // Database was reset after attempt to open failed with corruption.
|
| + STORE_INIT_RESULT_RECOVERED_AFTER_CORRUPTION,
|
| + STORE_INIT_RESULT_COUNT
|
| +};
|
| +
|
| // ModelTypeStoreBackend handles operations with leveldb. It is oblivious of the
|
| // fact that it is called from separate thread (with the exception of ctor),
|
| // meaning it shouldn't deal with callbacks and task_runners.
|
| @@ -69,29 +96,11 @@ class ModelTypeStoreBackend
|
|
|
| static const int64_t kLatestSchemaVersion;
|
| static const char kDBSchemaDescriptorRecordId[];
|
| + static const char kStoreInitResultHistogramName[];
|
|
|
| explicit ModelTypeStoreBackend(const std::string& path);
|
| ~ModelTypeStoreBackend();
|
|
|
| - // In some scenarios ModelTypeStoreBackend holds ownership of env. Typical
|
| - // example is when test creates in memory environment with CreateInMemoryEnv
|
| - // and wants it to be destroyed along with backend. This is achieved by
|
| - // passing ownership of env to TakeEnvOwnership function.
|
| - //
|
| - // env_ declaration should appear before declaration of db_ because
|
| - // environment object should still be valid when db_'s destructor is called.
|
| - std::unique_ptr<leveldb::Env> env_;
|
| -
|
| - std::unique_ptr<leveldb::DB> db_;
|
| -
|
| - std::string path_;
|
| -
|
| - // backend_map_ holds raw pointer of backend, and when stores ask for backend,
|
| - // GetOrCreateBackend will return scoped_refptr of backend. backend_map_
|
| - // doesn't take reference to backend, therefore doesn't block backend
|
| - // destruction.
|
| - static base::LazyInstance<BackendMap> backend_map_;
|
| -
|
| // Init opens database at |path|. If database doesn't exist it creates one.
|
| // Normally |env| should be nullptr, this causes leveldb to use default disk
|
| // based environment from leveldb::Env::Default().
|
| @@ -100,6 +109,14 @@ class ModelTypeStoreBackend
|
| ModelTypeStore::Result Init(const std::string& path,
|
| std::unique_ptr<leveldb::Env> env);
|
|
|
| + // Opens leveldb database passing correct options. On success sets |db_| and
|
| + // returns ok status. On failure |db_| is nullptr and returned status reflects
|
| + // failure type.
|
| + leveldb::Status OpenDatabase(const std::string& path, leveldb::Env* env);
|
| +
|
| + // Destroys leveldb database. Used for recovering after database corruption.
|
| + leveldb::Status DestroyDatabase(const std::string& path, leveldb::Env* env);
|
| +
|
| // Attempts to read and return the database's version.
|
| // If there is not a schema descriptor present, the value returned is 0.
|
| // If an error occurs, the value returned is kInvalidSchemaVersion(-1).
|
| @@ -114,6 +131,28 @@ class ModelTypeStoreBackend
|
| // the schema, returning true on success.
|
| bool Migrate0To1();
|
|
|
| + static void RecordStoreInitResultHistogram(
|
| + StoreInitResultForHistogram result);
|
| +
|
| + // In some scenarios ModelTypeStoreBackend holds ownership of env. Typical
|
| + // example is when test creates in memory environment with CreateInMemoryEnv
|
| + // and wants it to be destroyed along with backend. This is achieved by
|
| + // passing ownership of env to TakeEnvOwnership function.
|
| + //
|
| + // env_ declaration should appear before declaration of db_ because
|
| + // environment object should still be valid when db_'s destructor is called.
|
| + std::unique_ptr<leveldb::Env> env_;
|
| +
|
| + std::unique_ptr<leveldb::DB> db_;
|
| +
|
| + std::string path_;
|
| +
|
| + // backend_map_ holds raw pointer of backend, and when stores ask for backend,
|
| + // GetOrCreateBackend will return scoped_refptr of backend. backend_map_
|
| + // doesn't take reference to backend, therefore doesn't block backend
|
| + // destruction.
|
| + static base::LazyInstance<BackendMap> backend_map_;
|
| +
|
| // Macro wrapped mutex to guard against concurrent calls in debug builds.
|
| DFAKE_MUTEX(push_pop_);
|
|
|
|
|