blob: c2bde47aa830dd47fb8f55480a9830f5ef4332c6 (
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
|
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_DEVTOOLS_DEVTOOLS_SETTINGS_H_
#define CHROME_BROWSER_DEVTOOLS_DEVTOOLS_SETTINGS_H_
#include <string>
#include "base/containers/flat_set.h"
#include "base/values.h"
#include "components/prefs/pref_change_registrar.h"
class Profile;
namespace base {
class Value;
}
struct RegisterOptions {
enum class SyncMode {
kSync,
kDontSync,
};
SyncMode sync_mode;
};
class DevToolsSettings {
public:
// The frontend setting name that mirrors prefs::kDevToolsSyncPreferences.
static const char kSyncDevToolsPreferencesFrontendName[];
static const bool kSyncDevToolsPreferencesDefault;
explicit DevToolsSettings(Profile* profile);
~DevToolsSettings();
void Register(const std::string& name, const RegisterOptions& options);
base::Value Get();
absl::optional<base::Value> Get(const std::string& name);
void Set(const std::string& name, const std::string& value);
void Remove(const std::string& name);
void Clear();
private:
const char* GetDictionaryNameForSettingsName(const std::string& name) const;
const char* GetDictionaryNameForSyncedPrefs() const;
void DevToolsSyncPreferencesChanged();
Profile* const profile_;
// Contains the set of synced settings.
// The DevTools frontend *must* call `Register` for each setting prior to
// use, which guarantees that this set must not be persisted.
base::flat_set<std::string> synced_setting_names_;
// Settings pref observer that moves synced settings between their two
// dictionaries depending on the state of kDevToolsSyncPreferences.
// kDevToolsSyncPreferences is only changed via the frontend, so it is
// sufficient to only listen for changes during a DevTools session.
PrefChangeRegistrar pref_change_registrar_;
};
#endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_SETTINGS_H_
|