| 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_factory.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" |
| 11 #include "base/prefs/default_pref_store.h" | 11 #include "base/prefs/default_pref_store.h" |
| 12 #include "base/prefs/json_pref_store.h" | 12 #include "base/prefs/json_pref_store.h" |
| 13 #include "chrome/browser/policy/configuration_policy_pref_store.h" | 13 #include "chrome/browser/policy/configuration_policy_pref_store.h" |
| 14 #include "chrome/browser/prefs/command_line_pref_store.h" | 14 #include "chrome/browser/prefs/command_line_pref_store.h" |
| 15 #include "chrome/browser/prefs/pref_model_associator.h" | 15 #include "chrome/browser/prefs/pref_model_associator.h" |
| 16 #include "chrome/browser/prefs/pref_notifier_impl.h" | 16 #include "chrome/browser/prefs/pref_notifier_impl.h" |
| 17 #include "chrome/browser/prefs/pref_service.h" | 17 #include "chrome/browser/prefs/pref_service.h" |
| 18 #include "chrome/browser/prefs/pref_service_syncable_builder.h" |
| 18 #include "chrome/browser/prefs/pref_value_store.h" | 19 #include "chrome/browser/prefs/pref_value_store.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/ui/profile_error_dialog.h" | 21 #include "chrome/browser/ui/profile_error_dialog.h" |
| 21 #include "content/public/browser/browser_context.h" | 22 #include "content/public/browser/browser_context.h" |
| 22 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
| 23 #include "grit/chromium_strings.h" | 24 #include "grit/chromium_strings.h" |
| 24 #include "grit/generated_resources.h" | 25 #include "grit/generated_resources.h" |
| 25 | 26 |
| 26 using content::BrowserContext; | 27 using content::BrowserContext; |
| 27 using content::BrowserThread; | 28 using content::BrowserThread; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 43 | 44 |
| 44 if (message_id) { | 45 if (message_id) { |
| 45 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 46 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 46 base::Bind(&ShowProfileErrorDialog, message_id)); | 47 base::Bind(&ShowProfileErrorDialog, message_id)); |
| 47 } | 48 } |
| 48 UMA_HISTOGRAM_ENUMERATION("PrefService.ReadError", error, | 49 UMA_HISTOGRAM_ENUMERATION("PrefService.ReadError", error, |
| 49 PersistentPrefStore::PREF_READ_ERROR_MAX_ENUM); | 50 PersistentPrefStore::PREF_READ_ERROR_MAX_ENUM); |
| 50 } | 51 } |
| 51 } | 52 } |
| 52 | 53 |
| 53 } // namespace | 54 void PrepareBuilder( |
| 54 | 55 PrefServiceSyncableBuilder* builder, |
| 55 // TODO(joi): Find a better home for this. | |
| 56 PrefServiceBase* PrefServiceBase::FromBrowserContext(BrowserContext* context) { | |
| 57 return static_cast<Profile*>(context)->GetPrefs(); | |
| 58 } | |
| 59 | |
| 60 ChromePrefServiceBuilder::ChromePrefServiceBuilder() { | |
| 61 ResetDefaultState(); | |
| 62 } | |
| 63 | |
| 64 ChromePrefServiceBuilder::~ChromePrefServiceBuilder() { | |
| 65 } | |
| 66 | |
| 67 PrefService* ChromePrefServiceBuilder::CreateChromePrefs( | |
| 68 const FilePath& pref_filename, | 56 const FilePath& pref_filename, |
| 69 base::SequencedTaskRunner* pref_io_task_runner, | 57 base::SequencedTaskRunner* pref_io_task_runner, |
| 70 policy::PolicyService* policy_service, | 58 policy::PolicyService* policy_service, |
| 71 PrefStore* extension_prefs, | 59 PrefStore* extension_prefs, |
| 72 bool async) { | 60 bool async) { |
| 73 #if defined(OS_LINUX) | 61 #if defined(OS_LINUX) |
| 74 // We'd like to see what fraction of our users have the preferences | 62 // We'd like to see what fraction of our users have the preferences |
| 75 // stored on a network file system, as we've had no end of troubles | 63 // stored on a network file system, as we've had no end of troubles |
| 76 // with NFS/AFS. | 64 // with NFS/AFS. |
| 77 // TODO(evanm): remove this once we've collected state. | 65 // TODO(evanm): remove this once we've collected state. |
| 78 file_util::FileSystemType fstype; | 66 file_util::FileSystemType fstype; |
| 79 if (file_util::GetFileSystemType(pref_filename.DirName(), &fstype)) { | 67 if (file_util::GetFileSystemType(pref_filename.DirName(), &fstype)) { |
| 80 UMA_HISTOGRAM_ENUMERATION("PrefService.FileSystemType", | 68 UMA_HISTOGRAM_ENUMERATION("PrefService.FileSystemType", |
| 81 static_cast<int>(fstype), | 69 static_cast<int>(fstype), |
| 82 file_util::FILE_SYSTEM_TYPE_COUNT); | 70 file_util::FILE_SYSTEM_TYPE_COUNT); |
| 83 } | 71 } |
| 84 #endif | 72 #endif |
| 85 | 73 |
| 86 #if defined(ENABLE_CONFIGURATION_POLICY) | 74 #if defined(ENABLE_CONFIGURATION_POLICY) |
| 87 using policy::ConfigurationPolicyPrefStore; | 75 using policy::ConfigurationPolicyPrefStore; |
| 88 WithManagedPrefs( | 76 builder->WithManagedPrefs( |
| 89 ConfigurationPolicyPrefStore::CreateMandatoryPolicyPrefStore( | 77 ConfigurationPolicyPrefStore::CreateMandatoryPolicyPrefStore( |
| 90 policy_service)); | 78 policy_service)); |
| 91 WithRecommendedPrefs( | 79 builder->WithRecommendedPrefs( |
| 92 ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore( | 80 ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore( |
| 93 policy_service)); | 81 policy_service)); |
| 94 #endif // ENABLE_CONFIGURATION_POLICY | 82 #endif // ENABLE_CONFIGURATION_POLICY |
| 95 | 83 |
| 96 WithAsync(async); | 84 builder->WithAsync(async); |
| 97 WithExtensionPrefs(extension_prefs); | 85 builder->WithExtensionPrefs(extension_prefs); |
| 98 WithCommandLinePrefs( | 86 builder->WithCommandLinePrefs( |
| 99 new CommandLinePrefStore(CommandLine::ForCurrentProcess())); | 87 new CommandLinePrefStore(CommandLine::ForCurrentProcess())); |
| 100 WithUserPrefs(new JsonPrefStore(pref_filename, pref_io_task_runner)); | 88 builder->WithReadErrorCallback(base::Bind(&HandleReadError)); |
| 101 | 89 builder->WithUserPrefs(new JsonPrefStore(pref_filename, pref_io_task_runner)); |
| 102 PrefService* pref_service = Create(); | |
| 103 ResetDefaultState(); | |
| 104 return pref_service; | |
| 105 } | 90 } |
| 106 | 91 |
| 107 void ChromePrefServiceBuilder::ResetDefaultState() { | 92 } // namespace |
| 108 WithReadErrorCallback(base::Bind(&HandleReadError)); | 93 |
| 109 WithSyncAssociator(new PrefModelAssociator()); | 94 // TODO(joi): Find a better home for this. |
| 95 PrefServiceBase* PrefServiceBase::FromBrowserContext(BrowserContext* context) { |
| 96 return static_cast<Profile*>(context)->GetPrefs(); |
| 110 } | 97 } |
| 98 |
| 99 namespace chrome_prefs { |
| 100 |
| 101 PrefServiceSimple* CreateLocalState( |
| 102 const FilePath& pref_filename, |
| 103 base::SequencedTaskRunner* pref_io_task_runner, |
| 104 policy::PolicyService* policy_service, |
| 105 PrefStore* extension_prefs, |
| 106 bool async) { |
| 107 PrefServiceSyncableBuilder builder; |
| 108 PrepareBuilder(&builder, |
| 109 pref_filename, |
| 110 pref_io_task_runner, |
| 111 policy_service, |
| 112 extension_prefs, |
| 113 async); |
| 114 return builder.CreateSimple(); |
| 115 } |
| 116 |
| 117 PrefServiceSyncable* CreateProfilePrefs( |
| 118 const FilePath& pref_filename, |
| 119 base::SequencedTaskRunner* pref_io_task_runner, |
| 120 policy::PolicyService* policy_service, |
| 121 PrefStore* extension_prefs, |
| 122 bool async) { |
| 123 PrefServiceSyncableBuilder builder; |
| 124 PrepareBuilder(&builder, |
| 125 pref_filename, |
| 126 pref_io_task_runner, |
| 127 policy_service, |
| 128 extension_prefs, |
| 129 async); |
| 130 return builder.CreateSyncable(); |
| 131 } |
| 132 |
| 133 } // namespace chrome_prefs |
| OLD | NEW |