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" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h" | |
12 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
13 #include "components/prefs/pref_registry_simple.h" | 14 #include "components/prefs/pref_registry_simple.h" |
14 #include "components/prefs/pref_service.h" | 15 #include "components/prefs/pref_service.h" |
15 #include "components/prefs/scoped_user_pref_update.h" | 16 #include "components/prefs/scoped_user_pref_update.h" |
16 #include "content/public/browser/browser_context.h" | 17 #include "content/public/browser/browser_context.h" |
17 #include "extensions/browser/extension_registry.h" | 18 #include "extensions/browser/extension_registry.h" |
18 #include "extensions/common/feature_switch.h" | 19 #include "extensions/common/feature_switch.h" |
19 | 20 |
20 namespace extensions { | 21 namespace extensions { |
21 | 22 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 bool success = | 86 bool success = |
86 migration_pref->GetBoolean(component_action_id, &component_action_pref); | 87 migration_pref->GetBoolean(component_action_id, &component_action_pref); |
87 DCHECK(success); // Shouldn't fail, but can in case of pref corruption. | 88 DCHECK(success); // Shouldn't fail, but can in case of pref corruption. |
88 } | 89 } |
89 | 90 |
90 if (!has_component_action_pref && extension_was_installed) { | 91 if (!has_component_action_pref && extension_was_installed) { |
91 SetComponentActionPref(component_action_id, true); | 92 SetComponentActionPref(component_action_id, true); |
92 component_action_pref = true; | 93 component_action_pref = true; |
93 } | 94 } |
94 | 95 |
95 if (component_action_pref && | 96 if (component_action_pref) { |
mark a. foltz
2016/09/09 17:48:28
Just so I understand - this code is here to ensure
| |
96 !delegate_->HasComponentAction(component_action_id)) { | 97 if (component_action_id == |
97 delegate_->AddComponentAction(component_action_id); | 98 ComponentToolbarActionsFactory::kMediaRouterActionId) { |
99 pref_service_->SetBoolean(prefs::kMediaRouterAlwaysShowActionIcon, | |
mark a. foltz
2016/09/09 17:48:28
Can this only be set if the current value is not a
| |
100 true); | |
101 } | |
102 if (!delegate_->HasComponentAction(component_action_id)) | |
103 delegate_->AddComponentAction(component_action_id); | |
98 } | 104 } |
99 } | 105 } |
100 | 106 |
101 void ComponentMigrationHelper::OnFeatureDisabled( | 107 void ComponentMigrationHelper::OnFeatureDisabled( |
102 const std::string& component_action_id) { | 108 const std::string& component_action_id) { |
103 std::vector<ExtensionId> extension_ids = | 109 std::vector<ExtensionId> extension_ids = |
104 GetExtensionIdsForActionId(component_action_id); | 110 GetExtensionIdsForActionId(component_action_id); |
105 DCHECK(!extension_ids.empty()); | 111 DCHECK(!extension_ids.empty()); |
106 | 112 |
107 enabled_actions_.erase(component_action_id); | 113 enabled_actions_.erase(component_action_id); |
108 RemoveComponentActionPref(component_action_id); | 114 RemoveComponentActionPref(component_action_id); |
109 | 115 |
116 if (component_action_id == | |
mark a. foltz
2016/09/09 17:48:28
If the feature is disabled, we should not be creat
| |
117 ComponentToolbarActionsFactory::kMediaRouterActionId) { | |
118 pref_service_->SetBoolean(prefs::kMediaRouterAlwaysShowActionIcon, | |
119 false); | |
120 } | |
121 | |
110 if (FeatureSwitch::extension_action_redesign()->IsEnabled() && | 122 if (FeatureSwitch::extension_action_redesign()->IsEnabled() && |
111 delegate_->HasComponentAction(component_action_id)) | 123 delegate_->HasComponentAction(component_action_id)) |
112 delegate_->RemoveComponentAction(component_action_id); | 124 delegate_->RemoveComponentAction(component_action_id); |
113 } | 125 } |
114 | 126 |
115 void ComponentMigrationHelper::OnActionRemoved( | 127 void ComponentMigrationHelper::OnActionRemoved( |
116 const std::string& component_action_id) { | 128 const std::string& component_action_id) { |
117 // Record preference for the future. | 129 // Record preference for the future. |
118 SetComponentActionPref(component_action_id, false); | 130 SetComponentActionPref(component_action_id, false); |
119 | 131 |
120 // Remove the action. | 132 // Remove the action. |
121 if (delegate_->HasComponentAction(component_action_id)) | 133 if (delegate_->HasComponentAction(component_action_id)) |
122 delegate_->RemoveComponentAction(component_action_id); | 134 delegate_->RemoveComponentAction(component_action_id); |
123 } | 135 } |
124 | 136 |
125 void ComponentMigrationHelper::OnExtensionReady( | 137 void ComponentMigrationHelper::OnExtensionReady( |
126 content::BrowserContext* browser_context, | 138 content::BrowserContext* browser_context, |
127 const Extension* extension) { | 139 const Extension* extension) { |
128 const ExtensionId& extension_id = extension->id(); | 140 const ExtensionId& extension_id = extension->id(); |
129 const std::string& component_action_id = | 141 const std::string& component_action_id = |
130 GetActionIdForExtensionId(extension_id); | 142 GetActionIdForExtensionId(extension_id); |
131 if (component_action_id.empty()) | 143 if (component_action_id.empty()) |
132 return; | 144 return; |
133 if (base::ContainsKey(enabled_actions_, component_action_id)) { | 145 if (base::ContainsKey(enabled_actions_, component_action_id)) { |
134 UnloadExtension(extension_id); | 146 UnloadExtension(extension_id); |
135 SetComponentActionPref(component_action_id, true); | 147 SetComponentActionPref(component_action_id, true); |
136 | 148 |
149 // We treat installation of the cast extension as a signal to permanently | |
150 // show the icon in the toolbar. | |
151 if (component_action_id == | |
mark a. foltz
2016/09/09 17:48:28
Please check-and-set the pref.
| |
152 ComponentToolbarActionsFactory::kMediaRouterActionId) { | |
153 pref_service_->SetBoolean(prefs::kMediaRouterAlwaysShowActionIcon, | |
154 true); | |
155 } | |
156 | |
137 if (!delegate_->HasComponentAction(component_action_id)) | 157 if (!delegate_->HasComponentAction(component_action_id)) |
138 delegate_->AddComponentAction(component_action_id); | 158 delegate_->AddComponentAction(component_action_id); |
139 } | 159 } |
140 } | 160 } |
141 | 161 |
142 void ComponentMigrationHelper::SetComponentActionPref( | 162 void ComponentMigrationHelper::SetComponentActionPref( |
143 const std::string& component_action_id, | 163 const std::string& component_action_id, |
144 bool enabled) { | 164 bool enabled) { |
145 DictionaryPrefUpdate update(pref_service_, | 165 DictionaryPrefUpdate update(pref_service_, |
146 ::prefs::kToolbarMigratedComponentActionStatus); | 166 ::prefs::kToolbarMigratedComponentActionStatus); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
179 std::string ComponentMigrationHelper::GetActionIdForExtensionId( | 199 std::string ComponentMigrationHelper::GetActionIdForExtensionId( |
180 const ExtensionId& extension_id) const { | 200 const ExtensionId& extension_id) const { |
181 for (const auto& i : migrated_actions_) { | 201 for (const auto& i : migrated_actions_) { |
182 if (i.second == extension_id) | 202 if (i.second == extension_id) |
183 return i.first; | 203 return i.first; |
184 } | 204 } |
185 return ""; | 205 return ""; |
186 } | 206 } |
187 | 207 |
188 } // namespace extensions | 208 } // namespace extensions |
OLD | NEW |