OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/prefs/chrome_pref_service_builder.h" | 5 #include "chrome/browser/prefs/chrome_pref_service_builder.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 return static_cast<Profile*>(context)->GetPrefs(); | 64 return static_cast<Profile*>(context)->GetPrefs(); |
65 } | 65 } |
66 | 66 |
67 ChromePrefServiceBuilder::ChromePrefServiceBuilder() { | 67 ChromePrefServiceBuilder::ChromePrefServiceBuilder() { |
68 ResetDefaultState(); | 68 ResetDefaultState(); |
69 } | 69 } |
70 | 70 |
71 ChromePrefServiceBuilder::~ChromePrefServiceBuilder() { | 71 ChromePrefServiceBuilder::~ChromePrefServiceBuilder() { |
72 } | 72 } |
73 | 73 |
74 PrefService* ChromePrefServiceBuilder::CreateChromePrefs( | 74 PrefServiceSimple* ChromePrefServiceBuilder::CreateLocalState( |
75 const FilePath& pref_filename, | 75 const FilePath& pref_filename, |
76 base::SequencedTaskRunner* pref_io_task_runner, | 76 base::SequencedTaskRunner* pref_io_task_runner, |
77 policy::PolicyService* policy_service, | 77 policy::PolicyService* policy_service, |
| 78 PrefStore* extension_prefs, |
| 79 bool async) { |
| 80 PrefService* pref_service = Build(new PrefServiceSimple); |
| 81 ResetDefaultState(); |
| 82 return static_cast<PrefServiceSimple*>(pref_service); |
| 83 } |
| 84 |
| 85 PrefServiceSyncable* ChromePrefServiceBuilder::CreateProfilePrefs( |
| 86 const FilePath& pref_filename, |
| 87 base::SequencedTaskRunner* pref_io_task_runner, |
| 88 policy::PolicyService* policy_service, |
| 89 PrefStore* extension_prefs, |
| 90 bool async) { |
| 91 PrefService* pref_service = Build(new PrefServiceSyncable); |
| 92 ResetDefaultState(); |
| 93 return static_cast<PrefServiceSyncable*>(pref_service); |
| 94 } |
| 95 |
| 96 void ChromePrefServiceBuilder::BuildImpl( |
| 97 const FilePath& pref_filename, |
| 98 base::SequencedTaskRunner* pref_io_task_runner, |
| 99 policy::PolicyService* policy_service, |
78 PrefStore* extension_prefs, | 100 PrefStore* extension_prefs, |
79 bool async) { | 101 bool async) { |
80 #if defined(OS_LINUX) | 102 #if defined(OS_LINUX) |
81 // We'd like to see what fraction of our users have the preferences | 103 // We'd like to see what fraction of our users have the preferences |
82 // stored on a network file system, as we've had no end of troubles | 104 // stored on a network file system, as we've had no end of troubles |
83 // with NFS/AFS. | 105 // with NFS/AFS. |
84 // TODO(evanm): remove this once we've collected state. | 106 // TODO(evanm): remove this once we've collected state. |
85 file_util::FileSystemType fstype; | 107 file_util::FileSystemType fstype; |
86 if (file_util::GetFileSystemType(pref_filename.DirName(), &fstype)) { | 108 if (file_util::GetFileSystemType(pref_filename.DirName(), &fstype)) { |
87 UMA_HISTOGRAM_ENUMERATION("PrefService.FileSystemType", | 109 UMA_HISTOGRAM_ENUMERATION("PrefService.FileSystemType", |
88 static_cast<int>(fstype), | 110 static_cast<int>(fstype), |
89 file_util::FILE_SYSTEM_TYPE_COUNT); | 111 file_util::FILE_SYSTEM_TYPE_COUNT); |
90 } | 112 } |
91 #endif | 113 #endif |
92 | 114 |
93 #if defined(ENABLE_CONFIGURATION_POLICY) | 115 #if defined(ENABLE_CONFIGURATION_POLICY) |
94 using policy::ConfigurationPolicyPrefStore; | 116 using policy::ConfigurationPolicyPrefStore; |
95 WithManagedPrefs( | 117 WithManagedPrefs( |
96 ConfigurationPolicyPrefStore::CreateMandatoryPolicyPrefStore( | 118 ConfigurationPolicyPrefStore::CreateMandatoryPolicyPrefStore( |
97 policy_service)); | 119 policy_service)); |
98 WithRecommendedPrefs( | 120 WithRecommendedPrefs( |
99 ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore( | 121 ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore( |
100 policy_service)); | 122 policy_service)); |
101 #endif // ENABLE_CONFIGURATION_POLICY | 123 #endif // ENABLE_CONFIGURATION_POLICY |
102 | 124 |
103 WithAsync(async); | 125 WithAsync(async); |
104 WithCommandLinePrefs( | 126 WithCommandLinePrefs( |
105 new CommandLinePrefStore(CommandLine::ForCurrentProcess())); | 127 new CommandLinePrefStore(CommandLine::ForCurrentProcess())); |
106 WithUserPrefs(new JsonPrefStore(pref_filename, pref_io_task_runner)); | 128 WithUserPrefs(new JsonPrefStore(pref_filename, pref_io_task_runner)); |
107 | |
108 PrefService* pref_service = Create(); | |
109 ResetDefaultState(); | |
110 return pref_service; | |
111 } | 129 } |
112 | 130 |
113 void ChromePrefServiceBuilder::ResetDefaultState() { | 131 void ChromePrefServiceBuilder::ResetDefaultState() { |
114 WithLocalizedStringMethod(base::Bind(&l10n_util::GetStringUTF8)); | 132 WithLocalizedStringMethod(base::Bind(&l10n_util::GetStringUTF8)); |
115 WithReadErrorCallback(base::Bind(&HandleReadError)); | 133 WithReadErrorCallback(base::Bind(&HandleReadError)); |
116 WithSyncAssociator(new PrefModelAssociator()); | |
117 } | 134 } |
OLD | NEW |