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

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: Ready for review. 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"
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_value_store.h" 18 #include "chrome/browser/prefs/pref_value_store.h"
19 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/ui/profile_error_dialog.h" 20 #include "chrome/browser/ui/profile_error_dialog.h"
21 #include "content/public/browser/browser_context.h" 21 #include "content/public/browser/browser_context.h"
22 #include "content/public/browser/browser_thread.h" 22 #include "content/public/browser/browser_thread.h"
23 #include "grit/chromium_strings.h" 23 #include "grit/chromium_strings.h"
24 #include "grit/generated_resources.h" 24 #include "grit/generated_resources.h"
25 #include "ui/base/l10n/l10n_util.h"
26 25
27 using content::BrowserContext; 26 using content::BrowserContext;
28 using content::BrowserThread; 27 using content::BrowserThread;
29 28
30 namespace { 29 namespace {
31 30
32 // Forwards a notification after a PostMessage so that we can wait for the 31 // Forwards a notification after a PostMessage so that we can wait for the
33 // MessageLoop to run. 32 // MessageLoop to run.
34 void NotifyReadError(int message_id) { 33 void NotifyReadError(int message_id) {
35 ShowProfileErrorDialog(message_id); 34 ShowProfileErrorDialog(message_id);
(...skipping 21 matching lines...) Expand all
57 } 56 }
58 } 57 }
59 58
60 } // namespace 59 } // namespace
61 60
62 // TODO(joi): Find a better home for this. 61 // TODO(joi): Find a better home for this.
63 PrefServiceBase* PrefServiceBase::FromBrowserContext(BrowserContext* context) { 62 PrefServiceBase* PrefServiceBase::FromBrowserContext(BrowserContext* context) {
64 return static_cast<Profile*>(context)->GetPrefs(); 63 return static_cast<Profile*>(context)->GetPrefs();
65 } 64 }
66 65
67 ChromePrefServiceBuilder::ChromePrefServiceBuilder() { 66 ChromePrefServiceFactory::ChromePrefServiceFactory() {
68 ResetDefaultState(); 67 ResetDefaultState();
69 } 68 }
70 69
71 ChromePrefServiceBuilder::~ChromePrefServiceBuilder() { 70 ChromePrefServiceFactory::~ChromePrefServiceFactory() {
72 } 71 }
73 72
74 PrefService* ChromePrefServiceBuilder::CreateChromePrefs( 73 PrefServiceSimple* ChromePrefServiceFactory::CreateLocalState(
75 const FilePath& pref_filename, 74 const FilePath& pref_filename,
76 base::SequencedTaskRunner* pref_io_task_runner, 75 base::SequencedTaskRunner* pref_io_task_runner,
77 policy::PolicyService* policy_service, 76 policy::PolicyService* policy_service,
77 PrefStore* extension_prefs,
78 bool async) {
79 PrepareBuilder(pref_filename,
80 pref_io_task_runner,
81 policy_service,
82 extension_prefs,
83 async);
84
85 PrefServiceSimple* pref_service = new PrefServiceSimple();
Mattias Nissler (ping if slow) 2012/12/20 13:41:52 I think I posted this somewhere already, but to re
Jói 2012/12/20 16:30:31 We addressed that by making the constructor privat
Mattias Nissler (ping if slow) 2012/12/21 13:09:31 I would really prefer the ctor approach, which wou
86 builder_.Build(pref_service);
87 ResetDefaultState();
88 return pref_service;
89 }
90
91 PrefServiceSyncable* ChromePrefServiceFactory::CreateProfilePrefs(
92 const FilePath& pref_filename,
93 base::SequencedTaskRunner* pref_io_task_runner,
94 policy::PolicyService* policy_service,
95 PrefStore* extension_prefs,
96 bool async) {
97 PrepareBuilder(pref_filename,
98 pref_io_task_runner,
99 policy_service,
100 extension_prefs,
101 async);
102
103 PrefServiceSyncable* pref_service = new PrefServiceSyncable();
104 builder_.Build(pref_service);
105 ResetDefaultState();
106 return pref_service;
107 }
108
109 void ChromePrefServiceFactory::PrepareBuilder(
110 const FilePath& pref_filename,
111 base::SequencedTaskRunner* pref_io_task_runner,
112 policy::PolicyService* policy_service,
78 PrefStore* extension_prefs, 113 PrefStore* extension_prefs,
79 bool async) { 114 bool async) {
80 #if defined(OS_LINUX) 115 #if defined(OS_LINUX)
81 // We'd like to see what fraction of our users have the preferences 116 // 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 117 // stored on a network file system, as we've had no end of troubles
83 // with NFS/AFS. 118 // with NFS/AFS.
84 // TODO(evanm): remove this once we've collected state. 119 // TODO(evanm): remove this once we've collected state.
85 file_util::FileSystemType fstype; 120 file_util::FileSystemType fstype;
86 if (file_util::GetFileSystemType(pref_filename.DirName(), &fstype)) { 121 if (file_util::GetFileSystemType(pref_filename.DirName(), &fstype)) {
87 UMA_HISTOGRAM_ENUMERATION("PrefService.FileSystemType", 122 UMA_HISTOGRAM_ENUMERATION("PrefService.FileSystemType",
88 static_cast<int>(fstype), 123 static_cast<int>(fstype),
89 file_util::FILE_SYSTEM_TYPE_COUNT); 124 file_util::FILE_SYSTEM_TYPE_COUNT);
90 } 125 }
91 #endif 126 #endif
92 127
93 #if defined(ENABLE_CONFIGURATION_POLICY) 128 #if defined(ENABLE_CONFIGURATION_POLICY)
94 using policy::ConfigurationPolicyPrefStore; 129 using policy::ConfigurationPolicyPrefStore;
95 WithManagedPrefs( 130 builder_.WithManagedPrefs(
96 ConfigurationPolicyPrefStore::CreateMandatoryPolicyPrefStore( 131 ConfigurationPolicyPrefStore::CreateMandatoryPolicyPrefStore(
97 policy_service)); 132 policy_service));
98 WithRecommendedPrefs( 133 builder_.WithRecommendedPrefs(
99 ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore( 134 ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore(
100 policy_service)); 135 policy_service));
101 #endif // ENABLE_CONFIGURATION_POLICY 136 #endif // ENABLE_CONFIGURATION_POLICY
102 137
103 WithAsync(async); 138 builder_.WithAsync(async);
104 WithCommandLinePrefs( 139 builder_.WithCommandLinePrefs(
105 new CommandLinePrefStore(CommandLine::ForCurrentProcess())); 140 new CommandLinePrefStore(CommandLine::ForCurrentProcess()));
106 WithUserPrefs(new JsonPrefStore(pref_filename, pref_io_task_runner)); 141 builder_.WithUserPrefs(new JsonPrefStore(pref_filename, pref_io_task_runner));
107
108 PrefService* pref_service = Create();
109 ResetDefaultState();
110 return pref_service;
111 } 142 }
112 143
113 void ChromePrefServiceBuilder::ResetDefaultState() { 144 void ChromePrefServiceFactory::ResetDefaultState() {
114 WithLocalizedStringMethod(base::Bind(&l10n_util::GetStringUTF8)); 145 builder_.WithReadErrorCallback(base::Bind(&HandleReadError));
115 WithReadErrorCallback(base::Bind(&HandleReadError));
116 WithSyncAssociator(new PrefModelAssociator());
117 } 146 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698