Commit 30448a01 authored by Devlin Cronin's avatar Devlin Cronin Committed by Commit Bot

[Extensions Cleanup] Make ActionInfo::Set*() take unique_ptrs

Rather than having ActionInfo::Set*() methods take a raw pointer, which
was released by a unique_ptr, and then is wrapped in another unique_ptr,
just have the methods take a unique_ptr directly.

Bug: None
Change-Id: I1d126e59b39f38859e4d16c63cbef8e757042a1d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1562099
Commit-Queue: Devlin <rdevlin.cronin@chromium.org>
Reviewed-by: default avatarKaran Bhatia <karandeepb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#650567}
parent 628b3f4e
...@@ -27,15 +27,15 @@ constexpr char kDisabled[] = "disabled"; ...@@ -27,15 +27,15 @@ constexpr char kDisabled[] = "disabled";
// The manifest data container for the ActionInfos for BrowserActions, // The manifest data container for the ActionInfos for BrowserActions,
// PageActions and SystemIndicators. // PageActions and SystemIndicators.
struct ActionInfoData : public Extension::ManifestData { struct ActionInfoData : public Extension::ManifestData {
explicit ActionInfoData(ActionInfo* action_info); explicit ActionInfoData(std::unique_ptr<ActionInfo> action_info);
~ActionInfoData() override; ~ActionInfoData() override;
// The action associated with the BrowserAction. // The action associated with the BrowserAction.
std::unique_ptr<ActionInfo> action_info; std::unique_ptr<ActionInfo> action_info;
}; };
ActionInfoData::ActionInfoData(ActionInfo* info) : action_info(info) { ActionInfoData::ActionInfoData(std::unique_ptr<ActionInfo> info)
} : action_info(std::move(info)) {}
ActionInfoData::~ActionInfoData() { ActionInfoData::~ActionInfoData() {
} }
...@@ -157,28 +157,30 @@ const ActionInfo* ActionInfo::GetSystemIndicatorInfo( ...@@ -157,28 +157,30 @@ const ActionInfo* ActionInfo::GetSystemIndicatorInfo(
// static // static
void ActionInfo::SetExtensionActionInfo(Extension* extension, void ActionInfo::SetExtensionActionInfo(Extension* extension,
ActionInfo* info) { std::unique_ptr<ActionInfo> info) {
extension->SetManifestData(keys::kAction, extension->SetManifestData(keys::kAction,
std::make_unique<ActionInfoData>(info)); std::make_unique<ActionInfoData>(std::move(info)));
} }
// static // static
void ActionInfo::SetBrowserActionInfo(Extension* extension, ActionInfo* info) { void ActionInfo::SetBrowserActionInfo(Extension* extension,
std::unique_ptr<ActionInfo> info) {
extension->SetManifestData(keys::kBrowserAction, extension->SetManifestData(keys::kBrowserAction,
std::make_unique<ActionInfoData>(info)); std::make_unique<ActionInfoData>(std::move(info)));
} }
// static // static
void ActionInfo::SetPageActionInfo(Extension* extension, ActionInfo* info) { void ActionInfo::SetPageActionInfo(Extension* extension,
std::unique_ptr<ActionInfo> info) {
extension->SetManifestData(keys::kPageAction, extension->SetManifestData(keys::kPageAction,
std::make_unique<ActionInfoData>(info)); std::make_unique<ActionInfoData>(std::move(info)));
} }
// static // static
void ActionInfo::SetSystemIndicatorInfo(Extension* extension, void ActionInfo::SetSystemIndicatorInfo(Extension* extension,
ActionInfo* info) { std::unique_ptr<ActionInfo> info) {
extension->SetManifestData(keys::kSystemIndicator, extension->SetManifestData(keys::kSystemIndicator,
std::make_unique<ActionInfoData>(info)); std::make_unique<ActionInfoData>(std::move(info)));
} }
// static // static
......
...@@ -55,18 +55,21 @@ struct ActionInfo { ...@@ -55,18 +55,21 @@ struct ActionInfo {
// Returns the extension's system indicator, if any. // Returns the extension's system indicator, if any.
static const ActionInfo* GetSystemIndicatorInfo(const Extension* extension); static const ActionInfo* GetSystemIndicatorInfo(const Extension* extension);
// Sets the extension's action. |extension| takes ownership of |info|. // Sets the extension's action.
static void SetExtensionActionInfo(Extension* extension, ActionInfo* info); static void SetExtensionActionInfo(Extension* extension,
std::unique_ptr<ActionInfo> info);
// Sets the extension's browser action. |extension| takes ownership of |info|. // Sets the extension's browser action.
static void SetBrowserActionInfo(Extension* extension, ActionInfo* info); static void SetBrowserActionInfo(Extension* extension,
std::unique_ptr<ActionInfo> info);
// Sets the extension's page action. |extension| takes ownership of |info|. // Sets the extension's page action.
static void SetPageActionInfo(Extension* extension, ActionInfo* info); static void SetPageActionInfo(Extension* extension,
std::unique_ptr<ActionInfo> info);
// Sets the extension's system indicator. |extension| takes ownership of // Sets the extension's system indicator.
// |info|. static void SetSystemIndicatorInfo(Extension* extension,
static void SetSystemIndicatorInfo(Extension* extension, ActionInfo* info); std::unique_ptr<ActionInfo> info);
// Returns true if the extension needs a verbose install message because // Returns true if the extension needs a verbose install message because
// of its page action. // of its page action.
......
...@@ -35,7 +35,7 @@ bool SystemIndicatorHandler::Parse(Extension* extension, ...@@ -35,7 +35,7 @@ bool SystemIndicatorHandler::Parse(Extension* extension,
if (!action_info.get()) if (!action_info.get())
return false; return false;
ActionInfo::SetSystemIndicatorInfo(extension, action_info.release()); ActionInfo::SetSystemIndicatorInfo(extension, std::move(action_info));
return true; return true;
} }
......
...@@ -67,7 +67,7 @@ bool ExtensionActionHandler::Parse(Extension* extension, ...@@ -67,7 +67,7 @@ bool ExtensionActionHandler::Parse(Extension* extension,
return false; // Failed to parse extension action definition. return false; // Failed to parse extension action definition.
if (key == manifest_keys::kAction) { if (key == manifest_keys::kAction) {
ActionInfo::SetExtensionActionInfo(extension, action_info.release()); ActionInfo::SetExtensionActionInfo(extension, std::move(action_info));
} else { } else {
if (dict->HasKey(manifest_keys::kActionDefaultState)) { if (dict->HasKey(manifest_keys::kActionDefaultState)) {
*error = *error =
...@@ -76,9 +76,9 @@ bool ExtensionActionHandler::Parse(Extension* extension, ...@@ -76,9 +76,9 @@ bool ExtensionActionHandler::Parse(Extension* extension,
} }
if (key == manifest_keys::kPageAction) if (key == manifest_keys::kPageAction)
ActionInfo::SetPageActionInfo(extension, action_info.release()); ActionInfo::SetPageActionInfo(extension, std::move(action_info));
else else
ActionInfo::SetBrowserActionInfo(extension, action_info.release()); ActionInfo::SetBrowserActionInfo(extension, std::move(action_info));
} }
} else { // No key, used for synthesizing an action for extensions with none. } else { // No key, used for synthesizing an action for extensions with none.
if (Manifest::IsComponentLocation(extension->location())) if (Manifest::IsComponentLocation(extension->location()))
...@@ -96,7 +96,7 @@ bool ExtensionActionHandler::Parse(Extension* extension, ...@@ -96,7 +96,7 @@ bool ExtensionActionHandler::Parse(Extension* extension,
// action) because the action should not be seen as enabled on every page. // action) because the action should not be seen as enabled on every page.
std::unique_ptr<ActionInfo> action_info(new ActionInfo()); std::unique_ptr<ActionInfo> action_info(new ActionInfo());
action_info->synthesized = true; action_info->synthesized = true;
ActionInfo::SetPageActionInfo(extension, action_info.release()); ActionInfo::SetPageActionInfo(extension, std::move(action_info));
} }
return true; return true;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment