Commit 081e3d8b authored by fdoray's avatar fdoray Committed by Commit bot

Use TaskScheduler instead of WorkerPool in extension_printer_handler.cc.

The following traits are used:

Priority: Inherited (default)
  The priority is inherited from the calling context (i.e. TaskTraits
  are initialized with the priority of the current task).

Shutdown behavior: CONTINUE_ON_SHUTDOWN
  Tasks posted with this mode which have not started executing before
  shutdown is initiated will never run. Tasks with this mode running at
  shutdown will be ignored (the worker will not be joined).

  Note: Tasks that were previously posted to base::WorkerPool should
  use this shutdown behavior because this is how base::WorkerPool
  handles all its tasks.

May Block:
  Tasks posted with MayBlock() may block. This includes but is not
  limited to tasks that wait on synchronous file I/O operations:
  read or write a file from disk, interact with a pipe or a socket,
  rename or delete a file, enumerate files in a directory, etc. This
  trait isn't required for the mere use of locks.

BUG=659191

Review-Url: https://codereview.chromium.org/2604923002
Cr-Commit-Position: refs/heads/master@{#442953}
parent 3c22c207
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/memory/ref_counted_memory.h" #include "base/memory/ref_counted_memory.h"
#include "base/strings/string_split.h" #include "base/strings/string_split.h"
#include "base/task_runner_util.h" #include "base/task_scheduler/post_task.h"
#include "chrome/browser/printing/pwg_raster_converter.h" #include "chrome/browser/printing/pwg_raster_converter.h"
#include "components/cloud_devices/common/cloud_device_description.h" #include "components/cloud_devices/common/cloud_device_description.h"
#include "components/cloud_devices/common/printer_description.h" #include "components/cloud_devices/common/printer_description.h"
...@@ -69,10 +69,9 @@ UpdateJobFileInfoOnWorkerThread( ...@@ -69,10 +69,9 @@ UpdateJobFileInfoOnWorkerThread(
// Callback to PWG raster conversion. // Callback to PWG raster conversion.
// Posts a task to update print job with info about file containing converted // Posts a task to update print job with info about file containing converted
// PWG raster data. The task is posted to |slow_task_runner|. // PWG raster data.
void UpdateJobFileInfo( void UpdateJobFileInfo(
std::unique_ptr<extensions::PrinterProviderPrintJob> job, std::unique_ptr<extensions::PrinterProviderPrintJob> job,
const scoped_refptr<base::TaskRunner>& slow_task_runner,
const ExtensionPrinterHandler::PrintJobCallback& callback, const ExtensionPrinterHandler::PrintJobCallback& callback,
bool success, bool success,
const base::FilePath& pwg_file_path) { const base::FilePath& pwg_file_path) {
...@@ -81,8 +80,11 @@ void UpdateJobFileInfo( ...@@ -81,8 +80,11 @@ void UpdateJobFileInfo(
return; return;
} }
base::PostTaskAndReplyWithResult( base::PostTaskWithTraitsAndReplyWithResult(
slow_task_runner.get(), FROM_HERE, FROM_HERE, base::TaskTraits()
.WithShutdownBehavior(
base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN)
.MayBlock(),
base::Bind(&UpdateJobFileInfoOnWorkerThread, pwg_file_path, base::Bind(&UpdateJobFileInfoOnWorkerThread, pwg_file_path,
base::Passed(&job)), base::Passed(&job)),
callback); callback);
...@@ -122,12 +124,8 @@ bool ParseProvisionalUsbPrinterId(const std::string& printer_id, ...@@ -122,12 +124,8 @@ bool ParseProvisionalUsbPrinterId(const std::string& printer_id,
} // namespace } // namespace
ExtensionPrinterHandler::ExtensionPrinterHandler( ExtensionPrinterHandler::ExtensionPrinterHandler(
content::BrowserContext* browser_context, content::BrowserContext* browser_context)
const scoped_refptr<base::TaskRunner>& slow_task_runner) : browser_context_(browser_context), weak_ptr_factory_(this) {}
: browser_context_(browser_context),
slow_task_runner_(slow_task_runner),
weak_ptr_factory_(this) {
}
ExtensionPrinterHandler::~ExtensionPrinterHandler() { ExtensionPrinterHandler::~ExtensionPrinterHandler() {
} }
...@@ -274,8 +272,7 @@ void ExtensionPrinterHandler::ConvertToPWGRaster( ...@@ -274,8 +272,7 @@ void ExtensionPrinterHandler::ConvertToPWGRaster(
data.get(), data.get(),
PWGRasterConverter::GetConversionSettings(printer_description, page_size), PWGRasterConverter::GetConversionSettings(printer_description, page_size),
PWGRasterConverter::GetBitmapSettings(printer_description, ticket), PWGRasterConverter::GetBitmapSettings(printer_description, ticket),
base::Bind(&UpdateJobFileInfo, base::Passed(&job), slow_task_runner_, base::Bind(&UpdateJobFileInfo, base::Passed(&job), callback));
callback));
} }
void ExtensionPrinterHandler::DispatchPrintJob( void ExtensionPrinterHandler::DispatchPrintJob(
......
...@@ -19,7 +19,6 @@ namespace base { ...@@ -19,7 +19,6 @@ namespace base {
class DictionaryValue; class DictionaryValue;
class ListValue; class ListValue;
class RefCountedMemory; class RefCountedMemory;
class TaskRunner;
} }
namespace content { namespace content {
...@@ -49,9 +48,7 @@ class ExtensionPrinterHandler : public PrinterHandler { ...@@ -49,9 +48,7 @@ class ExtensionPrinterHandler : public PrinterHandler {
using PrintJobCallback = base::Callback<void( using PrintJobCallback = base::Callback<void(
std::unique_ptr<extensions::PrinterProviderPrintJob>)>; std::unique_ptr<extensions::PrinterProviderPrintJob>)>;
ExtensionPrinterHandler( explicit ExtensionPrinterHandler(content::BrowserContext* browser_context);
content::BrowserContext* browser_context,
const scoped_refptr<base::TaskRunner>& slow_task_runner);
~ExtensionPrinterHandler() override; ~ExtensionPrinterHandler() override;
...@@ -122,8 +119,6 @@ class ExtensionPrinterHandler : public PrinterHandler { ...@@ -122,8 +119,6 @@ class ExtensionPrinterHandler : public PrinterHandler {
std::unique_ptr<printing::PWGRasterConverter> pwg_raster_converter_; std::unique_ptr<printing::PWGRasterConverter> pwg_raster_converter_;
int pending_enumeration_count_ = 0; int pending_enumeration_count_ = 0;
scoped_refptr<base::TaskRunner> slow_task_runner_;
base::WeakPtrFactory<ExtensionPrinterHandler> weak_ptr_factory_; base::WeakPtrFactory<ExtensionPrinterHandler> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(ExtensionPrinterHandler); DISALLOW_COPY_AND_ASSIGN(ExtensionPrinterHandler);
......
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/test/values_test_util.h" #include "base/test/values_test_util.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/extensions/test_extension_environment.h" #include "chrome/browser/extensions/test_extension_environment.h"
#include "chrome/browser/printing/pwg_raster_converter.h" #include "chrome/browser/printing/pwg_raster_converter.h"
...@@ -462,8 +461,8 @@ class ExtensionPrinterHandlerTest : public testing::Test { ...@@ -462,8 +461,8 @@ class ExtensionPrinterHandlerTest : public testing::Test {
void SetUp() override { void SetUp() override {
extensions::PrinterProviderAPIFactory::GetInstance()->SetTestingFactory( extensions::PrinterProviderAPIFactory::GetInstance()->SetTestingFactory(
env_.profile(), &BuildTestingPrinterProviderAPI); env_.profile(), &BuildTestingPrinterProviderAPI);
extension_printer_handler_.reset(new ExtensionPrinterHandler( extension_printer_handler_.reset(
env_.profile(), base::ThreadTaskRunnerHandle::Get())); new ExtensionPrinterHandler(env_.profile()));
pwg_raster_converter_ = new FakePWGRasterConverter(); pwg_raster_converter_ = new FakePWGRasterConverter();
extension_printer_handler_->SetPWGRasterConverterForTesting( extension_printer_handler_->SetPWGRasterConverterForTesting(
......
...@@ -4,12 +4,11 @@ ...@@ -4,12 +4,11 @@
#include "chrome/browser/ui/webui/print_preview/printer_handler.h" #include "chrome/browser/ui/webui/print_preview/printer_handler.h"
#include "base/threading/worker_pool.h"
#include "chrome/browser/ui/webui/print_preview/extension_printer_handler.h" #include "chrome/browser/ui/webui/print_preview/extension_printer_handler.h"
// static // static
std::unique_ptr<PrinterHandler> PrinterHandler::CreateForExtensionPrinters( std::unique_ptr<PrinterHandler> PrinterHandler::CreateForExtensionPrinters(
content::BrowserContext* browser_context) { content::BrowserContext* browser_context) {
return std::unique_ptr<ExtensionPrinterHandler>(new ExtensionPrinterHandler( return std::unique_ptr<ExtensionPrinterHandler>(
browser_context, base::WorkerPool::GetTaskRunner(true))); new ExtensionPrinterHandler(browser_context));
} }
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