Chromium Code Reviews| Index: chrome/browser/extensions/api/developer_private/extension_info_generator.cc |
| diff --git a/chrome/browser/extensions/api/developer_private/extension_info_generator.cc b/chrome/browser/extensions/api/developer_private/extension_info_generator.cc |
| index 858e9b8eee5e76a1fc4656053a217b3eefb5b56a..718634672c54ea2cd17f503d0f4046ae93a3b04f 100644 |
| --- a/chrome/browser/extensions/api/developer_private/extension_info_generator.cc |
| +++ b/chrome/browser/extensions/api/developer_private/extension_info_generator.cc |
| @@ -7,6 +7,7 @@ |
| #include <utility> |
| #include "base/base64.h" |
| +#include "base/callback_helpers.h" |
| #include "base/location.h" |
| #include "base/single_thread_task_runner.h" |
| #include "base/strings/utf_string_conversions.h" |
| @@ -103,13 +104,12 @@ void PopulateErrorBase(const ExtensionError& error, ErrorType* out) { |
| // Given a ManifestError object, converts it into its developer_private |
| // counterpart. |
| -linked_ptr<developer::ManifestError> ConstructManifestError( |
| - const ManifestError& error) { |
| - linked_ptr<developer::ManifestError> result(new developer::ManifestError()); |
| - PopulateErrorBase(error, result.get()); |
| - result->manifest_key = base::UTF16ToUTF8(error.manifest_key()); |
| +developer::ManifestError ConstructManifestError(const ManifestError& error) { |
| + developer::ManifestError result; |
| + PopulateErrorBase(error, &result); |
| + result.manifest_key = base::UTF16ToUTF8(error.manifest_key()); |
| if (!error.manifest_specific().empty()) { |
| - result->manifest_specific.reset( |
| + result.manifest_specific.reset( |
| new std::string(base::UTF16ToUTF8(error.manifest_specific()))); |
| } |
| return result; |
| @@ -117,40 +117,39 @@ linked_ptr<developer::ManifestError> ConstructManifestError( |
| // Given a RuntimeError object, converts it into its developer_private |
| // counterpart. |
| -linked_ptr<developer::RuntimeError> ConstructRuntimeError( |
| - const RuntimeError& error) { |
| - linked_ptr<developer::RuntimeError> result(new developer::RuntimeError()); |
| - PopulateErrorBase(error, result.get()); |
| +developer::RuntimeError ConstructRuntimeError(const RuntimeError& error) { |
| + developer::RuntimeError result; |
| + PopulateErrorBase(error, &result); |
| switch (error.level()) { |
| case logging::LOG_VERBOSE: |
| case logging::LOG_INFO: |
| - result->severity = developer::ERROR_LEVEL_LOG; |
| + result.severity = developer::ERROR_LEVEL_LOG; |
| break; |
| case logging::LOG_WARNING: |
| - result->severity = developer::ERROR_LEVEL_WARN; |
| + result.severity = developer::ERROR_LEVEL_WARN; |
| break; |
| case logging::LOG_FATAL: |
| case logging::LOG_ERROR: |
| - result->severity = developer::ERROR_LEVEL_ERROR; |
| + result.severity = developer::ERROR_LEVEL_ERROR; |
| break; |
| default: |
| NOTREACHED(); |
| } |
| - result->occurrences = error.occurrences(); |
| + result.occurrences = error.occurrences(); |
| // NOTE(devlin): This is called "render_view_id" in the api for legacy |
| // reasons, but it's not a high priority to change. |
| - result->render_view_id = error.render_frame_id(); |
| - result->render_process_id = error.render_process_id(); |
| - result->can_inspect = |
| + result.render_view_id = error.render_frame_id(); |
| + result.render_process_id = error.render_process_id(); |
| + result.can_inspect = |
| content::RenderFrameHost::FromID(error.render_process_id(), |
| error.render_frame_id()) != nullptr; |
| for (const StackFrame& f : error.stack_trace()) { |
| - linked_ptr<developer::StackFrame> frame(new developer::StackFrame()); |
| - frame->line_number = f.line_number; |
| - frame->column_number = f.column_number; |
| - frame->url = base::UTF16ToUTF8(f.source); |
| - frame->function_name = base::UTF16ToUTF8(f.function); |
| - result->stack_trace.push_back(frame); |
| + developer::StackFrame frame; |
| + frame.line_number = f.line_number; |
| + frame.column_number = f.column_number; |
| + frame.url = base::UTF16ToUTF8(f.source); |
| + frame.function_name = base::UTF16ToUTF8(f.function); |
| + result.stack_trace.push_back(std::move(frame)); |
| } |
| return result; |
| } |
| @@ -159,21 +158,21 @@ linked_ptr<developer::RuntimeError> ConstructRuntimeError( |
| // to the list of |commands|. |
| void ConstructCommands(CommandService* command_service, |
| const std::string& extension_id, |
| - std::vector<linked_ptr<developer::Command>>* commands) { |
| - auto construct_command = [](const Command& command, |
| - bool active, |
| + std::vector<developer::Command>* commands) { |
| + auto construct_command = [](const Command& command, bool active, |
| bool is_extension_action) { |
| - developer::Command* command_value = new developer::Command(); |
| - command_value->description = is_extension_action ? |
| - l10n_util::GetStringUTF8(IDS_EXTENSION_COMMANDS_GENERIC_ACTIVATE) : |
| - base::UTF16ToUTF8(command.description()); |
| - command_value->keybinding = |
| + developer::Command command_value; |
| + command_value.description = |
| + is_extension_action |
| + ? l10n_util::GetStringUTF8(IDS_EXTENSION_COMMANDS_GENERIC_ACTIVATE) |
| + : base::UTF16ToUTF8(command.description()); |
| + command_value.keybinding = |
| base::UTF16ToUTF8(command.accelerator().GetShortcutText()); |
| - command_value->name = command.command_name(); |
| - command_value->is_active = active; |
| - command_value->scope = command.global() ? developer::COMMAND_SCOPE_GLOBAL : |
| - developer::COMMAND_SCOPE_CHROME; |
| - command_value->is_extension_action = is_extension_action; |
| + command_value.name = command.command_name(); |
| + command_value.is_active = active; |
| + command_value.scope = command.global() ? developer::COMMAND_SCOPE_GLOBAL |
| + : developer::COMMAND_SCOPE_CHROME; |
| + command_value.is_extension_action = is_extension_action; |
| return command_value; |
| }; |
| bool active = false; |
| @@ -182,8 +181,7 @@ void ConstructCommands(CommandService* command_service, |
| CommandService::ALL, |
| &browser_action, |
| &active)) { |
| - commands->push_back( |
| - make_linked_ptr(construct_command(browser_action, active, true))); |
| + commands->push_back(construct_command(browser_action, active, true)); |
| } |
| Command page_action; |
| @@ -191,8 +189,7 @@ void ConstructCommands(CommandService* command_service, |
| CommandService::ALL, |
| &page_action, |
| &active)) { |
| - commands->push_back( |
| - make_linked_ptr(construct_command(page_action, active, true))); |
| + commands->push_back(construct_command(page_action, active, true)); |
| } |
| CommandMap named_commands; |
| @@ -214,8 +211,7 @@ void ConstructCommands(CommandService* command_service, |
| command_to_use.set_accelerator(active_command.accelerator()); |
| command_to_use.set_global(active_command.global()); |
| bool active = command_to_use.accelerator().key_code() != ui::VKEY_UNKNOWN; |
| - commands->push_back( |
| - make_linked_ptr(construct_command(command_to_use, active, false))); |
| + commands->push_back(construct_command(command_to_use, active, false)); |
| } |
| } |
| } |
| @@ -260,9 +256,9 @@ void ExtensionInfoGenerator::CreateExtensionInfo( |
| if (pending_image_loads_ == 0) { |
| // Don't call the callback re-entrantly. |
| - base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| - base::Bind(callback, list_)); |
| - list_.clear(); |
| + base::ThreadTaskRunnerHandle::Get()->PostTask( |
| + FROM_HERE, base::Bind(callback, base::Passed(std::move(list_)))); |
|
dcheng
2016/03/22 17:42:34
You shouldn't need std::move() with base::Passed()
Devlin
2016/03/22 17:58:40
Done.
|
| + list_ = ExtensionInfoList(); |
|
dcheng
2016/03/22 17:42:34
Just call clear(): it has no preconditions, and |l
Devlin
2016/03/22 17:58:40
Done.
|
| } else { |
| callback_ = callback; |
| } |
| @@ -296,9 +292,11 @@ void ExtensionInfoGenerator::CreateExtensionsInfo( |
| if (pending_image_loads_ == 0) { |
| // Don't call the callback re-entrantly. |
| - base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| - base::Bind(callback, list_)); |
| - list_.clear(); |
| + base::ThreadTaskRunnerHandle::Get()->PostTask( |
| + FROM_HERE, base::Bind(callback, base::Passed(std::move(list_)))); |
| + // std::move() leaves |list_| "in a valid but unspecified state afterwards." |
| + // What should we do here? |
|
dcheng
2016/03/22 17:42:34
See above.
Devlin
2016/03/22 17:58:40
Done.
|
| + list_ = ExtensionInfoList(); |
| } else { |
| callback_ = callback; |
| } |
| @@ -540,7 +538,7 @@ void ExtensionInfoGenerator::CreateExtensionInfoHelper( |
| ExtensionIconSet::MATCH_BIGGER); |
| if (icon.empty()) { |
| info->icon_url = GetDefaultIconUrl(extension.is_app(), !is_enabled); |
| - list_.push_back(make_linked_ptr(info.release())); |
| + list_.push_back(std::move(*info)); |
| } else { |
| ++pending_image_loads_; |
| // Max size of 128x128 is a random guess at a nice balance between being |
| @@ -615,18 +613,13 @@ void ExtensionInfoGenerator::OnImageLoaded( |
| is_app, info->state != developer::EXTENSION_STATE_ENABLED); |
| } |
| - list_.push_back(make_linked_ptr(info.release())); |
| + list_.push_back(std::move(*info)); |
| --pending_image_loads_; |
| if (pending_image_loads_ == 0) { // All done! |
| - // We assign to a temporary callback and list and reset the stored values so |
| - // that at the end of the method, any stored refs are destroyed. |
| - ExtensionInfoList list; |
| - list.swap(list_); |
| - ExtensionInfosCallback callback = callback_; |
| - callback_.Reset(); |
| - callback.Run(list); // WARNING: |this| is possibly deleted after this line! |
| + base::ResetAndReturn(&callback_).Run(std::move(list_)); |
| + // WARNING: |this| is possibly deleted after this line! |
| } |
| } |