Enable the following tests back under ThreadSanitizer v2:
[chromium-blink-merge.git] / printing / printing_context.cc
blob98ea11cba795b08231ed69111db57f640777de3b
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "printing/printing_context.h"
7 #include "base/logging.h"
8 #include "base/values.h"
9 #include "printing/page_setup.h"
10 #include "printing/page_size_margins.h"
11 #include "printing/print_settings_initializer.h"
13 namespace printing {
15 PrintingContext::PrintingContext(const std::string& app_locale)
16 : dialog_box_dismissed_(false),
17 in_print_job_(false),
18 abort_printing_(false),
19 app_locale_(app_locale) {
22 PrintingContext::~PrintingContext() {
25 void PrintingContext::set_margin_type(MarginType type) {
26 DCHECK(type != CUSTOM_MARGINS);
27 settings_.margin_type = type;
30 void PrintingContext::ResetSettings() {
31 ReleaseContext();
33 settings_.Clear();
35 in_print_job_ = false;
36 dialog_box_dismissed_ = false;
37 abort_printing_ = false;
40 PrintingContext::Result PrintingContext::OnError() {
41 ResetSettings();
42 return abort_printing_ ? CANCEL : FAILED;
45 PrintingContext::Result PrintingContext::UpdatePrintSettings(
46 const base::DictionaryValue& job_settings,
47 const PageRanges& ranges) {
48 ResetSettings();
50 job_settings.GetBoolean(kSettingHeaderFooterEnabled,
51 &settings_.display_header_footer);
53 int margin_type = DEFAULT_MARGINS;
54 if (!job_settings.GetInteger(kSettingMarginsType, &margin_type) ||
55 (margin_type != DEFAULT_MARGINS &&
56 margin_type != NO_MARGINS &&
57 margin_type != CUSTOM_MARGINS &&
58 margin_type != PRINTABLE_AREA_MARGINS)) {
59 margin_type = DEFAULT_MARGINS;
61 settings_.margin_type = static_cast<MarginType>(margin_type);
63 if (margin_type == CUSTOM_MARGINS) {
64 printing::PageSizeMargins page_size_margins;
65 GetCustomMarginsFromJobSettings(job_settings, &page_size_margins);
67 PageMargins margins_in_points;
68 margins_in_points.Clear();
69 margins_in_points.top = page_size_margins.margin_top;
70 margins_in_points.bottom = page_size_margins.margin_bottom;
71 margins_in_points.left = page_size_margins.margin_left;
72 margins_in_points.right = page_size_margins.margin_right;
74 settings_.SetCustomMargins(margins_in_points);
77 PrintingContext::Result result = UpdatePrinterSettings(job_settings, ranges);
78 PrintSettingsInitializer::InitHeaderFooterStrings(job_settings, &settings_);
80 job_settings.GetBoolean(kSettingShouldPrintBackgrounds,
81 &settings_.should_print_backgrounds);
82 job_settings.GetBoolean(kSettingShouldPrintSelectionOnly,
83 &settings_.selection_only);
84 return result;
87 } // namespace printing