| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "extensions/shell/browser/shell_prefs.h" | 5 #include "extensions/shell/browser/shell_prefs.h" |
| 6 | 6 |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 #include "components/pref_registry/pref_registry_syncable.h" | 8 #include "components/pref_registry/pref_registry_syncable.h" |
| 9 #include "components/prefs/json_pref_store.h" | 9 #include "components/prefs/json_pref_store.h" |
| 10 #include "components/prefs/pref_filter.h" | 10 #include "components/prefs/pref_filter.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 #endif | 32 #endif |
| 33 } | 33 } |
| 34 | 34 |
| 35 // Creates a JsonPrefStore from a file at |filepath| and synchronously loads | 35 // Creates a JsonPrefStore from a file at |filepath| and synchronously loads |
| 36 // the preferences. | 36 // the preferences. |
| 37 scoped_refptr<JsonPrefStore> CreateAndLoadPrefStore(const FilePath& filepath) { | 37 scoped_refptr<JsonPrefStore> CreateAndLoadPrefStore(const FilePath& filepath) { |
| 38 scoped_refptr<base::SequencedTaskRunner> task_runner = | 38 scoped_refptr<base::SequencedTaskRunner> task_runner = |
| 39 JsonPrefStore::GetTaskRunnerForFile( | 39 JsonPrefStore::GetTaskRunnerForFile( |
| 40 filepath, content::BrowserThread::GetBlockingPool()); | 40 filepath, content::BrowserThread::GetBlockingPool()); |
| 41 scoped_refptr<JsonPrefStore> pref_store = | 41 scoped_refptr<JsonPrefStore> pref_store = |
| 42 new JsonPrefStore(filepath, task_runner, scoped_ptr<PrefFilter>()); | 42 new JsonPrefStore(filepath, task_runner, std::unique_ptr<PrefFilter>()); |
| 43 pref_store->ReadPrefs(); // Synchronous. | 43 pref_store->ReadPrefs(); // Synchronous. |
| 44 return pref_store; | 44 return pref_store; |
| 45 } | 45 } |
| 46 | 46 |
| 47 } // namespace | 47 } // namespace |
| 48 | 48 |
| 49 namespace shell_prefs { | 49 namespace shell_prefs { |
| 50 | 50 |
| 51 scoped_ptr<PrefService> CreateLocalState(const FilePath& data_dir) { | 51 std::unique_ptr<PrefService> CreateLocalState(const FilePath& data_dir) { |
| 52 FilePath filepath = data_dir.AppendASCII("local_state.json"); | 52 FilePath filepath = data_dir.AppendASCII("local_state.json"); |
| 53 scoped_refptr<JsonPrefStore> pref_store = CreateAndLoadPrefStore(filepath); | 53 scoped_refptr<JsonPrefStore> pref_store = CreateAndLoadPrefStore(filepath); |
| 54 | 54 |
| 55 // Local state is considered "user prefs" from the factory's perspective. | 55 // Local state is considered "user prefs" from the factory's perspective. |
| 56 PrefServiceFactory factory; | 56 PrefServiceFactory factory; |
| 57 factory.set_user_prefs(pref_store); | 57 factory.set_user_prefs(pref_store); |
| 58 | 58 |
| 59 // Local state preferences are not syncable. | 59 // Local state preferences are not syncable. |
| 60 PrefRegistrySimple* registry = new PrefRegistrySimple; | 60 PrefRegistrySimple* registry = new PrefRegistrySimple; |
| 61 RegisterLocalStatePrefs(registry); | 61 RegisterLocalStatePrefs(registry); |
| 62 | 62 |
| 63 return factory.Create(registry); | 63 return factory.Create(registry); |
| 64 } | 64 } |
| 65 | 65 |
| 66 scoped_ptr<PrefService> CreateUserPrefService( | 66 std::unique_ptr<PrefService> CreateUserPrefService( |
| 67 content::BrowserContext* browser_context) { | 67 content::BrowserContext* browser_context) { |
| 68 FilePath filepath = browser_context->GetPath().AppendASCII("user_prefs.json"); | 68 FilePath filepath = browser_context->GetPath().AppendASCII("user_prefs.json"); |
| 69 scoped_refptr<JsonPrefStore> pref_store = CreateAndLoadPrefStore(filepath); | 69 scoped_refptr<JsonPrefStore> pref_store = CreateAndLoadPrefStore(filepath); |
| 70 | 70 |
| 71 PrefServiceFactory factory; | 71 PrefServiceFactory factory; |
| 72 factory.set_user_prefs(pref_store); | 72 factory.set_user_prefs(pref_store); |
| 73 | 73 |
| 74 // TODO(jamescook): If we want to support prefs that are set by extensions | 74 // TODO(jamescook): If we want to support prefs that are set by extensions |
| 75 // via ChromeSettings properties (e.g. chrome.accessibilityFeatures or | 75 // via ChromeSettings properties (e.g. chrome.accessibilityFeatures or |
| 76 // chrome.proxy) then this should create an ExtensionPrefStore and attach it | 76 // chrome.proxy) then this should create an ExtensionPrefStore and attach it |
| 77 // with PrefServiceFactory::set_extension_prefs(). | 77 // with PrefServiceFactory::set_extension_prefs(). |
| 78 // See https://developer.chrome.com/extensions/types#ChromeSetting | 78 // See https://developer.chrome.com/extensions/types#ChromeSetting |
| 79 | 79 |
| 80 // Prefs should be registered before the PrefService is created. | 80 // Prefs should be registered before the PrefService is created. |
| 81 PrefRegistrySyncable* pref_registry = new PrefRegistrySyncable; | 81 PrefRegistrySyncable* pref_registry = new PrefRegistrySyncable; |
| 82 ExtensionPrefs::RegisterProfilePrefs(pref_registry); | 82 ExtensionPrefs::RegisterProfilePrefs(pref_registry); |
| 83 | 83 |
| 84 scoped_ptr<PrefService> pref_service = factory.Create(pref_registry); | 84 std::unique_ptr<PrefService> pref_service = factory.Create(pref_registry); |
| 85 user_prefs::UserPrefs::Set(browser_context, pref_service.get()); | 85 user_prefs::UserPrefs::Set(browser_context, pref_service.get()); |
| 86 return pref_service; | 86 return pref_service; |
| 87 } | 87 } |
| 88 | 88 |
| 89 } // namespace shell_prefs | 89 } // namespace shell_prefs |
| 90 | 90 |
| 91 } // namespace extensions | 91 } // namespace extensions |
| OLD | NEW |