[go: nahoru, domu]

Use process behavior field in PrintingContext

In order to support a policy override for controlling out-of-process
printing, the low-level //printing layer cannot rely solely upon the
printing feature flags.  Since policy preferences reside at a higher
level than //printing, this state information needs to be provided
to PrintingContext.

All logic under //printing which uses ShouldPrintJobOop() needs to be
changed.  In some cases it is insufficient to just rely upon the
existing signal for whether system calls should be skipped, so a more
detailed signal is needed.

Replace the PrintingContext "skip system calls" mechanism with an enum
to identify the process behavior desired.  This can provide the details
for whether OOP printing is involved in addition to whether system
calls should be skipped for the PrintingContext instance being created.

This API change ripples through the rest of the printing stack.  This
prepares the upper levels of the printing stack to be ready to override
the behavior if OOP printing policy is specified.

Printing support in Pepper is unused, so this code no longer even needs
to check the feature flags.  This code is just changed to use a
placeholder value of OOP disabled.

Bug: 1497035
Low-Coverage-Reason: HARD_TO_TEST, https://crbug.com/1256506, https://crbug.com/1451540
Change-Id: I8724631551aeeeb954560f3c28f5ffb1f5c0b1f7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4987444
Reviewed-by: Derek Schuff <dschuff@chromium.org>
Commit-Queue: Alan Screen <awscreen@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1220535}
diff --git a/printing/emf_win_unittest.cc b/printing/emf_win_unittest.cc
index e02dc28..b2fe6777 100644
--- a/printing/emf_win_unittest.cc
+++ b/printing/emf_win_unittest.cc
@@ -90,7 +90,8 @@
   settings->set_device_name(u"UnitTest Printer");
 
   // Initialize it.
-  PrintingContextWin context(this);
+  PrintingContextWin context(this,
+                             PrintingContext::ProcessBehavior::kOopDisabled);
   EXPECT_EQ(mojom::ResultCode::kSuccess,
             context.InitWithSettingsForTest(std::move(settings)));
 
diff --git a/printing/printing_context.cc b/printing/printing_context.cc
index 6aae870..94f51e9f 100644
--- a/printing/printing_context.cc
+++ b/printing/printing_context.cc
@@ -29,11 +29,13 @@
 
 }  // namespace
 
-PrintingContext::PrintingContext(Delegate* delegate)
+PrintingContext::PrintingContext(Delegate* delegate,
+                                 ProcessBehavior process_behavior)
     : settings_(std::make_unique<PrintSettings>()),
       delegate_(delegate),
       in_print_job_(false),
-      abort_printing_(false) {
+      abort_printing_(false),
+      process_behavior_(process_behavior) {
   DCHECK(delegate_);
 }
 
@@ -42,11 +44,11 @@
 // static
 std::unique_ptr<PrintingContext> PrintingContext::Create(
     Delegate* delegate,
-    bool skip_system_calls) {
+    ProcessBehavior process_behavior) {
   return g_printing_context_factory_for_test
              ? g_printing_context_factory_for_test->CreatePrintingContext(
-                   delegate, skip_system_calls)
-             : PrintingContext::CreateImpl(delegate, skip_system_calls);
+                   delegate, process_behavior)
+             : PrintingContext::CreateImpl(delegate, process_behavior);
 }
 
 // static
diff --git a/printing/printing_context.h b/printing/printing_context.h
index c753f04..6db58a99 100644
--- a/printing/printing_context.h
+++ b/printing/printing_context.h
@@ -64,6 +64,28 @@
 #endif
   };
 
