1// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_PREFS_CHROME_PREF_SERVICE_FACTORY_H_
6#define CHROME_BROWSER_PREFS_CHROME_PREF_SERVICE_FACTORY_H_
7
8#include "base/memory/ref_counted.h"
9#include "base/memory/scoped_ptr.h"
10
11namespace base {
12class DictionaryValue;
13class FilePath;
14class SequencedTaskRunner;
15class Time;
16}
17
18namespace policy {
19class PolicyService;
20}
21
22namespace user_prefs {
23class PrefRegistrySyncable;
24}
25
26class PrefHashStore;
27class PrefRegistry;
28class PrefRegistrySimple;
29class PrefService;
30class PrefServiceSyncable;
31class PrefStore;
32class Profile;
33class SupervisedUserSettingsService;
34class TrackedPreferenceValidationDelegate;
35
36namespace chrome_prefs {
37
38namespace internals {
39
40extern const char kSettingsEnforcementTrialName[];
41extern const char kSettingsEnforcementGroupNoEnforcement[];
42extern const char kSettingsEnforcementGroupEnforceAlways[];
43extern const char kSettingsEnforcementGroupEnforceAlwaysWithDSE[];
44extern const char kSettingsEnforcementGroupEnforceAlwaysWithExtensionsAndDSE[];
45
46}  // namespace internals
47
48// Factory methods that create and initialize a new instance of a
49// PrefService for Chrome with the applicable PrefStores. The
50// |pref_filename| points to the user preference file. This is the
51// usual way to create a new PrefService.
52// |extension_pref_store| is used as the source for extension-controlled
53// preferences and may be NULL.
54// |policy_service| is used as the source for mandatory or recommended
55// policies.
56// |pref_registry| keeps the list of registered prefs and their default values.
57// If |async| is true, asynchronous version is used.
58// Notifies using PREF_INITIALIZATION_COMPLETED in the end. Details is set to
59// the created PrefService or NULL if creation has failed. Note, it is
60// guaranteed that in asynchronous version initialization happens after this
61// function returned.
62
63scoped_ptr<PrefService> CreateLocalState(
64    const base::FilePath& pref_filename,
65    base::SequencedTaskRunner* pref_io_task_runner,
66    policy::PolicyService* policy_service,
67    const scoped_refptr<PrefRegistry>& pref_registry,
68    bool async);
69
70scoped_ptr<PrefServiceSyncable> CreateProfilePrefs(
71    const base::FilePath& pref_filename,
72    base::SequencedTaskRunner* pref_io_task_runner,
73    TrackedPreferenceValidationDelegate* validation_delegate,
74    policy::PolicyService* policy_service,
75    SupervisedUserSettingsService* supervised_user_settings,
76    const scoped_refptr<PrefStore>& extension_prefs,
77    const scoped_refptr<user_prefs::PrefRegistrySyncable>& pref_registry,
78    bool async);
79
80// Schedules verification of the path resolution of the preferences file under
81// |profile_path|.
82void SchedulePrefsFilePathVerification(const base::FilePath& profile_path);
83
84// Call before startup tasks kick in to disable delays in
85// chrome_prefs::Schedule*() methods and ignore presence of a domain when
86// determining the active SettingsEnforcement group. For testing only.
87void DisableDelaysAndDomainCheckForTesting();
88
89// Schedules an update check for all PrefHashStores, stores whose version
90// doesn't match the latest version will then be updated. Clears all pref hash
91// state on platforms that don't yet support a pref hash store.
92void SchedulePrefHashStoresUpdateCheck(
93    const base::FilePath& initial_profile_path);
94
95// Initializes the preferences for the profile at |profile_path| with the
96// preference values in |master_prefs|. Returns true on success.
97bool InitializePrefsFromMasterPrefs(
98    const base::FilePath& profile_path,
99    const base::DictionaryValue& master_prefs);
100
101// Retrieves the time of the last preference reset event, if any, for the
102// provided profile. If no reset has occurred, returns a null |Time|.
103base::Time GetResetTime(Profile* profile);
104
105// Clears the time of the last preference reset event, if any, for the provided
106// profile.
107void ClearResetTime(Profile* profile);
108
109// Register local state prefs used by chrome preference system.
110void RegisterPrefs(PrefRegistrySimple* registry);
111
112// Register user prefs used by chrome preference system.
113void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
114
115}  // namespace chrome_prefs
116
117#endif  // CHROME_BROWSER_PREFS_CHROME_PREF_SERVICE_FACTORY_H_
118