Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: chrome/browser/prefs/chrome_pref_service_factory.cc

Issue 11570009: Split PrefService into PrefService, PrefServiceSimple and PrefServiceSyncable. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments. Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 } 50 }
51 } 51 }
52 52
53 } // namespace 53 } // namespace
54 54
55 // TODO(joi): Find a better home for this. 55 // TODO(joi): Find a better home for this.
56 PrefServiceBase* PrefServiceBase::FromBrowserContext(BrowserContext* context) { 56 PrefServiceBase* PrefServiceBase::FromBrowserContext(BrowserContext* context) {
57 return static_cast<Profile*>(context)->GetPrefs(); 57 return static_cast<Profile*>(context)->GetPrefs();
58 } 58 }
59 59
60 ChromePrefServiceBuilder::ChromePrefServiceBuilder() { 60 ChromePrefServiceFactory::ChromePrefServiceFactory() {
61 ResetDefaultState(); 61 ResetDefaultState();
62 } 62 }
63 63
64 ChromePrefServiceBuilder::~ChromePrefServiceBuilder() { 64 ChromePrefServiceFactory::~ChromePrefServiceFactory() {
65 } 65 }
66 66
67 PrefService* ChromePrefServiceBuilder::CreateChromePrefs( 67 PrefServiceSimple* ChromePrefServiceFactory::CreateLocalState(
68 const FilePath& pref_filename, 68 const FilePath& pref_filename,
69 base::SequencedTaskRunner* pref_io_task_runner, 69 base::SequencedTaskRunner* pref_io_task_runner,
70 policy::PolicyService* policy_service, 70 policy::PolicyService* policy_service,
71 PrefStore* extension_prefs,
72 bool async) {
73 PrepareBuilder(pref_filename,
74 pref_io_task_runner,
75 policy_service,
76 extension_prefs,
77 async);
78
79 PrefServiceSimple* pref_service = new PrefServiceSimple();
80 builder_.Build(pref_service);
81 ResetDefaultState();
82 return pref_service;
83 }
84
85 PrefServiceSyncable* ChromePrefServiceFactory::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 PrepareBuilder(pref_filename,
92 pref_io_task_runner,
93 policy_service,
94 extension_prefs,
95 async);
96
97 PrefServiceSyncable* pref_service = new PrefServiceSyncable();
98 builder_.Build(pref_service);
99 ResetDefaultState();
100 return pref_service;
101 }
102
103 void ChromePrefServiceFactory::PrepareBuilder(
104 const FilePath& pref_filename,
105 base::SequencedTaskRunner* pref_io_task_runner,
106 policy::PolicyService* policy_service,
71 PrefStore* extension_prefs, 107 PrefStore* extension_prefs,
72 bool async) { 108 bool async) {
73 #if defined(OS_LINUX) 109 #if defined(OS_LINUX)
74 // We'd like to see what fraction of our users have the preferences 110 // 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 111 // stored on a network file system, as we've had no end of troubles
76 // with NFS/AFS. 112 // with NFS/AFS.
77 // TODO(evanm): remove this once we've collected state. 113 // TODO(evanm): remove this once we've collected state.
78 file_util::FileSystemType fstype; 114 file_util::FileSystemType fstype;
79 if (file_util::GetFileSystemType(pref_filename.DirName(), &fstype)) { 115 if (file_util::GetFileSystemType(pref_filename.DirName(), &fstype)) {
80 UMA_HISTOGRAM_ENUMERATION("PrefService.FileSystemType", 116 UMA_HISTOGRAM_ENUMERATION("PrefService.FileSystemType",
81 static_cast<int>(fstype), 117 static_cast<int>(fstype),
82 file_util::FILE_SYSTEM_TYPE_COUNT); 118 file_util::FILE_SYSTEM_TYPE_COUNT);
83 } 119 }
84 #endif 120 #endif
85 121
86 #if defined(ENABLE_CONFIGURATION_POLICY) 122 #if defined(ENABLE_CONFIGURATION_POLICY)
87 using policy::ConfigurationPolicyPrefStore; 123 using policy::ConfigurationPolicyPrefStore;
88 WithManagedPrefs( 124 builder_.WithManagedPrefs(
89 ConfigurationPolicyPrefStore::CreateMandatoryPolicyPrefStore( 125 ConfigurationPolicyPrefStore::CreateMandatoryPolicyPrefStore(
90 policy_service)); 126 policy_service));
91 WithRecommendedPrefs( 127 builder_.WithRecommendedPrefs(
92 ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore( 128 ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore(
93 policy_service)); 129 policy_service));
94 #endif // ENABLE_CONFIGURATION_POLICY 130 #endif // ENABLE_CONFIGURATION_POLICY
95 131
96 WithAsync(async); 132 builder_.WithAsync(async);
97 WithExtensionPrefs(extension_prefs); 133 builder_.WithExtensionPrefs(extension_prefs);
98 WithCommandLinePrefs( 134 builder_.WithCommandLinePrefs(
99 new CommandLinePrefStore(CommandLine::ForCurrentProcess())); 135 new CommandLinePrefStore(CommandLine::ForCurrentProcess()));
100 WithUserPrefs(new JsonPrefStore(pref_filename, pref_io_task_runner)); 136 builder_.WithUserPrefs(new JsonPrefStore(pref_filename, pref_io_task_runner));
101
102 PrefService* pref_service = Create();
103 ResetDefaultState();
104 return pref_service;
105 } 137 }
106 138
107 void ChromePrefServiceBuilder::ResetDefaultState() { 139 void ChromePrefServiceFactory::ResetDefaultState() {
108 WithReadErrorCallback(base::Bind(&HandleReadError)); 140 builder_.WithReadErrorCallback(base::Bind(&HandleReadError));
109 WithSyncAssociator(new PrefModelAssociator());
110 } 141 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698