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

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

Issue 11570009: Split PrefService into PrefService, PrefServiceSimple and PrefServiceSyncable. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to head again, previous had unrelated broken win_rel test. 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
(Empty)
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 #include "chrome/browser/prefs/chrome_pref_service_builder.h"
6
7 #include "base/bind.h"
8 #include "base/file_path.h"
9 #include "base/file_util.h"
10 #include "base/metrics/histogram.h"
11 #include "base/prefs/default_pref_store.h"
12 #include "base/prefs/json_pref_store.h"
13 #include "chrome/browser/policy/configuration_policy_pref_store.h"
14 #include "chrome/browser/prefs/command_line_pref_store.h"
15 #include "chrome/browser/prefs/pref_model_associator.h"
16 #include "chrome/browser/prefs/pref_notifier_impl.h"
17 #include "chrome/browser/prefs/pref_service.h"
18 #include "chrome/browser/prefs/pref_value_store.h"
19 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/ui/profile_error_dialog.h"
21 #include "content/public/browser/browser_context.h"
22 #include "content/public/browser/browser_thread.h"
23 #include "grit/chromium_strings.h"
24 #include "grit/generated_resources.h"
25
26 using content::BrowserContext;
27 using content::BrowserThread;
28
29 namespace {
30
31 // Shows notifications which correspond to PersistentPrefStore's reading errors.
32 void HandleReadError(PersistentPrefStore::PrefReadError error) {
33 if (error != PersistentPrefStore::PREF_READ_ERROR_NONE) {
34 // Failing to load prefs on startup is a bad thing(TM). See bug 38352 for
35 // an example problem that this can cause.
36 // Do some diagnosis and try to avoid losing data.
37 int message_id = 0;
38 if (error <= PersistentPrefStore::PREF_READ_ERROR_JSON_TYPE) {
39 message_id = IDS_PREFERENCES_CORRUPT_ERROR;
40 } else if (error != PersistentPrefStore::PREF_READ_ERROR_NO_FILE) {
41 message_id = IDS_PREFERENCES_UNREADABLE_ERROR;
42 }
43
44 if (message_id) {
45 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
46 base::Bind(&ShowProfileErrorDialog, message_id));
47 }
48 UMA_HISTOGRAM_ENUMERATION("PrefService.ReadError", error,
49 PersistentPrefStore::PREF_READ_ERROR_MAX_ENUM);
50 }
51 }
52
53 } // namespace
54
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,
69 base::SequencedTaskRunner* pref_io_task_runner,
70 policy::PolicyService* policy_service,
71 PrefStore* extension_prefs,
72 bool async) {
73 #if defined(OS_LINUX)
74 // 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
76 // with NFS/AFS.
77 // TODO(evanm): remove this once we've collected state.
78 file_util::FileSystemType fstype;
79 if (file_util::GetFileSystemType(pref_filename.DirName(), &fstype)) {
80 UMA_HISTOGRAM_ENUMERATION("PrefService.FileSystemType",
81 static_cast<int>(fstype),
82 file_util::FILE_SYSTEM_TYPE_COUNT);
83 }
84 #endif
85
86 #if defined(ENABLE_CONFIGURATION_POLICY)
87 using policy::ConfigurationPolicyPrefStore;
88 WithManagedPrefs(
89 ConfigurationPolicyPrefStore::CreateMandatoryPolicyPrefStore(
90 policy_service));
91 WithRecommendedPrefs(
92 ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore(
93 policy_service));
94 #endif // ENABLE_CONFIGURATION_POLICY
95
96 WithAsync(async);
97 WithExtensionPrefs(extension_prefs);
98 WithCommandLinePrefs(
99 new CommandLinePrefStore(CommandLine::ForCurrentProcess()));
100 WithUserPrefs(new JsonPrefStore(pref_filename, pref_io_task_runner));
101
102 PrefService* pref_service = Create();
103 ResetDefaultState();
104 return pref_service;
105 }
106
107 void ChromePrefServiceBuilder::ResetDefaultState() {
108 WithReadErrorCallback(base::Bind(&HandleReadError));
109 WithSyncAssociator(new PrefModelAssociator());
110 }
OLDNEW
« no previous file with comments | « chrome/browser/prefs/chrome_pref_service_builder.h ('k') | chrome/browser/prefs/chrome_pref_service_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698