• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 The Chromium Embedded Framework Authors.
2 // Portions copyright 2016 The Chromium Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 
6 #ifndef CEF_LIBCEF_BROWSER_EXTENSIONS_VALUE_STORE_CEF_VALUE_STORE_FACTORY_H_
7 #define CEF_LIBCEF_BROWSER_EXTENSIONS_VALUE_STORE_CEF_VALUE_STORE_FACTORY_H_
8 
9 #include <map>
10 #include <memory>
11 
12 #include "base/files/file_path.h"
13 #include "components/value_store/value_store_factory.h"
14 
15 namespace value_store {
16 
17 class ValueStore;
18 
19 // Based on TestValueStoreFactory. Will either open a database on disk (if path
20 // provided) returning a |LeveldbValueStore|. Otherwise a new |CefingValueStore|
21 // instance will be returned.
22 class CefValueStoreFactory : public ValueStoreFactory {
23  public:
24   CefValueStoreFactory();
25   explicit CefValueStoreFactory(const base::FilePath& db_path);
26   CefValueStoreFactory(const CefValueStoreFactory&) = delete;
27   CefValueStoreFactory& operator=(const CefValueStoreFactory&) = delete;
28 
29   // ValueStoreFactory
30   std::unique_ptr<ValueStore> CreateValueStore(
31       const base::FilePath& directory,
32       const std::string& uma_client_name) override;
33   void DeleteValueStore(const base::FilePath& directory) override;
34   bool HasValueStore(const base::FilePath& directory) override;
35 
36   // Return the last created |ValueStore|. Use with caution as this may return
37   // a dangling pointer since the creator now owns the ValueStore which can be
38   // deleted at any time.
39   ValueStore* LastCreatedStore() const;
40   // Return the previously created |ValueStore| in the given directory.
41   ValueStore* GetExisting(const base::FilePath& directory) const;
42   // Reset this class (as if just created).
43   void Reset();
44 
45  private:
46   ~CefValueStoreFactory() override;
47 
48   std::unique_ptr<ValueStore> CreateStore();
49 
50   base::FilePath db_path_;
51   ValueStore* last_created_store_ = nullptr;
52 
53   // A mapping from directories to their ValueStore. None of these value
54   // stores are owned by this factory, so care must be taken when calling
55   // GetExisting.
56   std::map<base::FilePath, ValueStore*> value_store_map_;
57 };
58 
59 }  // namespace value_store
60 
61 #endif  // CEF_LIBCEF_BROWSER_EXTENSIONS_VALUE_STORE_CEF_VALUE_STORE_FACTORY_H_
62