migration_delegate.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_LEVELDB_PROTO_INTERNAL_MIGRATION_DELEGATE_H_
  5. #define COMPONENTS_LEVELDB_PROTO_INTERNAL_MIGRATION_DELEGATE_H_
  6. #include <memory>
  7. #include "base/callback.h"
  8. #include "components/leveldb_proto/internal/proto_leveldb_wrapper.h"
  9. #include "components/leveldb_proto/internal/unique_proto_database.h"
  10. namespace leveldb_proto {
  11. // Small class that strictly performs the migration functionality of
  12. // SharedProtoDatabase.
  13. class MigrationDelegate {
  14. public:
  15. using MigrationCallback = base::OnceCallback<void(bool)>;
  16. MigrationDelegate();
  17. ~MigrationDelegate();
  18. // Copies the keys/entries of |from| to |to|, and returns a boolean success
  19. // in |callback|.
  20. void DoMigration(UniqueProtoDatabase* from,
  21. UniqueProtoDatabase* to,
  22. MigrationCallback callback);
  23. private:
  24. void OnLoadKeysAndEntries(MigrationCallback callback,
  25. UniqueProtoDatabase* to,
  26. bool success,
  27. std::unique_ptr<KeyValueMap> keys_entries);
  28. void OnUpdateEntries(MigrationCallback callback, bool success);
  29. base::WeakPtrFactory<MigrationDelegate> weak_ptr_factory_{this};
  30. };
  31. } // namespace leveldb_proto
  32. #endif // COMPONENTS_LEVELDB_PROTO_INTERNAL_MIGRATION_DELEGATE_H_