| OLD | NEW |
| 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/api/system_indicator/system_indicator_manage
r_factory.h" | 7 #include "chrome/browser/extensions/api/system_indicator/system_indicator_manage
r_factory.h" |
| 8 #include "chrome/browser/extensions/extension_action.h" | 8 #include "chrome/browser/extensions/extension_action.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 10 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 const Extension* extension, | 78 const Extension* extension, |
| 79 UnloadedExtensionInfo::Reason reason) { | 79 UnloadedExtensionInfo::Reason reason) { |
| 80 page_actions_.erase(extension->id()); | 80 page_actions_.erase(extension->id()); |
| 81 browser_actions_.erase(extension->id()); | 81 browser_actions_.erase(extension->id()); |
| 82 system_indicators_.erase(extension->id()); | 82 system_indicators_.erase(extension->id()); |
| 83 } | 83 } |
| 84 | 84 |
| 85 namespace { | 85 namespace { |
| 86 | 86 |
| 87 // Returns map[extension_id] if that entry exists. Otherwise, if | 87 // Returns map[extension_id] if that entry exists. Otherwise, if |
| 88 // action_info!=NULL, creates an ExtensionAction from it, fills in the map, and | 88 // action_info!=nullptr, creates an ExtensionAction from it, fills in the map, |
| 89 // returns that. Otherwise (action_info==NULL), returns NULL. | 89 // and returns that. Otherwise (action_info==nullptr), returns nullptr. |
| 90 ExtensionAction* GetOrCreateOrNull( | 90 ExtensionAction* GetOrCreateOrNull( |
| 91 std::map<std::string, linked_ptr<ExtensionAction> >* map, | 91 std::map<std::string, std::unique_ptr<ExtensionAction>>* map, |
| 92 const Extension& extension, | 92 const Extension& extension, |
| 93 ActionInfo::Type action_type, | 93 ActionInfo::Type action_type, |
| 94 const ActionInfo* action_info, | 94 const ActionInfo* action_info, |
| 95 Profile* profile) { | 95 Profile* profile) { |
| 96 std::map<std::string, linked_ptr<ExtensionAction> >::const_iterator it = | 96 auto it = map->find(extension.id()); |
| 97 map->find(extension.id()); | |
| 98 if (it != map->end()) | 97 if (it != map->end()) |
| 99 return it->second.get(); | 98 return it->second.get(); |
| 100 if (!action_info) | 99 if (!action_info) |
| 101 return NULL; | 100 return nullptr; |
| 102 | 101 |
| 103 // Only create action info for enabled extensions. | 102 // Only create action info for enabled extensions. |
| 104 // This avoids bugs where actions are recreated just after being removed | 103 // This avoids bugs where actions are recreated just after being removed |
| 105 // in response to OnExtensionUnloaded(). | 104 // in response to OnExtensionUnloaded(). |
| 106 if (!ExtensionRegistry::Get(profile) | 105 if (!ExtensionRegistry::Get(profile) |
| 107 ->enabled_extensions().Contains(extension.id())) { | 106 ->enabled_extensions().Contains(extension.id())) { |
| 108 return NULL; | 107 return nullptr; |
| 109 } | 108 } |
| 110 | 109 |
| 111 linked_ptr<ExtensionAction> action(new ExtensionAction( | 110 std::unique_ptr<ExtensionAction> action( |
| 112 extension, action_type, *action_info)); | 111 new ExtensionAction(extension, action_type, *action_info)); |
| 113 (*map)[extension.id()] = action; | 112 ExtensionAction* raw_action = action.get(); |
| 114 return action.get(); | 113 (*map)[extension.id()] = std::move(action); |
| 114 return raw_action; |
| 115 } | 115 } |
| 116 | 116 |
| 117 } // namespace | 117 } // namespace |
| 118 | 118 |
| 119 ExtensionAction* ExtensionActionManager::GetPageAction( | 119 ExtensionAction* ExtensionActionManager::GetPageAction( |
| 120 const Extension& extension) const { | 120 const Extension& extension) const { |
| 121 return GetOrCreateOrNull(&page_actions_, extension, | 121 return GetOrCreateOrNull(&page_actions_, extension, |
| 122 ActionInfo::TYPE_PAGE, | 122 ActionInfo::TYPE_PAGE, |
| 123 ActionInfo::GetPageActionInfo(&extension), | 123 ActionInfo::GetPageActionInfo(&extension), |
| 124 profile_); | 124 profile_); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 136 const Extension& extension, | 136 const Extension& extension, |
| 137 ActionInfo::Type type) const { | 137 ActionInfo::Type type) const { |
| 138 const ActionInfo* info = ActionInfo::GetBrowserActionInfo(&extension); | 138 const ActionInfo* info = ActionInfo::GetBrowserActionInfo(&extension); |
| 139 if (!info) | 139 if (!info) |
| 140 info = ActionInfo::GetPageActionInfo(&extension); | 140 info = ActionInfo::GetPageActionInfo(&extension); |
| 141 | 141 |
| 142 // Create a new ExtensionAction of |type| with |extension|'s ActionInfo. | 142 // Create a new ExtensionAction of |type| with |extension|'s ActionInfo. |
| 143 // If no ActionInfo exists for |extension|, create and return a new action | 143 // If no ActionInfo exists for |extension|, create and return a new action |
| 144 // with a blank ActionInfo. | 144 // with a blank ActionInfo. |
| 145 // Populate any missing values from |extension|'s manifest. | 145 // Populate any missing values from |extension|'s manifest. |
| 146 std::unique_ptr<ExtensionAction> new_action( | 146 return base::MakeUnique<ExtensionAction>(extension, type, |
| 147 new ExtensionAction(extension, type, info ? *info : ActionInfo())); | 147 info ? *info : ActionInfo()); |
| 148 return new_action; | |
| 149 } | 148 } |
| 150 | 149 |
| 151 ExtensionAction* ExtensionActionManager::GetSystemIndicator( | 150 ExtensionAction* ExtensionActionManager::GetSystemIndicator( |
| 152 const Extension& extension) const { | 151 const Extension& extension) const { |
| 153 // If it does not already exist, create the SystemIndicatorManager for the | 152 // If it does not already exist, create the SystemIndicatorManager for the |
| 154 // given profile. This could return NULL if the system indicator area is | 153 // given profile. This could return NULL if the system indicator area is |
| 155 // unavailable on the current system. If so, return NULL to signal that | 154 // unavailable on the current system. If so, return NULL to signal that |
| 156 // the system indicator area is unusable. | 155 // the system indicator area is unusable. |
| 157 if (!SystemIndicatorManagerFactory::GetForProfile(profile_)) | 156 if (!SystemIndicatorManagerFactory::GetForProfile(profile_)) |
| 158 return NULL; | 157 return nullptr; |
| 159 | 158 |
| 160 return GetOrCreateOrNull(&system_indicators_, extension, | 159 return GetOrCreateOrNull(&system_indicators_, extension, |
| 161 ActionInfo::TYPE_SYSTEM_INDICATOR, | 160 ActionInfo::TYPE_SYSTEM_INDICATOR, |
| 162 ActionInfo::GetSystemIndicatorInfo(&extension), | 161 ActionInfo::GetSystemIndicatorInfo(&extension), |
| 163 profile_); | 162 profile_); |
| 164 } | 163 } |
| 165 | 164 |
| 166 ExtensionAction* ExtensionActionManager::GetExtensionAction( | 165 ExtensionAction* ExtensionActionManager::GetExtensionAction( |
| 167 const Extension& extension) const { | 166 const Extension& extension) const { |
| 168 ExtensionAction* action = GetBrowserAction(extension); | 167 ExtensionAction* action = GetBrowserAction(extension); |
| 169 return action ? action : GetPageAction(extension); | 168 return action ? action : GetPageAction(extension); |
| 170 } | 169 } |
| 171 | 170 |
| 172 } // namespace extensions | 171 } // namespace extensions |
| OLD | NEW |