| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "ios/chrome/browser/prefs/ios_chrome_pref_service_factory.h" | 5 #include "ios/chrome/browser/prefs/ios_chrome_pref_service_factory.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 // Record PersistentPrefStore's reading errors distribution. | 26 // Record PersistentPrefStore's reading errors distribution. |
| 27 void HandleReadError(PersistentPrefStore::PrefReadError error) { | 27 void HandleReadError(PersistentPrefStore::PrefReadError error) { |
| 28 // Sample the histogram also for the successful case in order to get a | 28 // Sample the histogram also for the successful case in order to get a |
| 29 // baseline on the success rate in addition to the error distribution. | 29 // baseline on the success rate in addition to the error distribution. |
| 30 UMA_HISTOGRAM_ENUMERATION("PrefService.ReadError", error, | 30 UMA_HISTOGRAM_ENUMERATION("PrefService.ReadError", error, |
| 31 PersistentPrefStore::PREF_READ_ERROR_MAX_ENUM); | 31 PersistentPrefStore::PREF_READ_ERROR_MAX_ENUM); |
| 32 } | 32 } |
| 33 | 33 |
| 34 void PrepareFactory(syncable_prefs::PrefServiceSyncableFactory* factory, | 34 void PrepareFactory(syncable_prefs::PrefServiceSyncableFactory* factory, |
| 35 policy::PolicyService* policy_service, | |
| 36 const base::FilePath& pref_filename, | 35 const base::FilePath& pref_filename, |
| 37 base::SequencedTaskRunner* pref_io_task_runner, | 36 base::SequencedTaskRunner* pref_io_task_runner, |
| 38 bool async) { | 37 bool async) { |
| 39 factory->set_user_prefs(make_scoped_refptr(new JsonPrefStore( | 38 factory->set_user_prefs(make_scoped_refptr(new JsonPrefStore( |
| 40 pref_filename, pref_io_task_runner, scoped_ptr<PrefFilter>()))); | 39 pref_filename, pref_io_task_runner, scoped_ptr<PrefFilter>()))); |
| 41 | 40 |
| 42 #if defined(ENABLE_CONFIGURATION_POLICY) | |
| 43 policy::BrowserPolicyConnector* policy_connector = | |
| 44 GetApplicationContext()->GetBrowserPolicyConnector(); | |
| 45 factory->SetManagedPolicies(policy_service, policy_connector); | |
| 46 factory->SetRecommendedPolicies(policy_service, policy_connector); | |
| 47 #endif // ENABLE_CONFIGURATION_POLICY | |
| 48 | |
| 49 factory->set_async(async); | 41 factory->set_async(async); |
| 50 factory->set_read_error_callback(base::Bind(&HandleReadError)); | 42 factory->set_read_error_callback(base::Bind(&HandleReadError)); |
| 51 factory->SetPrefModelAssociatorClient( | 43 factory->SetPrefModelAssociatorClient( |
| 52 IOSChromePrefModelAssociatorClient::GetInstance()); | 44 IOSChromePrefModelAssociatorClient::GetInstance()); |
| 53 } | 45 } |
| 54 | 46 |
| 55 } // namespace | 47 } // namespace |
| 56 | 48 |
| 57 scoped_ptr<PrefService> CreateLocalState( | 49 scoped_ptr<PrefService> CreateLocalState( |
| 58 const base::FilePath& pref_filename, | 50 const base::FilePath& pref_filename, |
| 59 base::SequencedTaskRunner* pref_io_task_runner, | 51 base::SequencedTaskRunner* pref_io_task_runner, |
| 60 policy::PolicyService* policy_service, | |
| 61 const scoped_refptr<PrefRegistry>& pref_registry, | 52 const scoped_refptr<PrefRegistry>& pref_registry, |
| 62 bool async) { | 53 bool async) { |
| 63 syncable_prefs::PrefServiceSyncableFactory factory; | 54 syncable_prefs::PrefServiceSyncableFactory factory; |
| 64 PrepareFactory(&factory, policy_service, pref_filename, pref_io_task_runner, | 55 PrepareFactory(&factory, pref_filename, pref_io_task_runner, async); |
| 65 async); | |
| 66 return factory.Create(pref_registry.get()); | 56 return factory.Create(pref_registry.get()); |
| 67 } | 57 } |
| 68 | 58 |
| 69 scoped_ptr<syncable_prefs::PrefServiceSyncable> CreateBrowserStatePrefs( | 59 scoped_ptr<syncable_prefs::PrefServiceSyncable> CreateBrowserStatePrefs( |
| 70 const base::FilePath& browser_state_path, | 60 const base::FilePath& browser_state_path, |
| 71 base::SequencedTaskRunner* pref_io_task_runner, | 61 base::SequencedTaskRunner* pref_io_task_runner, |
| 72 TrackedPreferenceValidationDelegate* validation_delegate, | 62 TrackedPreferenceValidationDelegate* validation_delegate, |
| 73 policy::PolicyService* policy_service, | |
| 74 const scoped_refptr<user_prefs::PrefRegistrySyncable>& pref_registry, | 63 const scoped_refptr<user_prefs::PrefRegistrySyncable>& pref_registry, |
| 75 bool async) { | 64 bool async) { |
| 76 // chrome_prefs::CreateProfilePrefs uses ProfilePrefStoreManager to create | 65 // chrome_prefs::CreateProfilePrefs uses ProfilePrefStoreManager to create |
| 77 // the preference store however since Chrome on iOS does not need to track | 66 // the preference store however since Chrome on iOS does not need to track |
| 78 // preference modifications (as applications are sand-boxed), it can use a | 67 // preference modifications (as applications are sand-boxed), it can use a |
| 79 // simple JsonPrefStore to store them (which is what PrefStoreManager uses | 68 // simple JsonPrefStore to store them (which is what PrefStoreManager uses |
| 80 // on platforms that do not track preference modifications). | 69 // on platforms that do not track preference modifications). |
| 81 syncable_prefs::PrefServiceSyncableFactory factory; | 70 syncable_prefs::PrefServiceSyncableFactory factory; |
| 82 PrepareFactory(&factory, policy_service, | 71 PrepareFactory(&factory, browser_state_path.Append(kPreferencesFilename), |
| 83 browser_state_path.Append(kPreferencesFilename), | |
| 84 pref_io_task_runner, async); | 72 pref_io_task_runner, async); |
| 85 scoped_ptr<syncable_prefs::PrefServiceSyncable> pref_service = | 73 scoped_ptr<syncable_prefs::PrefServiceSyncable> pref_service = |
| 86 factory.CreateSyncable(pref_registry.get()); | 74 factory.CreateSyncable(pref_registry.get()); |
| 87 ConfigureDefaultSearchPrefMigrationToDictionaryValue(pref_service.get()); | 75 ConfigureDefaultSearchPrefMigrationToDictionaryValue(pref_service.get()); |
| 88 return pref_service.Pass(); | 76 return pref_service.Pass(); |
| 89 } | 77 } |
| 90 | 78 |
| 91 scoped_ptr<syncable_prefs::PrefServiceSyncable> | 79 scoped_ptr<syncable_prefs::PrefServiceSyncable> |
| 92 CreateIncognitoBrowserStatePrefs( | 80 CreateIncognitoBrowserStatePrefs( |
| 93 syncable_prefs::PrefServiceSyncable* pref_service) { | 81 syncable_prefs::PrefServiceSyncable* pref_service) { |
| 94 // List of keys that cannot be changed in the user prefs file by the incognito | 82 // List of keys that cannot be changed in the user prefs file by the incognito |
| 95 // browser state. All preferences that store information about the browsing | 83 // browser state. All preferences that store information about the browsing |
| 96 // history or behaviour of the user should have this property. | 84 // history or behaviour of the user should have this property. |
| 97 std::vector<const char*> overlay_pref_names; | 85 std::vector<const char*> overlay_pref_names; |
| 98 overlay_pref_names.push_back(proxy_config::prefs::kProxy); | 86 overlay_pref_names.push_back(proxy_config::prefs::kProxy); |
| 99 return make_scoped_ptr(pref_service->CreateIncognitoPrefService( | 87 return make_scoped_ptr(pref_service->CreateIncognitoPrefService( |
| 100 nullptr, // incognito_extension_pref_store | 88 nullptr, // incognito_extension_pref_store |
| 101 overlay_pref_names)); | 89 overlay_pref_names)); |
| 102 } | 90 } |
| OLD | NEW |