1 // Copyright 2013 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 "base/prefs/pref_service_factory.h"
6
7 #include "base/bind.h"
8 #include "base/prefs/default_pref_store.h"
9 #include "base/prefs/json_pref_store.h"
10 #include "base/prefs/pref_filter.h"
11 #include "base/prefs/pref_notifier_impl.h"
12 #include "base/prefs/pref_service.h"
13
14 #include "base/prefs/pref_value_store.h"
15
16 namespace base {
17
18 namespace {
19
20 // Do-nothing default implementation.
DoNothingHandleReadError(PersistentPrefStore::PrefReadError error)21 void DoNothingHandleReadError(PersistentPrefStore::PrefReadError error) {
22 }
23
24 } // namespace
25
PrefServiceFactory()26 PrefServiceFactory::PrefServiceFactory()
27 : managed_prefs_(NULL),
28 supervised_user_prefs_(NULL),
29 extension_prefs_(NULL),
30 command_line_prefs_(NULL),
31 user_prefs_(NULL),
32 recommended_prefs_(NULL),
33 read_error_callback_(base::Bind(&DoNothingHandleReadError)),
34 async_(false) {}
35
~PrefServiceFactory()36 PrefServiceFactory::~PrefServiceFactory() {}
37
SetUserPrefsFile(const base::FilePath & prefs_file,base::SequencedTaskRunner * task_runner)38 void PrefServiceFactory::SetUserPrefsFile(
39 const base::FilePath& prefs_file,
40 base::SequencedTaskRunner* task_runner) {
41 user_prefs_ = new JsonPrefStore(
42 prefs_file, task_runner, scoped_ptr<PrefFilter>());
43 }
44
Create(PrefRegistry * pref_registry)45 scoped_ptr<PrefService> PrefServiceFactory::Create(
46 PrefRegistry* pref_registry) {
47 PrefNotifierImpl* pref_notifier = new PrefNotifierImpl();
48 scoped_ptr<PrefService> pref_service(
49 new PrefService(pref_notifier,
50 new PrefValueStore(managed_prefs_.get(),
51 supervised_user_prefs_.get(),
52 extension_prefs_.get(),
53 command_line_prefs_.get(),
54 user_prefs_.get(),
55 recommended_prefs_.get(),
56 pref_registry->defaults().get(),
57 pref_notifier),
58 user_prefs_.get(),
59 pref_registry,
60 read_error_callback_,
61 async_));
62 return pref_service.Pass();
63 }
64
65 } // namespace base
66