Skip to content

Commit

Permalink
Remove PrintedPagesSource.
Browse files Browse the repository at this point in the history
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 <rbpotter@chromium.org>
Commit-Queue: Vladislav Kuzkokov <vkuzkokov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#506394}
  • Loading branch information
Vladislav Kuzkokov authored and Commit Bot committed Oct 4, 2017
1 parent 1dd22ad commit ccceef0
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 92 deletions.
17 changes: 3 additions & 14 deletions chrome/browser/printing/print_job.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ void HoldRefCallback(const scoped_refptr<PrintJobWorkerOwner>& 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() ||
Expand All @@ -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);
Expand Down Expand Up @@ -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_;
}
Expand Down
12 changes: 2 additions & 10 deletions chrome/browser/printing/print_job.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
10 changes: 1 addition & 9 deletions chrome/browser/printing/print_job_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -105,8 +99,7 @@ TEST(PrintJobTest, SimplePrint) {
scoped_refptr<PrintJob> job(new TestPrintJob(&check));
EXPECT_TRUE(job->RunsTasksInCurrentSequence());
scoped_refptr<TestOwner> 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();
Expand Down Expand Up @@ -139,7 +132,6 @@ TEST(PrintJobTest, SimplePrintLateInit) {
job->Cancel();
job->RequestMissingPages();
job->FlushJob(timeout);
job->DisconnectSource();
job->is_job_pending();
job->document();
// Private
Expand Down
3 changes: 1 addition & 2 deletions chrome/browser/printing/print_view_manager_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<PrintJob>(print_job_.get()));
printing_succeeded_ = false;
Expand Down Expand Up @@ -489,7 +489,6 @@ void PrintViewManagerBase::ReleasePrintJob() {

registrar_.Remove(this, chrome::NOTIFICATION_PRINT_JOB_EVENT,
content::Source<PrintJob>(print_job_.get()));
print_job_->DisconnectSource();
// Don't close the worker thread.
print_job_ = nullptr;
}
Expand Down
5 changes: 1 addition & 4 deletions chrome/browser/printing/print_view_manager_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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);
Expand Down
1 change: 0 additions & 1 deletion printing/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
21 changes: 6 additions & 15 deletions printing/printed_document.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -108,7 +107,7 @@ PrintedDocument::PrintedDocument(const PrintSettings& settings,
}

if (!g_debug_dump_info.Get().empty())
DebugDumpSettings(name(), settings);
DebugDumpSettings(name, settings);
}

PrintedDocument::~PrintedDocument() {
Expand Down Expand Up @@ -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_);
Expand Down Expand Up @@ -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
Expand All @@ -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() {}

Expand Down
15 changes: 3 additions & 12 deletions printing/printed_document.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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_;
Expand All @@ -151,7 +142,7 @@ class PRINTING_EXPORT PrintedDocument
// construction.
struct Immutable {
Immutable(const PrintSettings& settings,
PrintedPagesSource* source,
const base::string16& name,
int cookie);
~Immutable();

Expand Down
1 change: 0 additions & 1 deletion printing/printed_document_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
24 changes: 0 additions & 24 deletions printing/printed_pages_source.h

This file was deleted.

0 comments on commit ccceef0

Please sign in to comment.