shared_proto_database_provider.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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_SHARED_PROTO_DATABASE_PROVIDER_H_
  5. #define COMPONENTS_LEVELDB_PROTO_INTERNAL_SHARED_PROTO_DATABASE_PROVIDER_H_
  6. #include "base/component_export.h"
  7. #include "base/memory/weak_ptr.h"
  8. #include "base/task/sequenced_task_runner.h"
  9. namespace leveldb_proto {
  10. class SharedProtoDatabase;
  11. class ProtoDatabaseProvider;
  12. // Helper class to be instantiated for each request for a shared database
  13. // provider to be used in the wrapper. |client_task_runner| is the
  14. // SequencedTaskRunner provided by the main provider so its WeakPtrs are
  15. // always checked on the right sequence.
  16. class COMPONENT_EXPORT(LEVELDB_PROTO) SharedProtoDatabaseProvider {
  17. public:
  18. using GetSharedDBInstanceCallback =
  19. base::OnceCallback<void(scoped_refptr<SharedProtoDatabase>)>;
  20. ~SharedProtoDatabaseProvider();
  21. void GetDBInstance(
  22. GetSharedDBInstanceCallback callback,
  23. scoped_refptr<base::SequencedTaskRunner> callback_task_runner);
  24. private:
  25. friend class ProtoDatabaseProvider;
  26. friend class TestSharedProtoDatabaseProvider;
  27. SharedProtoDatabaseProvider(
  28. const scoped_refptr<base::SequencedTaskRunner>& client_task_runner,
  29. base::WeakPtr<ProtoDatabaseProvider> provider_weak_ptr);
  30. scoped_refptr<base::SequencedTaskRunner> client_task_runner_;
  31. base::WeakPtr<ProtoDatabaseProvider> provider_weak_ptr_;
  32. };
  33. } // namespace leveldb_proto
  34. #endif // COMPONENTS_LEVELDB_PROTO_INTERNAL_SHARED_PROTO_DATABASE_PROVIDER_H_