| 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 15 matching lines...) Expand all Loading... |
| 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 const base::FilePath& pref_filename, | 35 const base::FilePath& pref_filename, |
| 36 base::SequencedTaskRunner* pref_io_task_runner, | 36 base::SequencedTaskRunner* pref_io_task_runner) { |
| 37 bool async) { | |
| 38 factory->set_user_prefs(make_scoped_refptr(new JsonPrefStore( | 37 factory->set_user_prefs(make_scoped_refptr(new JsonPrefStore( |
| 39 pref_filename, pref_io_task_runner, scoped_ptr<PrefFilter>()))); | 38 pref_filename, pref_io_task_runner, scoped_ptr<PrefFilter>()))); |
| 40 | 39 |
| 41 factory->set_async(async); | |
| 42 factory->set_read_error_callback(base::Bind(&HandleReadError)); | 40 factory->set_read_error_callback(base::Bind(&HandleReadError)); |
| 43 factory->SetPrefModelAssociatorClient( | 41 factory->SetPrefModelAssociatorClient( |
| 44 IOSChromePrefModelAssociatorClient::GetInstance()); | 42 IOSChromePrefModelAssociatorClient::GetInstance()); |
| 45 } | 43 } |
| 46 | 44 |
| 47 } // namespace | 45 } // namespace |
| 48 | 46 |
| 49 scoped_ptr<PrefService> CreateLocalState( | 47 scoped_ptr<PrefService> CreateLocalState( |
| 50 const base::FilePath& pref_filename, | 48 const base::FilePath& pref_filename, |
| 51 base::SequencedTaskRunner* pref_io_task_runner, | 49 base::SequencedTaskRunner* pref_io_task_runner, |
| 52 const scoped_refptr<PrefRegistry>& pref_registry, | 50 const scoped_refptr<PrefRegistry>& pref_registry) { |
| 53 bool async) { | |
| 54 syncable_prefs::PrefServiceSyncableFactory factory; | 51 syncable_prefs::PrefServiceSyncableFactory factory; |
| 55 PrepareFactory(&factory, pref_filename, pref_io_task_runner, async); | 52 PrepareFactory(&factory, pref_filename, pref_io_task_runner); |
| 56 return factory.Create(pref_registry.get()); | 53 return factory.Create(pref_registry.get()); |
| 57 } | 54 } |
| 58 | 55 |
| 59 scoped_ptr<syncable_prefs::PrefServiceSyncable> CreateBrowserStatePrefs( | 56 scoped_ptr<syncable_prefs::PrefServiceSyncable> CreateBrowserStatePrefs( |
| 60 const base::FilePath& browser_state_path, | 57 const base::FilePath& browser_state_path, |
| 61 base::SequencedTaskRunner* pref_io_task_runner, | 58 base::SequencedTaskRunner* pref_io_task_runner, |
| 62 TrackedPreferenceValidationDelegate* validation_delegate, | 59 TrackedPreferenceValidationDelegate* validation_delegate, |
| 63 const scoped_refptr<user_prefs::PrefRegistrySyncable>& pref_registry, | 60 const scoped_refptr<user_prefs::PrefRegistrySyncable>& pref_registry) { |
| 64 bool async) { | |
| 65 // chrome_prefs::CreateProfilePrefs uses ProfilePrefStoreManager to create | 61 // chrome_prefs::CreateProfilePrefs uses ProfilePrefStoreManager to create |
| 66 // the preference store however since Chrome on iOS does not need to track | 62 // the preference store however since Chrome on iOS does not need to track |
| 67 // preference modifications (as applications are sand-boxed), it can use a | 63 // preference modifications (as applications are sand-boxed), it can use a |
| 68 // simple JsonPrefStore to store them (which is what PrefStoreManager uses | 64 // simple JsonPrefStore to store them (which is what PrefStoreManager uses |
| 69 // on platforms that do not track preference modifications). | 65 // on platforms that do not track preference modifications). |
| 70 syncable_prefs::PrefServiceSyncableFactory factory; | 66 syncable_prefs::PrefServiceSyncableFactory factory; |
| 71 PrepareFactory(&factory, browser_state_path.Append(kPreferencesFilename), | 67 PrepareFactory(&factory, browser_state_path.Append(kPreferencesFilename), |
| 72 pref_io_task_runner, async); | 68 pref_io_task_runner); |
| 73 scoped_ptr<syncable_prefs::PrefServiceSyncable> pref_service = | 69 scoped_ptr<syncable_prefs::PrefServiceSyncable> pref_service = |
| 74 factory.CreateSyncable(pref_registry.get()); | 70 factory.CreateSyncable(pref_registry.get()); |
| 75 ConfigureDefaultSearchPrefMigrationToDictionaryValue(pref_service.get()); | 71 ConfigureDefaultSearchPrefMigrationToDictionaryValue(pref_service.get()); |
| 76 return pref_service.Pass(); | 72 return pref_service.Pass(); |
| 77 } | 73 } |
| 78 | 74 |
| 79 scoped_ptr<syncable_prefs::PrefServiceSyncable> | 75 scoped_ptr<syncable_prefs::PrefServiceSyncable> |
| 80 CreateIncognitoBrowserStatePrefs( | 76 CreateIncognitoBrowserStatePrefs( |
| 81 syncable_prefs::PrefServiceSyncable* pref_service) { | 77 syncable_prefs::PrefServiceSyncable* pref_service) { |
| 82 // List of keys that cannot be changed in the user prefs file by the incognito | 78 // List of keys that cannot be changed in the user prefs file by the incognito |
| 83 // browser state. All preferences that store information about the browsing | 79 // browser state. All preferences that store information about the browsing |
| 84 // history or behaviour of the user should have this property. | 80 // history or behaviour of the user should have this property. |
| 85 std::vector<const char*> overlay_pref_names; | 81 std::vector<const char*> overlay_pref_names; |
| 86 overlay_pref_names.push_back(proxy_config::prefs::kProxy); | 82 overlay_pref_names.push_back(proxy_config::prefs::kProxy); |
| 87 return make_scoped_ptr(pref_service->CreateIncognitoPrefService( | 83 return make_scoped_ptr(pref_service->CreateIncognitoPrefService( |
| 88 nullptr, // incognito_extension_pref_store | 84 nullptr, // incognito_extension_pref_store |
| 89 overlay_pref_names)); | 85 overlay_pref_names)); |
| 90 } | 86 } |
| OLD | NEW |