-
Notifications
You must be signed in to change notification settings - Fork 6.6k
/
interceptable_pref_filter.h
65 lines (54 loc) · 2.74 KB
/
interceptable_pref_filter.h
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
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SERVICES_PREFERENCES_TRACKED_INTERCEPTABLE_PREF_FILTER_H_
#define SERVICES_PREFERENCES_TRACKED_INTERCEPTABLE_PREF_FILTER_H_
#include "base/callback.h"
#include "base/memory/weak_ptr.h"
#include "base/values.h"
#include "components/prefs/pref_filter.h"
// A partial implementation of a PrefFilter whose FilterOnLoad call may be
// intercepted by a FilterOnLoadInterceptor. Implementations of
// InterceptablePrefFilter are expected to override FinalizeFilterOnLoad rather
// than re-overriding FilterOnLoad.
class InterceptablePrefFilter
: public PrefFilter,
public base::SupportsWeakPtr<InterceptablePrefFilter> {
public:
// A callback to be invoked by a FilterOnLoadInterceptor when its ready to
// hand back the |prefs| it was handed for early filtering. |prefs_altered|
// indicates whether the |prefs| were actually altered by the
// FilterOnLoadInterceptor before being handed back.
using FinalizeFilterOnLoadCallback =
base::OnceCallback<void(base::Value::Dict prefs, bool prefs_altered)>;
// A callback to be invoked from FilterOnLoad. It takes ownership of prefs
// and may modify them before handing them back to this
// InterceptablePrefFilter via |finalize_filter_on_load|.
using FilterOnLoadInterceptor = base::OnceCallback<void(
FinalizeFilterOnLoadCallback finalize_filter_on_load,
base::Value::Dict prefs)>;
InterceptablePrefFilter();
~InterceptablePrefFilter() override;
// PrefFilter partial implementation.
void FilterOnLoad(PostFilterOnLoadCallback post_filter_on_load_callback,
base::Value::Dict pref_store_contents) override;
// Registers |filter_on_load_interceptor| to intercept the next FilterOnLoad
// event. At most one FilterOnLoadInterceptor should be registered per
// PrefFilter.
void InterceptNextFilterOnLoad(
FilterOnLoadInterceptor filter_on_load_interceptor);
void OnStoreDeletionFromDisk() override;
private:
// Does any extra filtering required by the implementation of this
// InterceptablePrefFilter and hands back the |pref_store_contents| to the
// initial caller of FilterOnLoad.
virtual void FinalizeFilterOnLoad(
PostFilterOnLoadCallback post_filter_on_load_callback,
base::Value::Dict pref_store_contents,
bool prefs_altered) = 0;
// Callback to be invoked only once (and subsequently reset) on the next
// FilterOnLoad event. It will be allowed to modify the |prefs| handed to
// FilterOnLoad before handing them back to this PrefHashFilter.
FilterOnLoadInterceptor filter_on_load_interceptor_;
};
#endif // SERVICES_PREFERENCES_TRACKED_INTERCEPTABLE_PREF_FILTER_H_