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/memory/ptr_util.h" |
10 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
11 #include "components/prefs/json_pref_store.h" | 12 #include "components/prefs/json_pref_store.h" |
12 #include "components/prefs/persistent_pref_store.h" | 13 #include "components/prefs/persistent_pref_store.h" |
13 #include "components/prefs/pref_filter.h" | 14 #include "components/prefs/pref_filter.h" |
14 #include "components/prefs/pref_service.h" | 15 #include "components/prefs/pref_service.h" |
15 #include "components/proxy_config/proxy_config_pref_names.h" | 16 #include "components/proxy_config/proxy_config_pref_names.h" |
16 #include "components/search_engines/default_search_pref_migration.h" | 17 #include "components/search_engines/default_search_pref_migration.h" |
17 #include "components/syncable_prefs/pref_service_syncable.h" | 18 #include "components/syncable_prefs/pref_service_syncable.h" |
18 #include "components/syncable_prefs/pref_service_syncable_factory.h" | 19 #include "components/syncable_prefs/pref_service_syncable_factory.h" |
19 #include "ios/chrome/browser/application_context.h" | 20 #include "ios/chrome/browser/application_context.h" |
20 #include "ios/chrome/browser/prefs/ios_chrome_pref_model_associator_client.h" | 21 #include "ios/chrome/browser/prefs/ios_chrome_pref_model_associator_client.h" |
21 | 22 |
22 namespace { | 23 namespace { |
23 | 24 |
24 const char kPreferencesFilename[] = "Preferences"; | 25 const char kPreferencesFilename[] = "Preferences"; |
25 | 26 |
26 // Record PersistentPrefStore's reading errors distribution. | 27 // Record PersistentPrefStore's reading errors distribution. |
27 void HandleReadError(PersistentPrefStore::PrefReadError error) { | 28 void HandleReadError(PersistentPrefStore::PrefReadError error) { |
28 // Sample the histogram also for the successful case in order to get a | 29 // 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. | 30 // baseline on the success rate in addition to the error distribution. |
30 UMA_HISTOGRAM_ENUMERATION("PrefService.ReadError", error, | 31 UMA_HISTOGRAM_ENUMERATION("PrefService.ReadError", error, |
31 PersistentPrefStore::PREF_READ_ERROR_MAX_ENUM); | 32 PersistentPrefStore::PREF_READ_ERROR_MAX_ENUM); |
32 } | 33 } |
33 | 34 |
34 void PrepareFactory(syncable_prefs::PrefServiceSyncableFactory* factory, | 35 void PrepareFactory(syncable_prefs::PrefServiceSyncableFactory* factory, |
35 const base::FilePath& pref_filename, | 36 const base::FilePath& pref_filename, |
36 base::SequencedTaskRunner* pref_io_task_runner) { | 37 base::SequencedTaskRunner* pref_io_task_runner) { |
37 factory->set_user_prefs(make_scoped_refptr(new JsonPrefStore( | 38 factory->set_user_prefs(make_scoped_refptr(new JsonPrefStore( |
38 pref_filename, pref_io_task_runner, scoped_ptr<PrefFilter>()))); | 39 pref_filename, pref_io_task_runner, std::unique_ptr<PrefFilter>()))); |
39 | 40 |
40 factory->set_read_error_callback(base::Bind(&HandleReadError)); | 41 factory->set_read_error_callback(base::Bind(&HandleReadError)); |
41 factory->SetPrefModelAssociatorClient( | 42 factory->SetPrefModelAssociatorClient( |
42 IOSChromePrefModelAssociatorClient::GetInstance()); | 43 IOSChromePrefModelAssociatorClient::GetInstance()); |
43 } | 44 } |
44 | 45 |
45 } // namespace | 46 } // namespace |
46 | 47 |
47 scoped_ptr<PrefService> CreateLocalState( | 48 std::unique_ptr<PrefService> CreateLocalState( |
48 const base::FilePath& pref_filename, | 49 const base::FilePath& pref_filename, |
49 base::SequencedTaskRunner* pref_io_task_runner, | 50 base::SequencedTaskRunner* pref_io_task_runner, |
50 const scoped_refptr<PrefRegistry>& pref_registry) { | 51 const scoped_refptr<PrefRegistry>& pref_registry) { |
51 syncable_prefs::PrefServiceSyncableFactory factory; | 52 syncable_prefs::PrefServiceSyncableFactory factory; |
52 PrepareFactory(&factory, pref_filename, pref_io_task_runner); | 53 PrepareFactory(&factory, pref_filename, pref_io_task_runner); |
53 return factory.Create(pref_registry.get()); | 54 return factory.Create(pref_registry.get()); |
54 } | 55 } |
55 | 56 |
56 scoped_ptr<syncable_prefs::PrefServiceSyncable> CreateBrowserStatePrefs( | 57 std::unique_ptr<syncable_prefs::PrefServiceSyncable> CreateBrowserStatePrefs( |
57 const base::FilePath& browser_state_path, | 58 const base::FilePath& browser_state_path, |
58 base::SequencedTaskRunner* pref_io_task_runner, | 59 base::SequencedTaskRunner* pref_io_task_runner, |
59 const scoped_refptr<user_prefs::PrefRegistrySyncable>& pref_registry) { | 60 const scoped_refptr<user_prefs::PrefRegistrySyncable>& pref_registry) { |
60 // chrome_prefs::CreateProfilePrefs uses ProfilePrefStoreManager to create | 61 // chrome_prefs::CreateProfilePrefs uses ProfilePrefStoreManager to create |
61 // 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 |
62 // preference modifications (as applications are sand-boxed), it can use a | 63 // preference modifications (as applications are sand-boxed), it can use a |
63 // simple JsonPrefStore to store them (which is what PrefStoreManager uses | 64 // simple JsonPrefStore to store them (which is what PrefStoreManager uses |
64 // on platforms that do not track preference modifications). | 65 // on platforms that do not track preference modifications). |
65 syncable_prefs::PrefServiceSyncableFactory factory; | 66 syncable_prefs::PrefServiceSyncableFactory factory; |
66 PrepareFactory(&factory, browser_state_path.Append(kPreferencesFilename), | 67 PrepareFactory(&factory, browser_state_path.Append(kPreferencesFilename), |
67 pref_io_task_runner); | 68 pref_io_task_runner); |
68 scoped_ptr<syncable_prefs::PrefServiceSyncable> pref_service = | 69 std::unique_ptr<syncable_prefs::PrefServiceSyncable> pref_service = |
69 factory.CreateSyncable(pref_registry.get()); | 70 factory.CreateSyncable(pref_registry.get()); |
70 ConfigureDefaultSearchPrefMigrationToDictionaryValue(pref_service.get()); | 71 ConfigureDefaultSearchPrefMigrationToDictionaryValue(pref_service.get()); |
71 return pref_service; | 72 return pref_service; |
72 } | 73 } |
73 | 74 |
74 scoped_ptr<syncable_prefs::PrefServiceSyncable> | 75 std::unique_ptr<syncable_prefs::PrefServiceSyncable> |
75 CreateIncognitoBrowserStatePrefs( | 76 CreateIncognitoBrowserStatePrefs( |
76 syncable_prefs::PrefServiceSyncable* pref_service) { | 77 syncable_prefs::PrefServiceSyncable* pref_service) { |
77 // 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 |
78 // browser state. All preferences that store information about the browsing | 79 // browser state. All preferences that store information about the browsing |
79 // history or behaviour of the user should have this property. | 80 // history or behaviour of the user should have this property. |
80 std::vector<const char*> overlay_pref_names; | 81 std::vector<const char*> overlay_pref_names; |
81 overlay_pref_names.push_back(proxy_config::prefs::kProxy); | 82 overlay_pref_names.push_back(proxy_config::prefs::kProxy); |
82 return make_scoped_ptr(pref_service->CreateIncognitoPrefService( | 83 return base::WrapUnique(pref_service->CreateIncognitoPrefService( |
83 nullptr, // incognito_extension_pref_store | 84 nullptr, // incognito_extension_pref_store |
84 overlay_pref_names)); | 85 overlay_pref_names)); |
85 } | 86 } |
OLD | NEW |