+  enum class ProcessBehavior {
+    // Out-of-process support is disabled.  All platform printing calls are
+    // performed in the browser process.
+    kOopDisabled,
+#if BUILDFLAG(ENABLE_OOP_PRINTING)
+    // Out-of-process support is enabled.  This is for `PrintingContext`
+    // objects which exist in the PrintBackend service.  These objects make
+    // platform printing calls.
+    kOopEnabledPerformSystemCalls,
+    // Out-of-process support is enabled.  This is for `PrintingContext`
+    // objects which exist in the browser process.  These objects normally skip
+    // doing platform printing calls, deferring to an associated
+    // `PrintingContext` that is running in a PrintBackend service (i.e.,
+    // deferring to a `PrintingContext` with `kOopEnabledPerformSystemCalls`).
+    // An exception to deferring platform calls in this case is for platforms
+    // that cannot display a system print dialog from a PrintBackend service.
+    // On such platforms the relevant calls to invoke a system print dialog
+    // are still made from the browser process.
+    kOopEnabledSkipSystemCalls,
+#endif
+  };
+
   PrintingContext(const PrintingContext&) = delete;
   PrintingContext& operator=(const PrintingContext&) = delete;
   virtual ~PrintingContext();
@@ -157,14 +179,20 @@
 #endif
 
   // Creates an instance of this object.
-  static std::unique_ptr<PrintingContext> Create(Delegate* delegate,
-                                                 bool skip_system_calls);
+  static std::unique_ptr<PrintingContext> Create(
+      Delegate* delegate,
+      ProcessBehavior process_behavior);
 
   // Test method for generating printing contexts for testing.  This overrides
   // the platform-specific implementations of CreateImpl().
   static void SetPrintingContextFactoryForTest(
       PrintingContextFactoryForTest* factory);
 
+  // Determine process behavior, which can determine if system calls should be
+  // made and if certain extra code paths should be followed to support
+  // out-of-process printing.
+  ProcessBehavior process_behavior() const { return process_behavior_; }
+
   void set_margin_type(mojom::MarginType type);
   void set_is_modifiable(bool is_modifiable);
 
@@ -177,31 +205,17 @@
   int job_id() const { return job_id_; }
 
  protected:
-  explicit PrintingContext(Delegate* delegate);
+  PrintingContext(Delegate* delegate, ProcessBehavior process_behavior);
 
   // Creates an instance of this object. Implementers of this interface should
   // implement this method to create an object of their implementation.
-  static std::unique_ptr<PrintingContext> CreateImpl(Delegate* delegate,
-                                                     bool skip_system_calls);
+  static std::unique_ptr<PrintingContext> CreateImpl(
+      Delegate* delegate,
+      ProcessBehavior process_behavior);
 
   // Reinitializes the settings for object reuse.
   void ResetSettings();
 
-  // Determine if system calls should be skipped by this instance.
-  bool skip_system_calls() const {
-#if BUILDFLAG(ENABLE_OOP_PRINTING)
-    return skip_system_calls_;
-#else
-    return false;
-#endif
-  }
-
-#if BUILDFLAG(ENABLE_OOP_PRINTING)
-  // Make the one-way adjustment to have all system calls skipped by this
-  // `PrintingContext` instance.
-  void set_skip_system_calls() { skip_system_calls_ = true; }
-#endif
-
   // Does bookkeeping when an error occurs.
   virtual mojom::ResultCode OnError();
 
@@ -221,11 +235,7 @@
   int job_id_;
 
  private:
-#if BUILDFLAG(ENABLE_OOP_PRINTING)
-  // If this instance of PrintingContext should skip making any system calls
-  // to the operating system.
-  bool skip_system_calls_ = false;
-#endif
+  const ProcessBehavior process_behavior_;
 };
 
 }  // namespace printing
diff --git a/printing/printing_context_android.cc b/printing/printing_context_android.cc
index 80a40fc3..e1756eb 100644
--- a/printing/printing_context_android.cc
+++ b/printing/printing_context_android.cc
@@ -13,6 +13,7 @@
 #include "base/android/jni_android.h"
 #include "base/android/jni_array.h"
 #include "base/android/jni_string.h"
+#include "base/check_op.h"
 #include "base/files/file.h"
 #include "base/logging.h"
 #include "base/strings/string_number_conversions.h"
