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

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

Issue 11588004: Move ScriptBadge, ActionInfo out of Extension; preparation for BrowserAction (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years 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 (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/extensions/extension_action_manager.h" 5 #include "chrome/browser/extensions/extension_action_manager.h"
6 6
7 #include "chrome/browser/extensions/extension_action.h" 7 #include "chrome/browser/extensions/extension_action.h"
8 #include "chrome/browser/extensions/extension_system.h" 8 #include "chrome/browser/extensions/extension_system.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/profiles/profile_dependency_manager.h" 10 #include "chrome/browser/profiles/profile_dependency_manager.h"
11 #include "chrome/browser/profiles/profile_keyed_service_factory.h" 11 #include "chrome/browser/profiles/profile_keyed_service_factory.h"
12 #include "chrome/common/chrome_notification_types.h" 12 #include "chrome/common/chrome_notification_types.h"
13 #include "chrome/common/extensions/api/extension_action/action_info.h"
14 #include "chrome/common/extensions/api/extension_action/script_badge_handler.h"
13 #include "chrome/common/extensions/extension.h" 15 #include "chrome/common/extensions/extension.h"
14 #include "chrome/common/extensions/feature_switch.h" 16 #include "chrome/common/extensions/feature_switch.h"
15 #include "content/public/browser/notification_service.h" 17 #include "content/public/browser/notification_service.h"
16 #include "content/public/browser/notification_source.h" 18 #include "content/public/browser/notification_source.h"
17 19
18 namespace extensions { 20 namespace extensions {
19 21
20 namespace { 22 namespace {
21 23
22 // ProfileKeyedServiceFactory for ExtensionActionManager. 24 // ProfileKeyedServiceFactory for ExtensionActionManager.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 } 90 }
89 91
90 namespace { 92 namespace {
91 93
92 // Returns map[extension_id] if that entry exists. Otherwise, if 94 // Returns map[extension_id] if that entry exists. Otherwise, if
93 // action_info!=NULL, creates an ExtensionAction from it, fills in the map, and 95 // action_info!=NULL, creates an ExtensionAction from it, fills in the map, and
94 // returns that. Otherwise (action_info==NULL), returns NULL. 96 // returns that. Otherwise (action_info==NULL), returns NULL.
95 ExtensionAction* GetOrCreateOrNull( 97 ExtensionAction* GetOrCreateOrNull(
96 std::map<std::string, linked_ptr<ExtensionAction> >* map, 98 std::map<std::string, linked_ptr<ExtensionAction> >* map,
97 const std::string& extension_id, 99 const std::string& extension_id,
98 Extension::ActionInfo::Type action_type, 100 ActionInfo::Type action_type,
99 const Extension::ActionInfo* action_info) { 101 const ActionInfo* action_info) {
100 std::map<std::string, linked_ptr<ExtensionAction> >::const_iterator it = 102 std::map<std::string, linked_ptr<ExtensionAction> >::const_iterator it =
101 map->find(extension_id); 103 map->find(extension_id);
102 if (it != map->end()) 104 if (it != map->end())
103 return it->second.get(); 105 return it->second.get();
104 if (!action_info) 106 if (!action_info)
105 return NULL; 107 return NULL;
106 linked_ptr<ExtensionAction> action(new ExtensionAction( 108 linked_ptr<ExtensionAction> action(new ExtensionAction(
107 extension_id, action_type, *action_info)); 109 extension_id, action_type, *action_info));
108 (*map)[extension_id] = action; 110 (*map)[extension_id] = action;
109 return action.get(); 111 return action.get();
110 } 112 }
111 113
112 } // namespace 114 } // namespace
113 115
114 ExtensionAction* ExtensionActionManager::GetPageAction( 116 ExtensionAction* ExtensionActionManager::GetPageAction(
115 const extensions::Extension& extension) const { 117 const extensions::Extension& extension) const {
116 // The action box changes the meaning of the page action area, so we 118 // The action box changes the meaning of the page action area, so we
117 // need to convert page actions into browser actions. 119 // need to convert page actions into browser actions.
118 if (FeatureSwitch::script_badges()->IsEnabled()) 120 if (FeatureSwitch::script_badges()->IsEnabled())
119 return NULL; 121 return NULL;
120 return GetOrCreateOrNull(&page_actions_, extension.id(), 122 return GetOrCreateOrNull(&page_actions_, extension.id(),
121 Extension::ActionInfo::TYPE_PAGE, 123 ActionInfo::TYPE_PAGE,
122 extension.page_action_info()); 124 extension.page_action_info());
123 } 125 }
124 126
125 ExtensionAction* ExtensionActionManager::GetBrowserAction( 127 ExtensionAction* ExtensionActionManager::GetBrowserAction(
126 const extensions::Extension& extension) const { 128 const extensions::Extension& extension) const {
127 const Extension::ActionInfo* action_info = extension.browser_action_info(); 129 const ActionInfo* action_info = extension.browser_action_info();
128 Extension::ActionInfo::Type action_type = Extension::ActionInfo::TYPE_BROWSER; 130 ActionInfo::Type action_type = ActionInfo::TYPE_BROWSER;
129 if (FeatureSwitch::script_badges()->IsEnabled() && 131 if (FeatureSwitch::script_badges()->IsEnabled() &&
130 extension.page_action_info()) { 132 extension.page_action_info()) {
131 // The action box changes the meaning of the page action area, so we 133 // The action box changes the meaning of the page action area, so we
132 // need to convert page actions into browser actions. 134 // need to convert page actions into browser actions.
133 action_info = extension.page_action_info(); 135 action_info = extension.page_action_info();
134 action_type = Extension::ActionInfo::TYPE_PAGE; 136 action_type = ActionInfo::TYPE_PAGE;
135 } 137 }
136 return GetOrCreateOrNull(&browser_actions_, extension.id(), 138 return GetOrCreateOrNull(&browser_actions_, extension.id(),
137 action_type, action_info); 139 action_type, action_info);
138 } 140 }
139 141
140 ExtensionAction* ExtensionActionManager::GetSystemIndicator( 142 ExtensionAction* ExtensionActionManager::GetSystemIndicator(
141 const extensions::Extension& extension) const { 143 const extensions::Extension& extension) const {
142 return GetOrCreateOrNull(&system_indicators_, extension.id(), 144 return GetOrCreateOrNull(&system_indicators_, extension.id(),
143 Extension::ActionInfo::TYPE_SYSTEM_INDICATOR, 145 ActionInfo::TYPE_SYSTEM_INDICATOR,
144 extension.system_indicator_info()); 146 extension.system_indicator_info());
145 } 147 }
146 148
147 ExtensionAction* ExtensionActionManager::GetScriptBadge( 149 ExtensionAction* ExtensionActionManager::GetScriptBadge(
148 const extensions::Extension& extension) const { 150 const extensions::Extension& extension) const {
149 return GetOrCreateOrNull(&script_badges_, extension.id(), 151 return GetOrCreateOrNull(&script_badges_, extension.id(),
150 Extension::ActionInfo::TYPE_SCRIPT_BADGE, 152 ActionInfo::TYPE_SCRIPT_BADGE,
151 extension.script_badge_info()); 153 ScriptBadgeInfo::GetScriptBadge(&extension));
152 } 154 }
153 155
154 } // namespace extensions 156 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698