From ccceef0e79a7af2c971023815f2f13f5915d7c4c Mon Sep 17 00:00:00 2001 From: Vladislav Kuzkokov Date: Wed, 4 Oct 2017 15:30:10 +0000 Subject: [PATCH] Remove PrintedPagesSource. There's currently no reason for this class to exist. Change-Id: Id8a981e37696ceb6c28687f4d894c4278d856997 Reviewed-on: https://chromium-review.googlesource.com/693015 Reviewed-by: Rebekah Potter Commit-Queue: Vladislav Kuzkokov Cr-Commit-Position: refs/heads/master@{#506394} --- chrome/browser/printing/print_job.cc | 17 +++---------- chrome/browser/printing/print_job.h | 12 ++-------- chrome/browser/printing/print_job_unittest.cc | 10 +------- .../printing/print_view_manager_base.cc | 3 +-- .../printing/print_view_manager_base.h | 5 +--- printing/BUILD.gn | 1 - printing/printed_document.cc | 21 +++++----------- printing/printed_document.h | 15 +++--------- printing/printed_document_win.cc | 1 - printing/printed_pages_source.h | 24 ------------------- 10 files changed, 17 insertions(+), 92 deletions(-) delete mode 100644 printing/printed_pages_source.h diff --git a/chrome/browser/printing/print_job.cc b/chrome/browser/printing/print_job.cc index 2d2973b340be47..73594fee12e0ae 100644 --- a/chrome/browser/printing/print_job.cc +++ b/chrome/browser/printing/print_job.cc @@ -45,10 +45,7 @@ void HoldRefCallback(const scoped_refptr& owner, } // namespace PrintJob::PrintJob() - : source_(nullptr), - is_job_pending_(false), - is_canceling_(false), - quit_factory_(this) { + : is_job_pending_(false), is_canceling_(false), quit_factory_(this) { // This is normally a UI message loop, but in unit tests, the message loop is // of the 'default' type. DCHECK(base::MessageLoopForUI::IsCurrent() || @@ -65,19 +62,17 @@ PrintJob::~PrintJob() { } void PrintJob::Initialize(PrintJobWorkerOwner* job, - PrintedPagesSource* source, + const base::string16& name, int page_count) { - DCHECK(!source_); DCHECK(!worker_); DCHECK(!is_job_pending_); DCHECK(!is_canceling_); DCHECK(!document_.get()); - source_ = source; worker_ = job->DetachWorker(this); settings_ = job->settings(); PrintedDocument* new_doc = - new PrintedDocument(settings_, source_, job->cookie()); + new PrintedDocument(settings_, name, job->cookie()); new_doc->set_page_count(page_count); UpdatePrintedDocument(new_doc); @@ -205,12 +200,6 @@ bool PrintJob::FlushJob(base::TimeDelta timeout) { return true; } -void PrintJob::DisconnectSource() { - source_ = nullptr; - if (document_.get()) - document_->DisconnectSource(); -} - bool PrintJob::is_job_pending() const { return is_job_pending_; } diff --git a/chrome/browser/printing/print_job.h b/chrome/browser/printing/print_job.h index 6a189d6d569290..239456ba2bade6 100644 --- a/chrome/browser/printing/print_job.h +++ b/chrome/browser/printing/print_job.h @@ -26,7 +26,6 @@ class MetafilePlayer; class PrintJobWorker; class PrintedDocument; class PrintedPage; -class PrintedPagesSource; class PrinterQuery; // Manages the print work for a specific document. Talks to the printer through @@ -44,7 +43,8 @@ class PrintJob : public PrintJobWorkerOwner, // Grabs the ownership of the PrintJobWorker from another job, which is // usually a PrinterQuery. Set the expected page count of the print job. - void Initialize(PrintJobWorkerOwner* job, PrintedPagesSource* source, + void Initialize(PrintJobWorkerOwner* job, + const base::string16& name, int page_count); // content::NotificationObserver implementation. @@ -79,10 +79,6 @@ class PrintJob : public PrintJobWorkerOwner, // our data. bool FlushJob(base::TimeDelta timeout); - // Disconnects the PrintedPage source (PrintedPagesSource). It is done when - // the source is being destroyed. - void DisconnectSource(); - // Returns true if the print job is pending, i.e. between a StartPrinting() // and the end of the spooling. bool is_job_pending() const; @@ -143,10 +139,6 @@ class PrintJob : public PrintJobWorkerOwner, content::NotificationRegistrar registrar_; - // Source that generates the PrintedPage's (i.e. a WebContents). It will be - // set back to NULL if the source is deleted before this object. - PrintedPagesSource* source_; - // All the UI is done in a worker thread because many Win32 print functions // are blocking and enters a message loop without your consent. There is one // worker thread per print job. diff --git a/chrome/browser/printing/print_job_unittest.cc b/chrome/browser/printing/print_job_unittest.cc index 3902443fb7f555..481d363169489d 100644 --- a/chrome/browser/printing/print_job_unittest.cc +++ b/chrome/browser/printing/print_job_unittest.cc @@ -17,18 +17,12 @@ #include "content/public/browser/notification_service.h" #include "content/public/common/child_process_host.h" #include "content/public/test/test_browser_thread_bundle.h" -#include "printing/printed_pages_source.h" #include "testing/gtest/include/gtest/gtest.h" namespace printing { namespace { -class TestSource : public PrintedPagesSource { - public: - base::string16 RenderSourceName() override { return base::string16(); } -}; - class TestPrintJobWorker : public PrintJobWorker { public: explicit TestPrintJobWorker(PrintJobWorkerOwner* owner) @@ -105,8 +99,7 @@ TEST(PrintJobTest, SimplePrint) { scoped_refptr job(new TestPrintJob(&check)); EXPECT_TRUE(job->RunsTasksInCurrentSequence()); scoped_refptr owner(new TestOwner); - TestSource source; - job->Initialize(owner.get(), &source, 1); + job->Initialize(owner.get(), base::string16(), 1); job->Stop(); while (job->document()) { base::RunLoop().RunUntilIdle(); @@ -139,7 +132,6 @@ TEST(PrintJobTest, SimplePrintLateInit) { job->Cancel(); job->RequestMissingPages(); job->FlushJob(timeout); - job->DisconnectSource(); job->is_job_pending(); job->document(); // Private diff --git a/chrome/browser/printing/print_view_manager_base.cc b/chrome/browser/printing/print_view_manager_base.cc index 88cecc9cbd2ed9..e1d7bcd79da69a 100644 --- a/chrome/browser/printing/print_view_manager_base.cc +++ b/chrome/browser/printing/print_view_manager_base.cc @@ -426,7 +426,7 @@ bool PrintViewManagerBase::CreateNewPrintJob(PrintJobWorkerOwner* job) { return false; print_job_ = new PrintJob(); - print_job_->Initialize(job, this, number_pages_); + print_job_->Initialize(job, RenderSourceName(), number_pages_); registrar_.Add(this, chrome::NOTIFICATION_PRINT_JOB_EVENT, content::Source(print_job_.get())); printing_succeeded_ = false; @@ -489,7 +489,6 @@ void PrintViewManagerBase::ReleasePrintJob() { registrar_.Remove(this, chrome::NOTIFICATION_PRINT_JOB_EVENT, content::Source(print_job_.get())); - print_job_->DisconnectSource(); // Don't close the worker thread. print_job_ = nullptr; } diff --git a/chrome/browser/printing/print_view_manager_base.h b/chrome/browser/printing/print_view_manager_base.h index ee19939c1341eb..80f697fc309a56 100644 --- a/chrome/browser/printing/print_view_manager_base.h +++ b/chrome/browser/printing/print_view_manager_base.h @@ -16,7 +16,6 @@ #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" #include "printing/features/features.h" -#include "printing/printed_pages_source.h" struct PrintHostMsg_DidPrintPage_Params; @@ -33,7 +32,6 @@ class PrintQueriesQueue; // Base class for managing the print commands for a WebContents. class PrintViewManagerBase : public content::NotificationObserver, - public PrintedPagesSource, public PrintManager { public: ~PrintViewManagerBase() override; @@ -54,8 +52,7 @@ class PrintViewManagerBase : public content::NotificationObserver, void SystemDialogCancelled(); #endif - // PrintedPagesSource implementation. - base::string16 RenderSourceName() override; + base::string16 RenderSourceName(); protected: explicit PrintViewManagerBase(content::WebContents* web_contents); diff --git a/printing/BUILD.gn b/printing/BUILD.gn index 5765b4f86f3b08..e03e46a30ede8e 100644 --- a/printing/BUILD.gn +++ b/printing/BUILD.gn @@ -73,7 +73,6 @@ component("printing") { "printed_document_win.cc", "printed_page.cc", "printed_page.h", - "printed_pages_source.h", "printing_context.cc", "printing_context.h", "printing_export.h", diff --git a/printing/printed_document.cc b/printing/printed_document.cc index 89428491a0666b..557d9b6f41fb2c 100644 --- a/printing/printed_document.cc +++ b/printing/printed_document.cc @@ -30,7 +30,6 @@ #include "printing/page_number.h" #include "printing/print_settings_conversion.h" #include "printing/printed_page.h" -#include "printing/printed_pages_source.h" #include "printing/units.h" #include "ui/gfx/font.h" #include "ui/gfx/text_elider.h" @@ -95,9 +94,9 @@ void DebugDumpSettings(const base::string16& doc_name, } // namespace PrintedDocument::PrintedDocument(const PrintSettings& settings, - PrintedPagesSource* source, + const base::string16& name, int cookie) - : mutable_(source), immutable_(settings, source, cookie) { + : immutable_(settings, name, cookie) { // Records the expected page count if a range is setup. if (!settings.ranges().empty()) { // If there is a range, set the number of page @@ -108,7 +107,7 @@ PrintedDocument::PrintedDocument(const PrintSettings& settings, } if (!g_debug_dump_info.Get().empty()) - DebugDumpSettings(name(), settings); + DebugDumpSettings(name, settings); } PrintedDocument::~PrintedDocument() { @@ -179,11 +178,6 @@ bool PrintedDocument::IsComplete() const { return true; } -void PrintedDocument::DisconnectSource() { - base::AutoLock lock(lock_); - mutable_.source_ = NULL; -} - void PrintedDocument::set_page_count(int max_page) { base::AutoLock lock(lock_); DCHECK_EQ(0, mutable_.page_count_); @@ -245,10 +239,7 @@ void PrintedDocument::DebugDumpData( base::RetainedRef(data))); } -PrintedDocument::Mutable::Mutable(PrintedPagesSource* source) - : source_(source), - expected_page_count_(0), - page_count_(0) { +PrintedDocument::Mutable::Mutable() : expected_page_count_(0), page_count_(0) { #if defined(OS_POSIX) && !defined(OS_MACOSX) first_page = INT_MAX; #endif @@ -258,9 +249,9 @@ PrintedDocument::Mutable::~Mutable() { } PrintedDocument::Immutable::Immutable(const PrintSettings& settings, - PrintedPagesSource* source, + const base::string16& name, int cookie) - : settings_(settings), name_(source->RenderSourceName()), cookie_(cookie) {} + : settings_(settings), name_(name), cookie_(cookie) {} PrintedDocument::Immutable::~Immutable() {} diff --git a/printing/printed_document.h b/printing/printed_document.h index 69598f63012e77..4858376d926adc 100644 --- a/printing/printed_document.h +++ b/printing/printed_document.h @@ -24,7 +24,6 @@ namespace printing { class MetafilePlayer; class PrintedPage; -class PrintedPagesSource; class PrintingContext; // A collection of rendered pages. The settings are immutable. If the print @@ -39,7 +38,7 @@ class PRINTING_EXPORT PrintedDocument // The cookie shall be unique and has a specific relationship with its // originating source and settings. PrintedDocument(const PrintSettings& settings, - PrintedPagesSource* source, + const base::string16& name, int cookie); // Sets a page's data. 0-based. Takes metafile ownership. @@ -72,10 +71,6 @@ class PRINTING_EXPORT PrintedDocument // Note: locks while parsing the whole tree. bool IsComplete() const; - // Disconnects the PrintedPage source (PrintedPagesSource). It is done when - // the source is being destroyed. - void DisconnectSource(); - // Sets the number of pages in the document to be rendered. Can only be set // once. // Note: locks for a short amount of time. @@ -122,13 +117,9 @@ class PRINTING_EXPORT PrintedDocument // Contains all the mutable stuff. All this stuff MUST be accessed with the // lock held. struct Mutable { - explicit Mutable(PrintedPagesSource* source); + Mutable(); ~Mutable(); - // Source that generates the PrintedPage's (i.e. a TabContents). It will be - // set back to NULL if the source is deleted before this object. - PrintedPagesSource* source_; - // Contains the pages' representation. This is a collection of PrintedPage. // Warning: Lock must be held when accessing this member. PrintedPages pages_; @@ -151,7 +142,7 @@ class PRINTING_EXPORT PrintedDocument // construction. struct Immutable { Immutable(const PrintSettings& settings, - PrintedPagesSource* source, + const base::string16& name, int cookie); ~Immutable(); diff --git a/printing/printed_document_win.cc b/printing/printed_document_win.cc index 0db3716ceb417e..ef1f896e343a5e 100644 --- a/printing/printed_document_win.cc +++ b/printing/printed_document_win.cc @@ -6,7 +6,6 @@ #include "base/logging.h" #include "printing/page_number.h" -#include "printing/printed_pages_source.h" #include "printing/printed_page.h" #include "printing/units.h" #include "skia/ext/skia_utils_win.h" diff --git a/printing/printed_pages_source.h b/printing/printed_pages_source.h deleted file mode 100644 index 689ff044fb7a83..00000000000000 --- a/printing/printed_pages_source.h +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef PRINTING_PRINTED_PAGES_SOURCE_H_ -#define PRINTING_PRINTED_PAGES_SOURCE_H_ - -#include "base/strings/string16.h" - -namespace printing { - -// Source of printed pages. -class PrintedPagesSource { - public: - // Returns the document title. - virtual base::string16 RenderSourceName() = 0; - - protected: - virtual ~PrintedPagesSource() {} -}; - -} // namespace printing - -#endif // PRINTING_PRINTED_PAGES_SOURCE_H_