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
|
// Copyright (c) 2012 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 CHROME_BROWSER_PREFS_PREF_SERVICE_SYNCABLE_H_
#define CHROME_BROWSER_PREFS_PREF_SERVICE_SYNCABLE_H_
#include "chrome/browser/prefs/pref_model_associator.h"
#include "chrome/browser/prefs/pref_service.h"
class PrefServiceSyncableObserver;
namespace syncer {
class SyncableService;
}
// A PrefService that can be synced. Users are forced to declare
// whether preferences are syncable or not when registering them to
// this PrefService.
class PrefServiceSyncable : public PrefService {
public:
// Enum used when registering preferences to determine if it should be synced
// or not. This is only used for profile prefs, not local state prefs.
// See the Register*Pref methods for profile prefs below.
enum PrefSyncStatus {
UNSYNCABLE_PREF,
SYNCABLE_PREF
};
// You may wish to use PrefServiceBuilder or one of its subclasses
// for simplified construction.
PrefServiceSyncable(
PrefNotifierImpl* pref_notifier,
PrefValueStore* pref_value_store,
PersistentPrefStore* user_prefs,
DefaultPrefStore* default_store,
base::Callback<void(PersistentPrefStore::PrefReadError)>
read_error_callback,
bool async);
virtual ~PrefServiceSyncable();
// Creates an incognito copy of the pref service that shares most pref stores
// but uses a fresh non-persistent overlay for the user pref store and an
// individual extension pref store (to cache the effective extension prefs for
// incognito windows).
PrefServiceSyncable* CreateIncognitoPrefService(
PrefStore* incognito_extension_prefs);
// Returns true if preferences state has synchronized with the remote
// preferences. If true is returned it can be assumed the local preferences
// has applied changes from the remote preferences. The two may not be
// identical if a change is in flight (from either side).
bool IsSyncing();
void AddObserver(PrefServiceSyncableObserver* observer);
void RemoveObserver(PrefServiceSyncableObserver* observer);
virtual void UnregisterPreference(const char* path) OVERRIDE;
void RegisterBooleanPref(const char* path,
bool default_value,
PrefSyncStatus sync_status);
void RegisterIntegerPref(const char* path,
int default_value,
PrefSyncStatus sync_status);
void RegisterDoublePref(const char* path,
double default_value,
PrefSyncStatus sync_status);
void RegisterStringPref(const char* path,
const std::string& default_value,
PrefSyncStatus sync_status);
void RegisterFilePathPref(const char* path,
const FilePath& default_value,
PrefSyncStatus sync_status);
void RegisterListPref(const char* path,
PrefSyncStatus sync_status);
void RegisterDictionaryPref(const char* path,
PrefSyncStatus sync_status);
void RegisterListPref(const char* path,
base::ListValue* default_value,
PrefSyncStatus sync_status);
void RegisterDictionaryPref(const char* path,
base::DictionaryValue* default_value,
PrefSyncStatus sync_status);
void RegisterLocalizedBooleanPref(const char* path,
int locale_default_message_id,
PrefSyncStatus sync_status);
void RegisterLocalizedIntegerPref(const char* path,
int locale_default_message_id,
PrefSyncStatus sync_status);
void RegisterLocalizedDoublePref(const char* path,
int locale_default_message_id,
PrefSyncStatus sync_status);
void RegisterLocalizedStringPref(const char* path,
int locale_default_message_id,
PrefSyncStatus sync_status);
void RegisterInt64Pref(const char* path,
int64 default_value,
PrefSyncStatus sync_status);
void RegisterUint64Pref(const char* path,
uint64 default_value,
PrefSyncStatus sync_status);
// TODO(zea): Have PrefServiceSyncable implement
// syncer::SyncableService directly.
syncer::SyncableService* GetSyncableService();
// Do not call this after having derived an incognito or per tab pref service.
virtual void UpdateCommandLinePrefStore(PrefStore* cmd_line_store) OVERRIDE;
private:
friend class PrefModelAssociator;
// Invoked internally when the IsSyncing() state changes.
void OnIsSyncingChanged();
// Registers a preference at |path| with |default_value|. If the
// preference is syncable per |sync_status|, also registers it with
// PrefModelAssociator.
void RegisterSyncablePreference(const char* path,
Value* default_value,
PrefSyncStatus sync_status);
// Whether CreateIncognitoPrefService() has been called to create a
// "forked" PrefService.
bool pref_service_forked_;
PrefModelAssociator pref_sync_associator_;
ObserverList<PrefServiceSyncableObserver> observer_list_;
DISALLOW_COPY_AND_ASSIGN(PrefServiceSyncable);
};
#endif // CHROME_BROWSER_PREFS_PREF_SERVICE_SYNCABLE_H_
|