blob: 65db0275a7197e6f31aadff5f5a956b12c7d8552 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef EXTENSIONS_BROWSER_VALUE_STORE_LEGACY_VALUE_STORE_FACTORY_H_
#define EXTENSIONS_BROWSER_VALUE_STORE_LEGACY_VALUE_STORE_FACTORY_H_
#include <set>
#include <string>
#include "base/files/file_path.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "extensions/browser/value_store/value_store.h"
#include "extensions/browser/value_store/value_store_factory.h"
#include "extensions/common/extension.h"
namespace extensions {
// A factory to create legacy ValueStore instances for storing extension
// state/rules/settings. "legacy" refers to the initial storage implementation
// which created a settings database per extension.
class LegacyValueStoreFactory : public ValueStoreFactory {
public:
explicit LegacyValueStoreFactory(const base::FilePath& profile_path);
bool RulesDBExists() const;
bool StateDBExists() const;
// ValueStoreFactory:
scoped_ptr<ValueStore> CreateRulesStore() override;
scoped_ptr<ValueStore> CreateStateStore() override;
scoped_ptr<ValueStore> CreateSettingsStore(
settings_namespace::Namespace settings_namespace,
ModelType model_type,
const ExtensionId& extension_id) override;
void DeleteSettings(settings_namespace::Namespace settings_namespace,
ModelType model_type,
const ExtensionId& extension_id) override;
bool HasSettings(settings_namespace::Namespace settings_namespace,
ModelType model_type,
const ExtensionId& extension_id) override;
std::set<ExtensionId> GetKnownExtensionIDs(
settings_namespace::Namespace settings_namespace,
ModelType model_type) const override;
private:
friend class base::RefCounted<LegacyValueStoreFactory>;
// Manages a collection of legacy settings databases all within a common
// directory.
class ModelSettings {
public:
explicit ModelSettings(const base::FilePath& data_path);
base::FilePath GetDBPath(const ExtensionId& extension_id) const;
bool DeleteData(const ExtensionId& extension_id);
bool DataExists(const ExtensionId& extension_id) const;
std::set<ExtensionId> GetKnownExtensionIDs() const;
private:
// The path containing all settings databases under this root.
const base::FilePath data_path_;
DISALLOW_COPY_AND_ASSIGN(ModelSettings);
};
// Manages two collections of legacy settings databases (apps & extensions)
// within a common base directory.
class SettingsRoot {
public:
// If either |extension_dirname| or |app_dirname| are empty then that
// ModelSetting will *not* be created.
SettingsRoot(const base::FilePath& base_path,
const std::string& extension_dirname,
const std::string& app_dirname);
~SettingsRoot();
std::set<ExtensionId> GetKnownExtensionIDs(ModelType model_type) const;
const ModelSettings* GetModel(ModelType model_type) const;
ModelSettings* GetModel(ModelType model_type);
private:
scoped_ptr<ModelSettings> extensions_;
scoped_ptr<ModelSettings> apps_;
DISALLOW_COPY_AND_ASSIGN(SettingsRoot);
};
~LegacyValueStoreFactory() override;
const SettingsRoot& GetSettingsRoot(
settings_namespace::Namespace settings_namespace) const;
SettingsRoot& GetSettingsRoot(
settings_namespace::Namespace settings_namespace);
base::FilePath GetRulesDBPath() const;
base::FilePath GetStateDBPath() const;
const base::FilePath profile_path_;
SettingsRoot local_settings_;
SettingsRoot sync_settings_;
SettingsRoot managed_settings_;
DISALLOW_COPY_AND_ASSIGN(LegacyValueStoreFactory);
};
} // namespace extensions
#endif // EXTENSIONS_BROWSER_VALUE_STORE_LEGACY_VALUE_STORE_FACTORY_H_
|