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