OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/extensions/component_migration_helper.h" | 5 #include "chrome/browser/extensions/component_migration_helper.h" |
6 | 6 |
7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
10 #include "chrome/browser/extensions/extension_system_impl.h" | 10 #include "chrome/browser/extensions/extension_system_impl.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
72 if (IsExtensionInstalledAndEnabled(id)) { | 72 if (IsExtensionInstalledAndEnabled(id)) { |
73 extension_was_installed = true; | 73 extension_was_installed = true; |
74 UnloadExtension(id); | 74 UnloadExtension(id); |
75 } | 75 } |
76 } | 76 } |
77 | 77 |
78 // Read the pref to determine component action status. If not set, set to | 78 // Read the pref to determine component action status. If not set, set to |
79 // true if we unloaded an extension. | 79 // true if we unloaded an extension. |
80 const base::DictionaryValue* migration_pref = pref_service_->GetDictionary( | 80 const base::DictionaryValue* migration_pref = pref_service_->GetDictionary( |
81 ::prefs::kToolbarMigratedComponentActionStatus); | 81 ::prefs::kToolbarMigratedComponentActionStatus); |
82 bool has_component_action_pref = migration_pref->HasKey(component_action_id); | |
83 bool component_action_pref = false; | 82 bool component_action_pref = false; |
84 if (has_component_action_pref) { | 83 if (migration_pref->HasKey(component_action_id)) { |
85 bool success = | 84 component_action_pref = GetComponentActionPref(component_action_id); |
86 migration_pref->GetBoolean(component_action_id, &component_action_pref); | 85 } else if (extension_was_installed) { |
87 DCHECK(success); // Shouldn't fail, but can in case of pref corruption. | |
88 } | |
89 | |
90 if (!has_component_action_pref && extension_was_installed) { | |
91 SetComponentActionPref(component_action_id, true); | 86 SetComponentActionPref(component_action_id, true); |
92 component_action_pref = true; | 87 component_action_pref = true; |
93 } | 88 } |
94 | 89 |
95 if (component_action_pref && | 90 if (component_action_pref && |
96 !delegate_->HasComponentAction(component_action_id)) { | 91 !delegate_->HasComponentAction(component_action_id)) { |
97 delegate_->AddComponentAction(component_action_id); | 92 delegate_->AddComponentAction(component_action_id); |
98 } | 93 } |
99 } | 94 } |
100 | 95 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
132 return; | 127 return; |
133 if (base::ContainsKey(enabled_actions_, component_action_id)) { | 128 if (base::ContainsKey(enabled_actions_, component_action_id)) { |
134 UnloadExtension(extension_id); | 129 UnloadExtension(extension_id); |
135 SetComponentActionPref(component_action_id, true); | 130 SetComponentActionPref(component_action_id, true); |
136 | 131 |
137 if (!delegate_->HasComponentAction(component_action_id)) | 132 if (!delegate_->HasComponentAction(component_action_id)) |
138 delegate_->AddComponentAction(component_action_id); | 133 delegate_->AddComponentAction(component_action_id); |
139 } | 134 } |
140 } | 135 } |
141 | 136 |
137 bool ComponentMigrationHelper::GetComponentActionPref( | |
138 const std::string& component_action_id) const { | |
139 const base::DictionaryValue* migration_pref = pref_service_->GetDictionary( | |
140 ::prefs::kToolbarMigratedComponentActionStatus); | |
141 bool component_action_pref = false; | |
142 | |
143 migration_pref->GetBoolean(component_action_id, &component_action_pref); | |
takumif
2016/09/16 21:04:05
I can't DCHECK here because the MRActionController
Devlin
2016/09/16 22:37:32
The DCHECK was actually because it was always supp
takumif
2016/09/17 00:24:29
I see. Yes, it happens when MRActionController obs
| |
144 return component_action_pref; | |
145 } | |
146 | |
142 void ComponentMigrationHelper::SetComponentActionPref( | 147 void ComponentMigrationHelper::SetComponentActionPref( |
143 const std::string& component_action_id, | 148 const std::string& component_action_id, |
144 bool enabled) { | 149 bool enabled) { |
145 DictionaryPrefUpdate update(pref_service_, | 150 DictionaryPrefUpdate update(pref_service_, |
146 ::prefs::kToolbarMigratedComponentActionStatus); | 151 ::prefs::kToolbarMigratedComponentActionStatus); |
147 update->SetBoolean(component_action_id, enabled); | 152 update->SetBoolean(component_action_id, enabled); |
148 } | 153 } |
149 | 154 |
150 bool ComponentMigrationHelper::IsExtensionInstalledAndEnabled( | 155 bool ComponentMigrationHelper::IsExtensionInstalledAndEnabled( |
151 const ExtensionId& extension_id) const { | 156 const ExtensionId& extension_id) const { |
(...skipping 27 matching lines...) Expand all Loading... | |
179 std::string ComponentMigrationHelper::GetActionIdForExtensionId( | 184 std::string ComponentMigrationHelper::GetActionIdForExtensionId( |
180 const ExtensionId& extension_id) const { | 185 const ExtensionId& extension_id) const { |
181 for (const auto& i : migrated_actions_) { | 186 for (const auto& i : migrated_actions_) { |
182 if (i.second == extension_id) | 187 if (i.second == extension_id) |
183 return i.first; | 188 return i.first; |
184 } | 189 } |
185 return ""; | 190 return ""; |
186 } | 191 } |
187 | 192 |
188 } // namespace extensions | 193 } // namespace extensions |
OLD | NEW |