@@ -63,8 +64,8 @@
 // static
 std::unique_ptr<PrintingContext> PrintingContext::CreateImpl(
     Delegate* delegate,
-    bool skip_system_calls) {
-  DCHECK(!skip_system_calls);
+    ProcessBehavior process_behavior) {
+  DCHECK_EQ(process_behavior, ProcessBehavior::kOopDisabled);
   return std::make_unique<PrintingContextAndroid>(delegate);
 }
 
@@ -86,7 +87,7 @@
 }
 
 PrintingContextAndroid::PrintingContextAndroid(Delegate* delegate)
-    : PrintingContext(delegate) {
+    : PrintingContext(delegate, ProcessBehavior::kOopDisabled) {
   // The constructor is run in the IO thread.
 }
 
diff --git a/printing/printing_context_chromeos.cc b/printing/printing_context_chromeos.cc
index f3ff67f..11c2d149 100644
--- a/printing/printing_context_chromeos.cc
+++ b/printing/printing_context_chromeos.cc
@@ -280,34 +280,33 @@
 // static
 std::unique_ptr<PrintingContext> PrintingContext::CreateImpl(
     Delegate* delegate,
-    bool skip_system_calls) {
-  auto context = std::make_unique<PrintingContextChromeos>(delegate);
-#if BUILDFLAG(ENABLE_OOP_PRINTING)
-  if (skip_system_calls)
-    context->set_skip_system_calls();
-#endif
-  return context;
+    ProcessBehavior process_behavior) {
+  return std::make_unique<PrintingContextChromeos>(delegate, process_behavior);
 }
 
 // static
 std::unique_ptr<PrintingContextChromeos>
 PrintingContextChromeos::CreateForTesting(
     Delegate* delegate,
+    ProcessBehavior process_behavior,
     std::unique_ptr<CupsConnection> connection) {
   // Private ctor.
-  return base::WrapUnique(
-      new PrintingContextChromeos(delegate, std::move(connection)));
+  return base::WrapUnique(new PrintingContextChromeos(
+      delegate, process_behavior, std::move(connection)));
 }
 
-PrintingContextChromeos::PrintingContextChromeos(Delegate* delegate)
-    : PrintingContext(delegate),
+PrintingContextChromeos::PrintingContextChromeos(
+    Delegate* delegate,
+    ProcessBehavior process_behavior)
+    : PrintingContext(delegate, process_behavior),
       connection_(CupsConnection::Create()),
       ipp_options_(WrapIpp(nullptr)) {}
 
 PrintingContextChromeos::PrintingContextChromeos(
     Delegate* delegate,
+    ProcessBehavior process_behavior,
     std::unique_ptr<CupsConnection> connection)
-    : PrintingContext(delegate),
+    : PrintingContext(delegate, process_behavior),
       connection_(std::move(connection)),
       ipp_options_(WrapIpp(nullptr)) {}
 
@@ -447,8 +446,11 @@
   DCHECK(!in_print_job_);
   in_print_job_ = true;
 
-  if (skip_system_calls())
+#if BUILDFLAG(ENABLE_OOP_PRINTING)
+  if (process_behavior() == ProcessBehavior::kOopEnabledSkipSystemCalls) {
     return mojom::ResultCode::kSuccess;
+  }
+#endif
 
   std::string converted_name;
   if (send_user_info_) {
diff --git a/printing/printing_context_chromeos.h b/printing/printing_context_chromeos.h
index 67bc0026..deb0bb3 100644
--- a/printing/printing_context_chromeos.h
+++ b/printing/printing_context_chromeos.h
@@ -22,9 +22,10 @@
  public:
   static std::unique_ptr<PrintingContextChromeos> CreateForTesting(
       Delegate* delegate,
+      ProcessBehavior process_behavior,
       std::unique_ptr<CupsConnection> connection);
 
-  explicit PrintingContextChromeos(Delegate* delegate);
+  PrintingContextChromeos(Delegate* delegate, ProcessBehavior process_behavior);
   PrintingContextChromeos(const PrintingContextChromeos&) = delete;
   PrintingContextChromeos& operator=(const PrintingContextChromeos&) = delete;
   ~PrintingContextChromeos() override;
@@ -52,6 +53,7 @@
  private:
   // For testing. Use CreateForTesting() to create.
   PrintingContextChromeos(Delegate* delegate,
+                          ProcessBehavior process_behavior,
                           std::unique_ptr<CupsConnection> connection);
 
   // Lazily initializes `printer_`.
diff --git a/printing/printing_context_chromeos_unittest.cc b/printing/printing_context_chromeos_unittest.cc
index 8992f6e..2b74ba7 100644
--- a/printing/printing_context_chromeos_unittest.cc
+++ b/printing/printing_context_chromeos_unittest.cc
@@ -72,7 +72,8 @@
     EXPECT_CALL(*connection, GetPrinter(kPrinterName))
         .WillOnce(Return(ByMove(std::move(unique_printer))));
     printing_context_ = PrintingContextChromeos::CreateForTesting(
-        this, std::move(unique_connection));
+        this, PrintingContext::ProcessBehavior::kOopDisabled,
+        std::move(unique_connection));
     auto settings = std::make_unique<PrintSettings>();
     settings->set_device_name(kPrinterName16);
     settings->set_send_user_info(send_user_info);
diff --git a/printing/printing_context_factory_for_test.h b/printing/printing_context_factory_for_test.h
index 6ef1b51..8498a18 100644
--- a/printing/printing_context_factory_for_test.h
+++ b/printing/printing_context_factory_for_test.h
@@ -15,7 +15,7 @@
  public:
   virtual std::unique_ptr<PrintingContext> CreatePrintingContext(
       PrintingContext::Delegate* delegate,
-      bool skip_system_calls) = 0;
+      PrintingContext::ProcessBehavior process_behavior) = 0;
 };
 
 }  // namespace printing
