Index: printing/print_settings_conversion.cc |
diff --git a/printing/print_settings_conversion.cc b/printing/print_settings_conversion.cc |
index 7e8840cdb948ea5c1aa18a0d555fe890abb8d9c4..8f9bd3f5e236a394d47b33a220754e155f6413ec 100644 |
--- a/printing/print_settings_conversion.cc |
+++ b/printing/print_settings_conversion.cc |
@@ -12,6 +12,7 @@ |
#include <string> |
#include <utility> |
+#include "base/memory/ptr_util.h" |
#include "base/strings/string_number_conversions.h" |
#include "base/strings/utf_string_conversions.h" |
#include "base/time/time.h" |
@@ -44,32 +45,32 @@ void GetCustomMarginsFromJobSettings(const base::DictionaryValue& settings, |
void SetMarginsToJobSettings(const std::string& json_path, |
const PageMargins& margins, |
base::DictionaryValue* job_settings) { |
- base::DictionaryValue* dict = new base::DictionaryValue; |
- job_settings->Set(json_path, dict); |
+ auto dict = base::MakeUnique<base::DictionaryValue>(); |
dict->SetInteger(kSettingMarginTop, margins.top); |
dict->SetInteger(kSettingMarginBottom, margins.bottom); |
dict->SetInteger(kSettingMarginLeft, margins.left); |
dict->SetInteger(kSettingMarginRight, margins.right); |
+ job_settings->Set(json_path, std::move(dict)); |
} |
void SetSizeToJobSettings(const std::string& json_path, |
const gfx::Size& size, |
base::DictionaryValue* job_settings) { |
- base::DictionaryValue* dict = new base::DictionaryValue; |
- job_settings->Set(json_path, dict); |
+ auto dict = base::MakeUnique<base::DictionaryValue>(); |
dict->SetInteger("width", size.width()); |
dict->SetInteger("height", size.height()); |
+ job_settings->Set(json_path, std::move(dict)); |
} |
void SetRectToJobSettings(const std::string& json_path, |
const gfx::Rect& rect, |
base::DictionaryValue* job_settings) { |
- base::DictionaryValue* dict = new base::DictionaryValue; |
- job_settings->Set(json_path, dict); |
+ auto dict = base::MakeUnique<base::DictionaryValue>(); |
dict->SetInteger("x", rect.x()); |
dict->SetInteger("y", rect.y()); |
dict->SetInteger("width", rect.width()); |
dict->SetInteger("height", rect.height()); |
+ job_settings->Set(json_path, std::move(dict)); |
} |
} // namespace |
@@ -229,14 +230,14 @@ void PrintSettingsToJobSettingsDebug(const PrintSettings& settings, |
settings.selection_only()); |
job_settings->SetInteger(kSettingMarginsType, settings.margin_type()); |
if (!settings.ranges().empty()) { |
- base::ListValue* page_range_array = new base::ListValue; |
- job_settings->Set(kSettingPageRange, page_range_array); |
+ auto page_range_array = base::MakeUnique<base::ListValue>(); |
for (size_t i = 0; i < settings.ranges().size(); ++i) { |
- std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue); |
+ auto dict = base::MakeUnique<base::DictionaryValue>(); |
dict->SetInteger(kSettingPageRangeFrom, settings.ranges()[i].from + 1); |
dict->SetInteger(kSettingPageRangeTo, settings.ranges()[i].to + 1); |
page_range_array->Append(std::move(dict)); |
} |
+ job_settings->Set(kSettingPageRange, std::move(page_range_array)); |
} |
job_settings->SetBoolean(kSettingCollate, settings.collate()); |
@@ -248,24 +249,26 @@ void PrintSettingsToJobSettingsDebug(const PrintSettings& settings, |
// Following values are not read form JSON by InitSettings, so do not have |
// common public constants. So just serialize in "debug" section. |
- base::DictionaryValue* debug = new base::DictionaryValue; |
- job_settings->Set("debug", debug); |
+ auto debug = base::MakeUnique<base::DictionaryValue>(); |
debug->SetInteger("dpi", settings.dpi()); |
debug->SetInteger("deviceUnitsPerInch", settings.device_units_per_inch()); |
debug->SetBoolean("support_alpha_blend", settings.should_print_backgrounds()); |
debug->SetString("media_vendor_id", settings.requested_media().vendor_id); |
- SetSizeToJobSettings( |
- "media_size", settings.requested_media().size_microns, debug); |
+ SetSizeToJobSettings("media_size", settings.requested_media().size_microns, |
+ debug.get()); |
SetMarginsToJobSettings("requested_custom_margins_in_points", |
settings.requested_custom_margins_in_points(), |
- debug); |
+ debug.get()); |
const PageSetup& page_setup = settings.page_setup_device_units(); |
- SetMarginsToJobSettings( |
- "effective_margins", page_setup.effective_margins(), debug); |
- SetSizeToJobSettings("physical_size", page_setup.physical_size(), debug); |
- SetRectToJobSettings("overlay_area", page_setup.overlay_area(), debug); |
- SetRectToJobSettings("content_area", page_setup.content_area(), debug); |
- SetRectToJobSettings("printable_area", page_setup.printable_area(), debug); |
+ SetMarginsToJobSettings("effective_margins", page_setup.effective_margins(), |
+ debug.get()); |
+ SetSizeToJobSettings("physical_size", page_setup.physical_size(), |
+ debug.get()); |
+ SetRectToJobSettings("overlay_area", page_setup.overlay_area(), debug.get()); |
+ SetRectToJobSettings("content_area", page_setup.content_area(), debug.get()); |
+ SetRectToJobSettings("printable_area", page_setup.printable_area(), |
+ debug.get()); |
+ job_settings->Set("debug", std::move(debug)); |
} |
} // namespace printing |