Chromium Code Reviews| 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 (*map)[extension.id()] = std::move(action); |
| 114 return action.get(); | 113 return ((*map)[extension.id()]).get(); |
|
Devlin
2016/11/02 22:25:33
ditto
limasdf
2016/11/03 15:29:23
Done.
| |
| 115 } | 114 } |
| 116 | 115 |
| 117 } // namespace | 116 } // namespace |
| 118 | 117 |
| 119 ExtensionAction* ExtensionActionManager::GetPageAction( | 118 ExtensionAction* ExtensionActionManager::GetPageAction( |
| 120 const Extension& extension) const { | 119 const Extension& extension) const { |
| 121 return GetOrCreateOrNull(&page_actions_, extension, | 120 return GetOrCreateOrNull(&page_actions_, extension, |
| 122 ActionInfo::TYPE_PAGE, | 121 ActionInfo::TYPE_PAGE, |
| 123 ActionInfo::GetPageActionInfo(&extension), | 122 ActionInfo::GetPageActionInfo(&extension), |
| 124 profile_); | 123 profile_); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 136 const Extension& extension, | 135 const Extension& extension, |
| 137 ActionInfo::Type type) const { | 136 ActionInfo::Type type) const { |
| 138 const ActionInfo* info = ActionInfo::GetBrowserActionInfo(&extension); | 137 const ActionInfo* info = ActionInfo::GetBrowserActionInfo(&extension); |
| 139 if (!info) | 138 if (!info) |
| 140 info = ActionInfo::GetPageActionInfo(&extension); | 139 info = ActionInfo::GetPageActionInfo(&extension); |
| 141 | 140 |
| 142 // Create a new ExtensionAction of |type| with |extension|'s ActionInfo. | 141 // Create a new ExtensionAction of |type| with |extension|'s ActionInfo. |
| 143 // If no ActionInfo exists for |extension|, create and return a new action | 142 // If no ActionInfo exists for |extension|, create and return a new action |
| 144 // with a blank ActionInfo. | 143 // with a blank ActionInfo. |
| 145 // Populate any missing values from |extension|'s manifest. | 144 // Populate any missing values from |extension|'s manifest. |
| 146 std::unique_ptr<ExtensionAction> new_action( | 145 return base::MakeUnique<ExtensionAction>(extension, type, |
| 147 new ExtensionAction(extension, type, info ? *info : ActionInfo())); | 146 info ? *info : ActionInfo()); |
| 148 return new_action; | |
| 149 } | 147 } |
| 150 | 148 |
| 151 ExtensionAction* ExtensionActionManager::GetSystemIndicator( | 149 ExtensionAction* ExtensionActionManager::GetSystemIndicator( |
| 152 const Extension& extension) const { | 150 const Extension& extension) const { |
| 153 // If it does not already exist, create the SystemIndicatorManager for the | 151 // If it does not already exist, create the SystemIndicatorManager for the |
| 154 // given profile. This could return NULL if the system indicator area is | 152 // 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 | 153 // unavailable on the current system. If so, return NULL to signal that |
| 156 // the system indicator area is unusable. | 154 // the system indicator area is unusable. |
| 157 if (!SystemIndicatorManagerFactory::GetForProfile(profile_)) | 155 if (!SystemIndicatorManagerFactory::GetForProfile(profile_)) |
| 158 return NULL; | 156 return nullptr; |
| 159 | 157 |
| 160 return GetOrCreateOrNull(&system_indicators_, extension, | 158 return GetOrCreateOrNull(&system_indicators_, extension, |
| 161 ActionInfo::TYPE_SYSTEM_INDICATOR, | 159 ActionInfo::TYPE_SYSTEM_INDICATOR, |
| 162 ActionInfo::GetSystemIndicatorInfo(&extension), | 160 ActionInfo::GetSystemIndicatorInfo(&extension), |
| 163 profile_); | 161 profile_); |
| 164 } | 162 } |
| 165 | 163 |
| 166 ExtensionAction* ExtensionActionManager::GetExtensionAction( | 164 ExtensionAction* ExtensionActionManager::GetExtensionAction( |
| 167 const Extension& extension) const { | 165 const Extension& extension) const { |
| 168 ExtensionAction* action = GetBrowserAction(extension); | 166 ExtensionAction* action = GetBrowserAction(extension); |
| 169 return action ? action : GetPageAction(extension); | 167 return action ? action : GetPageAction(extension); |
| 170 } | 168 } |
| 171 | 169 |
| 172 } // namespace extensions | 170 } // namespace extensions |
| OLD | NEW |