OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/prefs/pref_value_store.h" | 5 #include "chrome/browser/prefs/pref_value_store.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/prefs/pref_notifier.h" | 8 #include "base/prefs/pref_notifier.h" |
9 #include "chrome/browser/prefs/pref_model_associator.h" | 9 #include "chrome/browser/prefs/pref_model_associator.h" |
10 | 10 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 bool succeeded) { | 45 bool succeeded) { |
46 pref_value_store_->OnInitializationCompleted(type_, succeeded); | 46 pref_value_store_->OnInitializationCompleted(type_, succeeded); |
47 } | 47 } |
48 | 48 |
49 PrefValueStore::PrefValueStore(PrefStore* managed_prefs, | 49 PrefValueStore::PrefValueStore(PrefStore* managed_prefs, |
50 PrefStore* extension_prefs, | 50 PrefStore* extension_prefs, |
51 PrefStore* command_line_prefs, | 51 PrefStore* command_line_prefs, |
52 PrefStore* user_prefs, | 52 PrefStore* user_prefs, |
53 PrefStore* recommended_prefs, | 53 PrefStore* recommended_prefs, |
54 PrefStore* default_prefs, | 54 PrefStore* default_prefs, |
55 PrefModelAssociator* pref_sync_associator, | |
56 PrefNotifier* pref_notifier) | 55 PrefNotifier* pref_notifier) |
57 : pref_sync_associator_(pref_sync_associator), | 56 : pref_sync_associator_(NULL), |
58 pref_notifier_(pref_notifier), | 57 pref_notifier_(pref_notifier), |
59 initialization_failed_(false) { | 58 initialization_failed_(false) { |
60 InitPrefStore(MANAGED_STORE, managed_prefs); | 59 InitPrefStore(MANAGED_STORE, managed_prefs); |
61 InitPrefStore(EXTENSION_STORE, extension_prefs); | 60 InitPrefStore(EXTENSION_STORE, extension_prefs); |
62 InitPrefStore(COMMAND_LINE_STORE, command_line_prefs); | 61 InitPrefStore(COMMAND_LINE_STORE, command_line_prefs); |
63 InitPrefStore(USER_STORE, user_prefs); | 62 InitPrefStore(USER_STORE, user_prefs); |
64 InitPrefStore(RECOMMENDED_STORE, recommended_prefs); | 63 InitPrefStore(RECOMMENDED_STORE, recommended_prefs); |
65 InitPrefStore(DEFAULT_STORE, default_prefs); | 64 InitPrefStore(DEFAULT_STORE, default_prefs); |
66 | 65 |
67 CheckInitializationCompleted(); | 66 CheckInitializationCompleted(); |
68 } | 67 } |
69 | 68 |
70 PrefValueStore::~PrefValueStore() {} | 69 PrefValueStore::~PrefValueStore() {} |
71 | 70 |
72 PrefValueStore* PrefValueStore::CloneAndSpecialize( | 71 PrefValueStore* PrefValueStore::CloneAndSpecialize( |
73 PrefStore* managed_prefs, | 72 PrefStore* managed_prefs, |
74 PrefStore* extension_prefs, | 73 PrefStore* extension_prefs, |
75 PrefStore* command_line_prefs, | 74 PrefStore* command_line_prefs, |
76 PrefStore* user_prefs, | 75 PrefStore* user_prefs, |
77 PrefStore* recommended_prefs, | 76 PrefStore* recommended_prefs, |
78 PrefStore* default_prefs, | 77 PrefStore* default_prefs, |
79 PrefModelAssociator* pref_sync_associator, | |
80 PrefNotifier* pref_notifier) { | 78 PrefNotifier* pref_notifier) { |
81 DCHECK(pref_notifier); | 79 DCHECK(pref_notifier); |
82 if (!managed_prefs) | 80 if (!managed_prefs) |
83 managed_prefs = GetPrefStore(MANAGED_STORE); | 81 managed_prefs = GetPrefStore(MANAGED_STORE); |
84 if (!extension_prefs) | 82 if (!extension_prefs) |
85 extension_prefs = GetPrefStore(EXTENSION_STORE); | 83 extension_prefs = GetPrefStore(EXTENSION_STORE); |
86 if (!command_line_prefs) | 84 if (!command_line_prefs) |
87 command_line_prefs = GetPrefStore(COMMAND_LINE_STORE); | 85 command_line_prefs = GetPrefStore(COMMAND_LINE_STORE); |
88 if (!user_prefs) | 86 if (!user_prefs) |
89 user_prefs = GetPrefStore(USER_STORE); | 87 user_prefs = GetPrefStore(USER_STORE); |
90 if (!recommended_prefs) | 88 if (!recommended_prefs) |
91 recommended_prefs = GetPrefStore(RECOMMENDED_STORE); | 89 recommended_prefs = GetPrefStore(RECOMMENDED_STORE); |
92 if (!default_prefs) | 90 if (!default_prefs) |
93 default_prefs = GetPrefStore(DEFAULT_STORE); | 91 default_prefs = GetPrefStore(DEFAULT_STORE); |
94 | 92 |
95 return new PrefValueStore( | 93 return new PrefValueStore( |
96 managed_prefs, extension_prefs, command_line_prefs, user_prefs, | 94 managed_prefs, extension_prefs, command_line_prefs, user_prefs, |
97 recommended_prefs, default_prefs, pref_sync_associator, pref_notifier); | 95 recommended_prefs, default_prefs, pref_notifier); |
| 96 } |
| 97 |
| 98 void PrefValueStore::set_sync_associator(PrefModelAssociator* sync_associator) { |
| 99 pref_sync_associator_ = sync_associator; |
98 } | 100 } |
99 | 101 |
100 bool PrefValueStore::GetValue(const std::string& name, | 102 bool PrefValueStore::GetValue(const std::string& name, |
101 base::Value::Type type, | 103 base::Value::Type type, |
102 const Value** out_value) const { | 104 const Value** out_value) const { |
103 // Check the |PrefStore|s in order of their priority from highest to lowest, | 105 // Check the |PrefStore|s in order of their priority from highest to lowest, |
104 // looking for the first preference value with the given |name| and |type|. | 106 // looking for the first preference value with the given |name| and |type|. |
105 for (size_t i = 0; i <= PREF_STORE_TYPE_MAX; ++i) { | 107 for (size_t i = 0; i <= PREF_STORE_TYPE_MAX; ++i) { |
106 if (GetValueFromStoreWithType(name.c_str(), type, | 108 if (GetValueFromStoreWithType(name.c_str(), type, |
107 static_cast<PrefStoreType>(i), out_value)) | 109 static_cast<PrefStoreType>(i), out_value)) |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 if (initialization_failed_) | 268 if (initialization_failed_) |
267 return; | 269 return; |
268 for (size_t i = 0; i <= PREF_STORE_TYPE_MAX; ++i) { | 270 for (size_t i = 0; i <= PREF_STORE_TYPE_MAX; ++i) { |
269 scoped_refptr<PrefStore> store = | 271 scoped_refptr<PrefStore> store = |
270 GetPrefStore(static_cast<PrefStoreType>(i)); | 272 GetPrefStore(static_cast<PrefStoreType>(i)); |
271 if (store && !store->IsInitializationComplete()) | 273 if (store && !store->IsInitializationComplete()) |
272 return; | 274 return; |
273 } | 275 } |
274 pref_notifier_->OnInitializationCompleted(true); | 276 pref_notifier_->OnInitializationCompleted(true); |
275 } | 277 } |
OLD | NEW |