Add CryptAuthDeviceManager for syncing the user's devices from CryptAuth.
[chromium-blink-merge.git] / chromecast / browser / pref_service_helper.cc
blob36ab18dcbcf416977b87c5b5e527ac40eb364088
1 // Copyright 2014 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.
5 #include "chromecast/browser/pref_service_helper.h"
7 #include <string>
9 #include "base/files/file_path.h"
10 #include "base/files/file_util.h"
11 #include "base/logging.h"
12 #include "base/path_service.h"
13 #include "base/prefs/json_pref_store.h"
14 #include "base/prefs/pref_registry_simple.h"
15 #include "base/prefs/pref_service_factory.h"
16 #include "base/prefs/pref_store.h"
17 #include "chromecast/base/cast_paths.h"
18 #include "chromecast/common/pref_names.h"
19 #include "content/public/browser/browser_thread.h"
21 namespace chromecast {
22 namespace shell {
24 namespace {
26 void UserPrefsLoadError(PersistentPrefStore::PrefReadError* error_val,
27 PersistentPrefStore::PrefReadError error) {
28 DCHECK(error_val);
29 *error_val = error;
32 base::FilePath GetConfigPath() {
33 base::FilePath config_path;
34 CHECK(PathService::Get(FILE_CAST_CONFIG, &config_path));
35 return config_path;
38 } // namespace
40 // static
41 scoped_ptr<PrefService> PrefServiceHelper::CreatePrefService(
42 PrefRegistrySimple* registry) {
43 const base::FilePath config_path(GetConfigPath());
44 VLOG(1) << "Loading config from " << config_path.value();
46 registry->RegisterBooleanPref(prefs::kEnableRemoteDebugging, false);
47 registry->RegisterBooleanPref(prefs::kMetricsIsNewClientID, false);
49 RegisterPlatformPrefs(registry);
51 base::PrefServiceFactory prefServiceFactory;
52 scoped_refptr<base::SequencedTaskRunner> task_runner =
53 JsonPrefStore::GetTaskRunnerForFile(
54 config_path,
55 content::BrowserThread::GetBlockingPool());
56 prefServiceFactory.SetUserPrefsFile(config_path, task_runner.get());
57 prefServiceFactory.set_async(false);
59 PersistentPrefStore::PrefReadError prefs_read_error =
60 PersistentPrefStore::PREF_READ_ERROR_NONE;
61 prefServiceFactory.set_read_error_callback(
62 base::Bind(&UserPrefsLoadError, &prefs_read_error));
64 scoped_ptr<PrefService> pref_service(prefServiceFactory.Create(registry));
65 if (prefs_read_error != PersistentPrefStore::PREF_READ_ERROR_NONE) {
66 LOG(ERROR) << "Cannot initialize chromecast config: "
67 << config_path.value()
68 << ", pref_error=" << prefs_read_error;
71 OnPrefsLoaded(pref_service.get());
72 return pref_service.Pass();
75 } // namespace shell
76 } // namespace chromecast