diff --git a/printing/printing_context_linux.cc b/printing/printing_context_linux.cc
index 2bb8fbf..49f0ddab 100644
--- a/printing/printing_context_linux.cc
+++ b/printing/printing_context_linux.cc
@@ -32,17 +32,13 @@
 // static
 std::unique_ptr<PrintingContext> PrintingContext::CreateImpl(
     Delegate* delegate,
-    bool skip_system_calls) {
-  auto context = std::make_unique<PrintingContextLinux>(delegate);
-#if BUILDFLAG(ENABLE_OOP_PRINTING)
-  if (skip_system_calls)
-    context->set_skip_system_calls();
-#endif
-  return context;
+    ProcessBehavior process_behavior) {
+  return std::make_unique<PrintingContextLinux>(delegate, process_behavior);
 }
 
-PrintingContextLinux::PrintingContextLinux(Delegate* delegate)
-    : PrintingContext(delegate), print_dialog_(nullptr) {}
+PrintingContextLinux::PrintingContextLinux(Delegate* delegate,
+                                           ProcessBehavior process_behavior)
+    : PrintingContext(delegate, process_behavior), print_dialog_(nullptr) {}
 
 PrintingContextLinux::~PrintingContextLinux() {
   ReleaseContext();
@@ -134,12 +130,15 @@
   document_name_ = document_name;
 
 #if BUILDFLAG(ENABLE_OOP_PRINTING_NO_OOP_BASIC_PRINT_DIALOG)
-  if (skip_system_calls()) {
+  if (process_behavior() == ProcessBehavior::kOopEnabledSkipSystemCalls) {
     return mojom::ResultCode::kSuccess;
   }
 
-  if (features::ShouldPrintJobOop() &&
+  if (process_behavior() == ProcessBehavior::kOopEnabledPerformSystemCalls &&
       !settings_->system_print_dialog_data().empty()) {
+    // Take the settings captured by the browser process from the system print
+    // dialog and apply them to this printing context in the PrintBackend
+    // service.
     if (!print_dialog_) {
       CHECK(ui::LinuxUi::instance());
       print_dialog_ = ui::LinuxUi::instance()->CreatePrintDialog(this);
diff --git a/printing/printing_context_linux.h b/printing/printing_context_linux.h
index 6fb35248..86ccebe 100644
--- a/printing/printing_context_linux.h
+++ b/printing/printing_context_linux.h
@@ -20,7 +20,7 @@
 // PrintingContext with optional native UI for print dialog and pdf_paper_size.
 class COMPONENT_EXPORT(PRINTING) PrintingContextLinux : public PrintingContext {
  public:
-  explicit PrintingContextLinux(Delegate* delegate);
+  PrintingContextLinux(Delegate* delegate, ProcessBehavior process_behavior);
   PrintingContextLinux(const PrintingContextLinux&) = delete;
   PrintingContextLinux& operator=(const PrintingContextLinux&) = delete;
   ~PrintingContextLinux() override;
diff --git a/printing/printing_context_mac.h b/printing/printing_context_mac.h
index c9a13ae..0b21e70 100644
--- a/printing/printing_context_mac.h
+++ b/printing/printing_context_mac.h
@@ -21,7 +21,7 @@
 
 class COMPONENT_EXPORT(PRINTING) PrintingContextMac : public PrintingContext {
  public:
-  explicit PrintingContextMac(Delegate* delegate);
+  PrintingContextMac(Delegate* delegate, ProcessBehavior process_behavior);
   PrintingContextMac(const PrintingContextMac&) = delete;
   PrintingContextMac& operator=(const PrintingContextMac&) = delete;
   ~PrintingContextMac() override;
diff --git a/printing/printing_context_mac.mm b/printing/printing_context_mac.mm
index fab1e04..b051381 100644
--- a/printing/printing_context_mac.mm
+++ b/printing/printing_context_mac.mm
@@ -361,17 +361,13 @@
 // static
 std::unique_ptr<PrintingContext> PrintingContext::CreateImpl(
     Delegate* delegate,
-    bool skip_system_calls) {
-  auto context = std::make_unique<PrintingContextMac>(delegate);
-#if BUILDFLAG(ENABLE_OOP_PRINTING)
-  if (skip_system_calls)
-    context->set_skip_system_calls();
-#endif
-  return context;
+    ProcessBehavior process_behavior) {
+  return std::make_unique<PrintingContextMac>(delegate, process_behavior);
 }
 
-PrintingContextMac::PrintingContextMac(Delegate* delegate)
-    : PrintingContext(delegate),
+PrintingContextMac::PrintingContextMac(Delegate* delegate,
+                                       ProcessBehavior process_behavior)
+    : PrintingContext(delegate, process_behavior),
       print_info_([NSPrintInfo.sharedPrintInfo copy]) {}
 
 PrintingContextMac::~PrintingContextMac() {
@@ -427,7 +423,11 @@
         InitPrintSettingsFromPrintInfo();
         mojom::ResultCode result = mojom::ResultCode::kSuccess;
 #if BUILDFLAG(ENABLE_OOP_PRINTING_NO_OOP_BASIC_PRINT_DIALOG)
-        if (features::ShouldPrintJobOop()) {
+        if (process_behavior() == ProcessBehavior::kOopEnabledSkipSystemCalls) {
+          // This is running in the browser process, where system calls are
+          // normally not allowed except for this system dialog exception.
+          // Capture the setting here to be transmitted to a PrintBackend
+          // service when the document is printed.
           result = CaptureSystemPrintDialogData(print_info_, settings_.get());
         }
 #endif
@@ -767,12 +767,19 @@
 
   in_print_job_ = true;
 
-  if (skip_system_calls())
+#if BUILDFLAG(ENABLE_OOP_PRINTING)
+  if (process_behavior() == ProcessBehavior::kOopEnabledSkipSystemCalls) {
     return mojom::ResultCode::kSuccess;
+  }
+#endif
 
 #if BUILDFLAG(ENABLE_OOP_PRINTING_NO_OOP_BASIC_PRINT_DIALOG)
-  if (features::ShouldPrintJobOop() &&
+  if (process_behavior() == ProcessBehavior::kOopEnabledPerformSystemCalls &&
       !settings_->system_print_dialog_data().empty()) {
+    // Settings which the browser process captured from the system dialog now
+    // need to be applied to the printing context here which is running in a
+    // PrintBackend service.
+
     // NOTE: Reset `print_info_` with a copy of `sharedPrintInfo` so as to
     // start with a clean slate.
     print_info_ = [[NSPrintInfo sharedPrintInfo] copy];
diff --git a/printing/printing_context_no_system_dialog.cc b/printing/printing_context_no_system_dialog.cc
index 4809793..c6ca48a 100644
--- a/printing/printing_context_no_system_dialog.cc
+++ b/printing/printing_context_no_system_dialog.cc
@@ -23,13 +23,16 @@
 // static
 std::unique_ptr<PrintingContext> PrintingContext::CreateImpl(
     Delegate* delegate,
-    bool skip_system_calls) {
-  return std::make_unique<PrintingContextNoSystemDialog>(delegate);
+    ProcessBehavior process_behavior) {
+  return std::make_unique<PrintingContextNoSystemDialog>(delegate,
+                                                         process_behavior);
 }
 #endif  // !BUILDFLAG(USE_CUPS)
 
-PrintingContextNoSystemDialog::PrintingContextNoSystemDialog(Delegate* delegate)
-    : PrintingContext(delegate) {}
+PrintingContextNoSystemDialog::PrintingContextNoSystemDialog(
+    Delegate* delegate,
+    ProcessBehavior process_behavior)
+    : PrintingContext(delegate, process_behavior) {}
 
 PrintingContextNoSystemDialog::~PrintingContextNoSystemDialog() {
   ReleaseContext();
diff --git a/printing/printing_context_no_system_dialog.h b/printing/printing_context_no_system_dialog.h
index 92c4145c..b0dcf7f8 100644
--- a/printing/printing_context_no_system_dialog.h
+++ b/printing/printing_context_no_system_dialog.h
@@ -16,7 +16,8 @@
 class COMPONENT_EXPORT(PRINTING) PrintingContextNoSystemDialog
     : public PrintingContext {
  public:
-  explicit PrintingContextNoSystemDialog(Delegate* delegate);
+  PrintingContextNoSystemDialog(Delegate* delegate,
+                                ProcessBehavior process_behavior);
   PrintingContextNoSystemDialog(const PrintingContextNoSystemDialog&) = delete;
   PrintingContextNoSystemDialog& operator=(
       const PrintingContextNoSystemDialog&) = delete;
diff --git a/printing/printing_context_system_dialog_win.cc b/printing/printing_context_system_dialog_win.cc
index 8a7d9c1..391397c 100644
--- a/printing/printing_context_system_dialog_win.cc
+++ b/printing/printing_context_system_dialog_win.cc
@@ -15,15 +15,11 @@
 #include "printing/print_settings_initializer_win.h"
 #include "skia/ext/skia_utils_win.h"
 
-#if BUILDFLAG(ENABLE_OOP_PRINTING)
-#include "printing/printing_features.h"
-#endif
-
 namespace printing {
 
 HWND PrintingContextSystemDialogWin::GetWindow() {
 #if BUILDFLAG(ENABLE_OOP_PRINTING)
-  if (features::ShouldPrintJobOop()) {
+  if (process_behavior() == ProcessBehavior::kOopEnabledPerformSystemCalls) {
     // Delving through the view tree to get to root window happens separately
     // in the browser process (i.e., not in `PrintingContextSystemDialogWin`)
     // before sending the identified window owner to the Print Backend service.
@@ -39,8 +35,9 @@
 }
 
 PrintingContextSystemDialogWin::PrintingContextSystemDialogWin(
-    Delegate* delegate)
-    : PrintingContextWin(delegate) {}
+    Delegate* delegate,
+    ProcessBehavior process_behavior)
+    : PrintingContextWin(delegate, process_behavior) {}
 
 PrintingContextSystemDialogWin::~PrintingContextSystemDialogWin() {}
 
diff --git a/printing/printing_context_system_dialog_win.h b/printing/printing_context_system_dialog_win.h
index d873d9dc..ca4a1ac 100644
--- a/printing/printing_context_system_dialog_win.h
+++ b/printing/printing_context_system_dialog_win.h
@@ -20,7 +20,8 @@
 class COMPONENT_EXPORT(PRINTING) PrintingContextSystemDialogWin
     : public PrintingContextWin {
  public:
-  explicit PrintingContextSystemDialogWin(Delegate* delegate);
+  PrintingContextSystemDialogWin(Delegate* delegate,
+                                 ProcessBehavior process_behavior);
   PrintingContextSystemDialogWin(const PrintingContextSystemDialogWin&) =
       delete;
   PrintingContextSystemDialogWin& operator=(
diff --git a/printing/printing_context_win.cc b/printing/printing_context_win.cc
index 82f8235..db75a04 100644
--- a/printing/printing_context_win.cc
+++ b/printing/printing_context_win.cc
@@ -78,18 +78,14 @@
 // static
 std::unique_ptr<PrintingContext> PrintingContext::CreateImpl(
     Delegate* delegate,
-    bool skip_system_calls) {
-  std::unique_ptr<PrintingContext> context;
-  context = std::make_unique<PrintingContextSystemDialogWin>(delegate);
-#if BUILDFLAG(ENABLE_OOP_PRINTING)
-  if (skip_system_calls)
-    context->set_skip_system_calls();
-#endif
-  return context;
+    ProcessBehavior process_behavior) {
+  return std::make_unique<PrintingContextSystemDialogWin>(delegate,
+                                                          process_behavior);
 }
 
-PrintingContextWin::PrintingContextWin(Delegate* delegate)
-    : PrintingContext(delegate), context_(nullptr) {}
+PrintingContextWin::PrintingContextWin(Delegate* delegate,
+                                       ProcessBehavior process_behavior)
+    : PrintingContext(delegate, process_behavior), context_(nullptr) {}
 
 PrintingContextWin::~PrintingContextWin() {
   ReleaseContext();
@@ -327,16 +323,24 @@
 mojom::ResultCode PrintingContextWin::NewDocument(
     const std::u16string& document_name) {
   DCHECK(!in_print_job_);
-  if (!context_ && !skip_system_calls())
+  if (!context_
+#if BUILDFLAG(ENABLE_OOP_PRINTING)
+      && process_behavior() != ProcessBehavior::kOopEnabledSkipSystemCalls
+#endif
+  ) {
     return OnError();
+  }
 
   // Set the flag used by the AbortPrintJob dialog procedure.
   abort_printing_ = false;
 
   in_print_job_ = true;
 
-  if (skip_system_calls())
+#if BUILDFLAG(ENABLE_OOP_PRINTING)
+  if (process_behavior() == ProcessBehavior::kOopEnabledSkipSystemCalls) {
     return mojom::ResultCode::kSuccess;
+  }
+#endif
 
   if (base::FeatureList::IsEnabled(printing::features::kUseXpsForPrinting)) {
     // This is all the new document context needed when using XPS.
diff --git a/printing/printing_context_win.h b/printing/printing_context_win.h
index b4d969d0..f3babb9 100644
--- a/printing/printing_context_win.h
+++ b/printing/printing_context_win.h
@@ -20,7 +20,7 @@
 
 class COMPONENT_EXPORT(PRINTING) PrintingContextWin : public PrintingContext {
  public:
-  explicit PrintingContextWin(Delegate* delegate);
+  PrintingContextWin(Delegate* delegate, ProcessBehavior process_behavior);
   PrintingContextWin(const PrintingContextWin&) = delete;
   PrintingContextWin& operator=(const PrintingContextWin&) = delete;
   ~PrintingContextWin() override;
diff --git a/printing/printing_context_win_unittest.cc b/printing/printing_context_win_unittest.cc
index d55e5ab..4398dbe 100644
--- a/printing/printing_context_win_unittest.cc
+++ b/printing/printing_context_win_unittest.cc
@@ -58,8 +58,10 @@
 
 class MockPrintingContextWin : public PrintingContextSystemDialogWin {
  public:
-  explicit MockPrintingContextWin(Delegate* delegate)
-      : PrintingContextSystemDialogWin(delegate) {}
+  MockPrintingContextWin(Delegate* delegate)
+      : PrintingContextSystemDialogWin(
+            delegate,
+            PrintingContext::ProcessBehavior::kOopDisabled) {}
 
  protected:
   // This is a fake PrintDlgEx implementation that sets the right fields in
@@ -183,7 +185,8 @@
   auto settings = std::make_unique<PrintSettings>();
   settings->set_device_name(base::WideToUTF16(GetDefaultPrinter()));
   // Initialize it.
-  PrintingContextWin context(this);
+  PrintingContextWin context(this,
+                             PrintingContext::ProcessBehavior::kOopDisabled);
   EXPECT_EQ(mojom::ResultCode::kSuccess,
             context.InitWithSettingsForTest(std::move(settings)));
 
diff --git a/printing/test_printing_context.cc b/printing/test_printing_context.cc
index da8055a..8eca2dfa 100644
--- a/printing/test_printing_context.cc
+++ b/printing/test_printing_context.cc
@@ -43,13 +43,8 @@
 }
 
 TestPrintingContext::TestPrintingContext(Delegate* delegate,
-                                         bool skip_system_calls)
-    : PrintingContext(delegate) {
-#if BUILDFLAG(ENABLE_OOP_PRINTING)
-  if (skip_system_calls)
-    set_skip_system_calls();
-#endif
-}
+                                         ProcessBehavior process_behavior)
+    : PrintingContext(delegate, process_behavior) {}
 
 TestPrintingContext::~TestPrintingContext() = default;
 
@@ -185,7 +180,7 @@
   DCHECK(!in_print_job_);
 
 #if BUILDFLAG(ENABLE_OOP_PRINTING_NO_OOP_BASIC_PRINT_DIALOG)
-  if (!skip_system_calls() && features::ShouldPrintJobOop() &&
+  if (process_behavior() == ProcessBehavior::kOopEnabledPerformSystemCalls &&
       !settings_->system_print_dialog_data().empty()) {
     // Mimic the update when system print dialog settings are provided to
     // Print Backend service from the browser process.
@@ -204,7 +199,13 @@
   abort_printing_ = false;
   in_print_job_ = true;
 
-  if (!skip_system_calls()) {
+#if BUILDFLAG(ENABLE_OOP_PRINTING)
+  const bool make_system_calls =
+      process_behavior() != ProcessBehavior::kOopEnabledSkipSystemCalls;
+#else
+  const bool make_system_calls = true;
+#endif
+  if (make_system_calls) {
     if (new_document_cancels_) {
       return mojom::ResultCode::kCanceled;
     }
diff --git a/printing/test_printing_context.h b/printing/test_printing_context.h
index 5750134..1db95b6 100644
--- a/printing/test_printing_context.h
+++ b/printing/test_printing_context.h
@@ -45,7 +45,7 @@
 #endif
       const PrintSettings&)>;
 
-  TestPrintingContext(Delegate* delegate, bool skip_system_calls);
+  TestPrintingContext(Delegate* delegate, ProcessBehavior process_behavior);
   TestPrintingContext(const TestPrintingContext&) = delete;
   TestPrintingContext& operator=(const TestPrintingContext&) = delete;
   ~TestPrintingContext() override;