Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Side by Side Diff: chrome/browser/extensions/component_migration_helper.cc

Issue 2260343002: Revert of Show the Cast toolbar icon ephemerally when Cast is in use (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
13 #include "chrome/common/pref_names.h" 12 #include "chrome/common/pref_names.h"
14 #include "components/prefs/pref_registry_simple.h" 13 #include "components/prefs/pref_registry_simple.h"
15 #include "components/prefs/pref_service.h" 14 #include "components/prefs/pref_service.h"
16 #include "components/prefs/scoped_user_pref_update.h" 15 #include "components/prefs/scoped_user_pref_update.h"
17 #include "content/public/browser/browser_context.h" 16 #include "content/public/browser/browser_context.h"
18 #include "extensions/browser/extension_registry.h" 17 #include "extensions/browser/extension_registry.h"
19 #include "extensions/common/feature_switch.h" 18 #include "extensions/common/feature_switch.h"
20 19
21 namespace extensions { 20 namespace extensions {
22 21
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 DCHECK(success); // Shouldn't fail, but can in case of pref corruption. 87 DCHECK(success); // Shouldn't fail, but can in case of pref corruption.
89 } 88 }
90 89
91 if (!has_component_action_pref && extension_was_installed) { 90 if (!has_component_action_pref && extension_was_installed) {
92 SetComponentActionPref(component_action_id, true); 91 SetComponentActionPref(component_action_id, true);
93 component_action_pref = true; 92 component_action_pref = true;
94 } 93 }
95 94
96 if (component_action_pref && 95 if (component_action_pref &&
97 !delegate_->HasComponentAction(component_action_id)) { 96 !delegate_->HasComponentAction(component_action_id)) {
98 if (component_action_id ==
99 ComponentToolbarActionsFactory::kMediaRouterActionId) {
100 pref_service_->SetBoolean(prefs::kMediaRouterAlwaysShowActionIcon,
101 true);
102 }
103 delegate_->AddComponentAction(component_action_id); 97 delegate_->AddComponentAction(component_action_id);
104 } 98 }
105 } 99 }
106 100
107 void ComponentMigrationHelper::OnFeatureDisabled( 101 void ComponentMigrationHelper::OnFeatureDisabled(
108 const std::string& component_action_id) { 102 const std::string& component_action_id) {
109 std::vector<ExtensionId> extension_ids = 103 std::vector<ExtensionId> extension_ids =
110 GetExtensionIdsForActionId(component_action_id); 104 GetExtensionIdsForActionId(component_action_id);
111 DCHECK(!extension_ids.empty()); 105 DCHECK(!extension_ids.empty());
112 106
113 enabled_actions_.erase(component_action_id); 107 enabled_actions_.erase(component_action_id);
114 RemoveComponentActionPref(component_action_id); 108 RemoveComponentActionPref(component_action_id);
115 109
116 if (component_action_id ==
117 ComponentToolbarActionsFactory::kMediaRouterActionId) {
118 pref_service_->SetBoolean(prefs::kMediaRouterAlwaysShowActionIcon,
119 false);
120 }
121
122 if (FeatureSwitch::extension_action_redesign()->IsEnabled() && 110 if (FeatureSwitch::extension_action_redesign()->IsEnabled() &&
123 delegate_->HasComponentAction(component_action_id)) 111 delegate_->HasComponentAction(component_action_id))
124 delegate_->RemoveComponentAction(component_action_id); 112 delegate_->RemoveComponentAction(component_action_id);
125 } 113 }
126 114
127 void ComponentMigrationHelper::OnActionRemoved( 115 void ComponentMigrationHelper::OnActionRemoved(
128 const std::string& component_action_id) { 116 const std::string& component_action_id) {
129 // Record preference for the future. 117 // Record preference for the future.
130 SetComponentActionPref(component_action_id, false); 118 SetComponentActionPref(component_action_id, false);
131 119
132 // Remove the action. 120 // Remove the action.
133 if (delegate_->HasComponentAction(component_action_id)) 121 if (delegate_->HasComponentAction(component_action_id))
134 delegate_->RemoveComponentAction(component_action_id); 122 delegate_->RemoveComponentAction(component_action_id);
135 } 123 }
136 124
137 void ComponentMigrationHelper::OnExtensionReady( 125 void ComponentMigrationHelper::OnExtensionReady(
138 content::BrowserContext* browser_context, 126 content::BrowserContext* browser_context,
139 const Extension* extension) { 127 const Extension* extension) {
140 const ExtensionId& extension_id = extension->id(); 128 const ExtensionId& extension_id = extension->id();
141 const std::string& component_action_id = 129 const std::string& component_action_id =
142 GetActionIdForExtensionId(extension_id); 130 GetActionIdForExtensionId(extension_id);
143 if (component_action_id.empty()) 131 if (component_action_id.empty())
144 return; 132 return;
145 if (base::ContainsKey(enabled_actions_, component_action_id)) { 133 if (base::ContainsKey(enabled_actions_, component_action_id)) {
146 UnloadExtension(extension_id); 134 UnloadExtension(extension_id);
147 SetComponentActionPref(component_action_id, true); 135 SetComponentActionPref(component_action_id, true);
148 136
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 ==
152 ComponentToolbarActionsFactory::kMediaRouterActionId) {
153 pref_service_->SetBoolean(prefs::kMediaRouterAlwaysShowActionIcon,
154 true);
155 }
156
157 if (!delegate_->HasComponentAction(component_action_id)) 137 if (!delegate_->HasComponentAction(component_action_id))
158 delegate_->AddComponentAction(component_action_id); 138 delegate_->AddComponentAction(component_action_id);
159 } 139 }
160 } 140 }
161 141
162 void ComponentMigrationHelper::SetComponentActionPref( 142 void ComponentMigrationHelper::SetComponentActionPref(
163 const std::string& component_action_id, 143 const std::string& component_action_id,
164 bool enabled) { 144 bool enabled) {
165 DictionaryPrefUpdate update(pref_service_, 145 DictionaryPrefUpdate update(pref_service_,
166 ::prefs::kToolbarMigratedComponentActionStatus); 146 ::prefs::kToolbarMigratedComponentActionStatus);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 std::string ComponentMigrationHelper::GetActionIdForExtensionId( 179 std::string ComponentMigrationHelper::GetActionIdForExtensionId(
200 const ExtensionId& extension_id) const { 180 const ExtensionId& extension_id) const {
201 for (const auto& i : migrated_actions_) { 181 for (const auto& i : migrated_actions_) {
202 if (i.second == extension_id) 182 if (i.second == extension_id)
203 return i.first; 183 return i.first;
204 } 184 }
205 return ""; 185 return "";
206 } 186 }
207 187
208 } // namespace extensions 188 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/app/media_router_strings.grdp ('k') | chrome/browser/extensions/component_migration_helper_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698