blob: 3d63e639e2fb675396774c3142b1c46297d62d5c [file] [log] [blame]
Troy Hildebrandt3b7014b2018-12-18 17:32:141// 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
5#ifndef COMPONENTS_LEVELDB_PROTO_SHARED_PROTO_DATABASE_PROVIDER_H_
6#define COMPONENTS_LEVELDB_PROTO_SHARED_PROTO_DATABASE_PROVIDER_H_
7
8#include "base/memory/weak_ptr.h"
9#include "base/sequenced_task_runner.h"
10
11namespace leveldb_proto {
12
13class SharedProtoDatabase;
14class ProtoDatabaseProvider;
15
16// Helper class to be instantiated for each request for a shared database
17// provider to be used in the wrapper. |task_runner| is the
18// SequencedTaskRunner provided by the main provider so its WeakPtrs are
19// always checked on the right sequence.
20class SharedProtoDatabaseProvider {
21 public:
22 using GetSharedDBInstanceCallback =
23 base::OnceCallback<void(scoped_refptr<SharedProtoDatabase>)>;
24
25 ~SharedProtoDatabaseProvider();
26
27 void GetDBInstance(
28 GetSharedDBInstanceCallback callback,
29 scoped_refptr<base::SequencedTaskRunner> callback_task_runner);
30
31 private:
32 friend class ProtoDatabaseProvider;
33 friend class TestSharedProtoDatabaseProvider;
34
35 SharedProtoDatabaseProvider(
36 const scoped_refptr<base::SequencedTaskRunner>& task_runner,
37 base::WeakPtr<ProtoDatabaseProvider> provider_weak_ptr);
38
39 scoped_refptr<base::SequencedTaskRunner> task_runner_;
40 base::WeakPtr<ProtoDatabaseProvider> provider_weak_ptr_;
41};
42
43} // namespace leveldb_proto
44
45#endif // COMPONENTS_LEVELDB_PROTO_SHARED_PROTO_DATABASE_PROVIDER_H_