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

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

Issue 2294973002: Create MediaRouterActionController and MediaRouterUIService (Closed)
Patch Set: Address Derek and Mark's comments Created 4 years, 3 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"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
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) {
Devlin 2016/09/15 21:08:41 Note: this is a behavior change, where previously
takumif 2016/09/16 21:04:05 I believe there's no behavior change. If the pref
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
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 bool success =
143 migration_pref->GetBoolean(component_action_id, &component_action_pref);
144
145 DCHECK(success);
146 return component_action_pref;
147 }
148
142 void ComponentMigrationHelper::SetComponentActionPref( 149 void ComponentMigrationHelper::SetComponentActionPref(
143 const std::string& component_action_id, 150 const std::string& component_action_id,
144 bool enabled) { 151 bool enabled) {
145 DictionaryPrefUpdate update(pref_service_, 152 DictionaryPrefUpdate update(pref_service_,
146 ::prefs::kToolbarMigratedComponentActionStatus); 153 ::prefs::kToolbarMigratedComponentActionStatus);
147 update->SetBoolean(component_action_id, enabled); 154 update->SetBoolean(component_action_id, enabled);
148 } 155 }
149 156
150 bool ComponentMigrationHelper::IsExtensionInstalledAndEnabled( 157 bool ComponentMigrationHelper::IsExtensionInstalledAndEnabled(
151 const ExtensionId& extension_id) const { 158 const ExtensionId& extension_id) const {
(...skipping 27 matching lines...) Expand all
179 std::string ComponentMigrationHelper::GetActionIdForExtensionId( 186 std::string ComponentMigrationHelper::GetActionIdForExtensionId(
180 const ExtensionId& extension_id) const { 187 const ExtensionId& extension_id) const {
181 for (const auto& i : migrated_actions_) { 188 for (const auto& i : migrated_actions_) {
182 if (i.second == extension_id) 189 if (i.second == extension_id)
183 return i.first; 190 return i.first;
184 } 191 }
185 return ""; 192 return "";
186 } 193 }
187 194
188 } // namespace extensions 195 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698