summaryrefslogtreecommitdiff
path: root/chromium/services/preferences/public/mojom/preferences.mojom
blob: 66caa7d7b77970cc9e0131d56ff568681138acc0 (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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
// 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.

module prefs.mojom;

import "mojo/common/values.mojom";
import "mojo/public/mojom/base/file_path.mojom";
import "mojo/public/mojom/base/string16.mojom";
import "services/preferences/public/mojom/tracked_preference_validation_delegate.mojom";

const string kServiceName = "preferences";
const string kLocalStateServiceName = "local_state";

// The know pref store types.
//
// Should be kept in sync with PrefValueStore::PrefStoreType.
enum PrefStoreType {
  MANAGED,
  SUPERVISED_USER,
  EXTENSION,
  COMMAND_LINE,
  USER,
  RECOMMENDED,
  DEFAULT,
};

// Allows observing changes to prefs stored in a |PrefStore|.
interface PrefStoreObserver {
  // Preferences have been changed.
  OnPrefsChanged(array<PrefUpdate> updates);

  // The PrefStore has been initialized (asynchronously).
  OnInitializationCompleted(bool succeeded);

  // A preference write by this client has been applied. If this
  // PrefStoreObserver is associated with a PersistentPrefStore, one
  // OnPrefChangeAck() message is sent in response to each SetValues() message.
  // This exists to ensure acks are ordered with respect to OnPrefsChanged
  // messages.
  OnPrefChangeAck();
};

// Captures the connections to a PrefStore by supplying the initial state of the
// store and a handle to receive notifications on.
struct PrefStoreConnection {
  // Handle to receive updates on.
  PrefStoreObserver& observer;

  // Initial values of the PrefStore. These will not be communicated through
  // OnPrefChanged.
  mojo.common.mojom.DictionaryValue initial_prefs;

  // Is the PrefStore initialized? If not it should not be used before
  // OnInitializationCompleted has been called.
  bool is_initialized;
};

struct PersistentPrefStoreConnection {
  enum ReadError {
    NONE = 0,
    JSON_PARSE = 1,
    JSON_TYPE = 2,
    ACCESS_DENIED = 3,
    FILE_OTHER = 4,
    FILE_LOCKED = 5,
    NO_FILE = 6,
    JSON_REPEAT = 7,
    // OTHER = 8,  // Deprecated.
    FILE_NOT_SPECIFIED = 9,
    ASYNCHRONOUS_TASK_INCOMPLETE = 10,
  };

  PrefStoreConnection? pref_store_connection;
  PersistentPrefStore? pref_store;
  ReadError read_error;
  bool read_only;
};

struct IncognitoPersistentPrefStoreConnection {
  PersistentPrefStoreConnection pref_store_connection;
  array<string> overlay_pref_names;
};

// Allows connections to pref stores registered with |PrefStoreRegistry|.
interface PrefStoreConnector {
  // Connect to all registered pref stores, retrieving the current values of all
  // prefs in each store and an |observer| interfaces through which updates can
  // be received.
  //
  // The returned |connection| is the connection to the main writable user pref
  // store.
  //
  // Calls to |Connect| before |Init| are allowed and will cause the calls to
  // queue and connect once |Init| has been called.
  Connect(PrefRegistry pref_registry) =>
      (PersistentPrefStoreConnection connection,
       IncognitoPersistentPrefStoreConnection? underlay,
       array<PrefRegistration> remote_defaults,
       map<PrefStoreType, PrefStoreConnection> connections);
};

// An update to a subcomponent of a pref.
struct SubPrefUpdate {
  // The path to the changed value within the pref.
  array<string> path;
  // The new value; a null |value| indicates a delete.
  mojo.common.mojom.Value? value;
};

union PrefUpdateValue {
  // Updates to several values within a pref (e.g. inside a dictionary stored
  // under the pref key).
  array<SubPrefUpdate> split_updates;
  // An atomic update to the pref. A null |atomic_update| indicates a delete.
  mojo.common.mojom.Value? atomic_update;
};

// An update to a pref.
struct PrefUpdate {
  // The key of the pref being updated.
  string key;
  // The value update.
  PrefUpdateValue value;
  // |flags| is a bitmask of WritablePrefStore::PrefWriteFlags.
  uint32 flags;
};

// An interface providing mutation access to a PersistentPrefStore.
interface PersistentPrefStore {
  // Sets the values for prefs.
  SetValues(array<PrefUpdate> updates);

  // Requests that the pref service transmits its value for a pref (or sub-pref
  // if |sub_pref_path| is non-empty). The value will be transmitted over the
  // corresponding PrefStoreObserver interface previous returned by
  // PrefStoreConnector.Connect().
  RequestValue(string key, array<string> sub_pref_path);

  // These mirror the C++ PersistentPrefStore methods.
  CommitPendingWrite() => ();
  SchedulePendingLossyWrites();
  ClearMutableValues();
  OnStoreDeletionFromDisk();
};

// A registry of all prefs registered by a single client.
struct PrefRegistry {
  // A list of pref keys that are private to this client. This client claims
  // exclusive access to these prefs.
  array<string> private_registrations;

  // A list of pref keys that are public, but owned by another client.
  array<string> foreign_registrations;

  // A list of prefs that are publicly owned by this client. Each registration
  // contains the key, the default value and flags. These are shared with
  // clients that list the same pref in |foreign_registrations|.
  array<PrefRegistration> public_registrations;
};

struct PrefRegistration {
  string key;

  mojo.common.mojom.Value default_value;

  // A bitfield of flags. Flag values are defined in
  // PrefRegistry::PrefRegistrationFlags and
  // PrefRegistrySyncable::PrefRegistrationFlags.
  uint32 flags;
};

// ---------------------------------------------------------------------
// Service Configuration

// These parameters are passed to prefs::CreateTrackedPersistentPrefStore() in
// services/preferences/persistent_pref_store_factory.cc.
struct TrackedPersistentPrefStoreConfiguration {
  mojo_base.mojom.FilePath unprotected_pref_filename;
  mojo_base.mojom.FilePath protected_pref_filename;
  array<TrackedPreferenceMetadata> tracking_configuration;
  uint64 reporting_ids_count;
  string seed;
  string legacy_device_id;
  string registry_seed;
  mojo_base.mojom.String16 registry_path;
  TrackedPreferenceValidationDelegate? validation_delegate;
  ResetOnLoadObserver? reset_on_load_observer;
};

struct TrackedPreferenceMetadata {
  enum EnforcementLevel { NO_ENFORCEMENT, ENFORCE_ON_LOAD };

  enum PrefTrackingStrategy {
    // Atomic preferences are tracked as a whole.
    ATOMIC,
    // Split preferences are dictionaries for which each top-level entry is
    // tracked independently. Note: preferences using this strategy must be kept
    // in sync with TrackedSplitPreferences in histograms.xml.
    SPLIT,
  };

  enum ValueType {
    IMPERSONAL,
    // The preference value may contain personal information.
    PERSONAL,
  };

  uint64 reporting_id;
  string name;
  EnforcementLevel enforcement_level;
  PrefTrackingStrategy strategy;
  ValueType value_type;
};

interface ResetOnLoadObserver {
  OnResetOnLoad();
};