Skip to content

Commit 8ec6fd0

Browse files
committed
sync upstream code
1 parent fbefe51 commit 8ec6fd0

34 files changed

+3070
-1057
lines changed

nw.gypi

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,8 @@
258258
'src/browser/printing/printer_query.h',
259259
'src/browser/printing/print_view_manager.cc',
260260
'src/browser/printing/print_view_manager.h',
261+
'src/browser/printing/print_view_manager_base.cc',
262+
'src/browser/printing/print_view_manager_base.h',
261263
'src/browser/shell_application_mac.h',
262264
'src/browser/shell_application_mac.mm',
263265
'src/browser/shell_devtools_delegate.cc',
@@ -468,6 +470,15 @@
468470
'sources': [
469471
'src/browser/color_chooser_dialog.cc',
470472
'src/browser/color_chooser_dialog.h',
473+
'src/browser/printing_handler.cc',
474+
'src/browser/printing_handler.h',
475+
'src/browser/shell_content_utility_client.cc',
476+
'src/browser/shell_content_utility_client.h',
477+
'<(DEPTH)/chrome/browser/printing/pdf_to_emf_converter.cc',
478+
'<(DEPTH)/chrome/utility/cloud_print/bitmap_image.cc',
479+
'<(DEPTH)/chrome/utility/cloud_print/bitmap_image.h',
480+
'<(DEPTH)/chrome/utility/cloud_print/pwg_encoder.cc',
481+
'<(DEPTH)/chrome/utility/cloud_print/pwg_encoder.h',
471482
],
472483
'resource_include_dirs': [
473484
'<(SHARED_INTERMEDIATE_DIR)/webkit',
@@ -816,6 +827,7 @@
816827
'dependencies': [
817828
'nw_lib',
818829
'nw_pak',
830+
'<(DEPTH)/pdf/pdf.gyp:pdf',
819831
],
820832
'include_dirs': [
821833
'<(DEPTH)',

src/browser/printing/print_job.cc

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@
1010
#include "base/threading/thread_restrictions.h"
1111
#include "base/threading/worker_pool.h"
1212
#include "base/timer/timer.h"
13+
#include "chrome/browser/chrome_notification_types.h"
14+
#include "chrome/browser/printing/print_job_worker.h"
1315
#include "content/public/browser/browser_thread.h"
14-
#include "content/nw/src/browser/printing/print_job_worker.h"
15-
#include "content/public/browser/notification_types.h"
1616
#include "content/public/browser/notification_service.h"
1717
#include "printing/printed_document.h"
1818
#include "printing/printed_page.h"
1919

2020
using base::TimeDelta;
21-
using base::MessageLoop;
2221

2322
namespace {
2423

@@ -33,7 +32,7 @@ void HoldRefCallback(const scoped_refptr<printing::PrintJobWorkerOwner>& owner,
3332
namespace printing {
3433

3534
PrintJob::PrintJob()
36-
: ui_message_loop_(MessageLoop::current()),
35+
: ui_message_loop_(base::MessageLoop::current()),
3736
source_(NULL),
3837
worker_(),
3938
settings_(),
@@ -43,8 +42,8 @@ PrintJob::PrintJob()
4342
DCHECK(ui_message_loop_);
4443
// This is normally a UI message loop, but in unit tests, the message loop is
4544
// of the 'default' type.
46-
DCHECK(ui_message_loop_->type() == MessageLoop::TYPE_UI ||
47-
ui_message_loop_->type() == MessageLoop::TYPE_DEFAULT);
45+
DCHECK(base::MessageLoopForUI::IsCurrent() ||
46+
ui_message_loop_->type() == base::MessageLoop::TYPE_DEFAULT);
4847
ui_message_loop_->AddDestructionObserver(this);
4948
}
5049

@@ -55,7 +54,7 @@ PrintJob::~PrintJob() {
5554
DCHECK(!is_canceling_);
5655
if (worker_.get())
5756
DCHECK(worker_->message_loop() == NULL);
58-
DCHECK_EQ(ui_message_loop_, MessageLoop::current());
57+
DCHECK_EQ(ui_message_loop_, base::MessageLoop::current());
5958
}
6059

6160
void PrintJob::Initialize(PrintJobWorkerOwner* job,
@@ -71,22 +70,24 @@ void PrintJob::Initialize(PrintJobWorkerOwner* job,
7170
settings_ = job->settings();
7271

7372
PrintedDocument* new_doc =
74-
new PrintedDocument(settings_, source_, job->cookie(),
75-
content::BrowserThread::GetBlockingPool());
73+
new PrintedDocument(settings_,
74+
source_,
75+
job->cookie(),
76+
content::BrowserThread::GetBlockingPool());
7677
new_doc->set_page_count(page_count);
7778
UpdatePrintedDocument(new_doc);
7879

7980
// Don't forget to register to our own messages.
80-
registrar_.Add(this, content::NOTIFICATION_PRINT_JOB_EVENT,
81+
registrar_.Add(this, chrome::NOTIFICATION_PRINT_JOB_EVENT,
8182
content::Source<PrintJob>(this));
8283
}
8384

8485
void PrintJob::Observe(int type,
8586
const content::NotificationSource& source,
8687
const content::NotificationDetails& details) {
87-
DCHECK_EQ(ui_message_loop_, MessageLoop::current());
88+
DCHECK_EQ(ui_message_loop_, base::MessageLoop::current());
8889
switch (type) {
89-
case content::NOTIFICATION_PRINT_JOB_EVENT: {
90+
case chrome::NOTIFICATION_PRINT_JOB_EVENT: {
9091
OnNotifyPrintJobEvent(*content::Details<JobEventDetails>(details).ptr());
9192
break;
9293
}
@@ -106,7 +107,7 @@ PrintJobWorker* PrintJob::DetachWorker(PrintJobWorkerOwner* new_owner) {
106107
return NULL;
107108
}
108109

109-
MessageLoop* PrintJob::message_loop() {
110+
base::MessageLoop* PrintJob::message_loop() {
110111
return ui_message_loop_;
111112
}
112113

@@ -126,7 +127,7 @@ void PrintJob::WillDestroyCurrentMessageLoop() {
126127
}
127128

128129
void PrintJob::StartPrinting() {
129-
DCHECK_EQ(ui_message_loop_, MessageLoop::current());
130+
DCHECK_EQ(ui_message_loop_, base::MessageLoop::current());
130131
DCHECK(worker_->message_loop());
131132
DCHECK(!is_job_pending_);
132133
if (!worker_->message_loop() || is_job_pending_)
@@ -145,13 +146,13 @@ void PrintJob::StartPrinting() {
145146
scoped_refptr<JobEventDetails> details(
146147
new JobEventDetails(JobEventDetails::NEW_DOC, document_.get(), NULL));
147148
content::NotificationService::current()->Notify(
148-
content::NOTIFICATION_PRINT_JOB_EVENT,
149+
chrome::NOTIFICATION_PRINT_JOB_EVENT,
149150
content::Source<PrintJob>(this),
150151
content::Details<JobEventDetails>(details.get()));
151152
}
152153

153154
void PrintJob::Stop() {
154-
DCHECK_EQ(ui_message_loop_, MessageLoop::current());
155+
DCHECK_EQ(ui_message_loop_, base::MessageLoop::current());
155156

156157
if (quit_factory_.HasWeakPtrs()) {
157158
// In case we're running a nested message loop to wait for a job to finish,
@@ -179,8 +180,9 @@ void PrintJob::Cancel() {
179180
// Be sure to live long enough.
180181
scoped_refptr<PrintJob> handle(this);
181182

182-
DCHECK_EQ(ui_message_loop_, MessageLoop::current());
183-
MessageLoop* worker_loop = worker_.get() ? worker_->message_loop() : NULL;
183+
DCHECK_EQ(ui_message_loop_, base::MessageLoop::current());
184+
base::MessageLoop* worker_loop =
185+
worker_.get() ? worker_->message_loop() : NULL;
184186
if (worker_loop) {
185187
// Call this right now so it renders the context invalid. Do not use
186188
// InvokeLater since it would take too much time.
@@ -190,7 +192,7 @@ void PrintJob::Cancel() {
190192
scoped_refptr<JobEventDetails> details(
191193
new JobEventDetails(JobEventDetails::FAILED, NULL, NULL));
192194
content::NotificationService::current()->Notify(
193-
content::NOTIFICATION_PRINT_JOB_EVENT,
195+
chrome::NOTIFICATION_PRINT_JOB_EVENT,
194196
content::Source<PrintJob>(this),
195197
content::Details<JobEventDetails>(details.get()));
196198
Stop();
@@ -201,11 +203,12 @@ bool PrintJob::FlushJob(base::TimeDelta timeout) {
201203
// Make sure the object outlive this message loop.
202204
scoped_refptr<PrintJob> handle(this);
203205

204-
MessageLoop::current()->PostDelayedTask(FROM_HERE,
206+
base::MessageLoop::current()->PostDelayedTask(FROM_HERE,
205207
base::Bind(&PrintJob::Quit, quit_factory_.GetWeakPtr()), timeout);
206208

207-
MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current());
208-
MessageLoop::current()->Run();
209+
base::MessageLoop::ScopedNestableTaskAllower allow(
210+
base::MessageLoop::current());
211+
base::MessageLoop::current()->Run();
209212

210213
return true;
211214
}
@@ -269,7 +272,7 @@ void PrintJob::OnNotifyPrintJobEvent(const JobEventDetails& event_details) {
269272
}
270273
case JobEventDetails::DOC_DONE: {
271274
// This will call Stop() and broadcast a JOB_DONE message.
272-
MessageLoop::current()->PostTask(
275+
base::MessageLoop::current()->PostTask(
273276
FROM_HERE, base::Bind(&PrintJob::OnDocumentDone, this));
274277
break;
275278
}
@@ -291,13 +294,13 @@ void PrintJob::OnDocumentDone() {
291294
scoped_refptr<JobEventDetails> details(
292295
new JobEventDetails(JobEventDetails::JOB_DONE, document_.get(), NULL));
293296
content::NotificationService::current()->Notify(
294-
content::NOTIFICATION_PRINT_JOB_EVENT,
297+
chrome::NOTIFICATION_PRINT_JOB_EVENT,
295298
content::Source<PrintJob>(this),
296299
content::Details<JobEventDetails>(details.get()));
297300
}
298301

299302
void PrintJob::ControlledWorkerShutdown() {
300-
DCHECK_EQ(ui_message_loop_, MessageLoop::current());
303+
DCHECK_EQ(ui_message_loop_, base::MessageLoop::current());
301304

302305
// The deadlock this code works around is specific to window messaging on
303306
// Windows, so we aren't likely to need it on any other platforms.
@@ -342,7 +345,7 @@ void PrintJob::HoldUntilStopIsCalled() {
342345
}
343346

344347
void PrintJob::Quit() {
345-
MessageLoop::current()->Quit();
348+
base::MessageLoop::current()->Quit();
346349
}
347350

348351
// Takes settings_ ownership and will be deleted in the receiving thread.

src/browser/printing/print_job.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class PrintJobWorker;
2727
class PrinterQuery;
2828

2929
// Manages the print work for a specific document. Talks to the printer through
30-
// PrintingContext though PrintJob::Worker. Hides access to PrintingContext in a
30+
// PrintingContext through PrintJobWorker. Hides access to PrintingContext in a
3131
// worker thread so the caller never blocks. PrintJob will send notifications on
3232
// any state change. While printing, the PrintJobManager instance keeps a
3333
// reference to the job to be sure it is kept alive. All the code in this class

src/browser/printing/print_job_manager.cc

Lines changed: 84 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,80 +2,124 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
#include "content/nw/src/browser/printing/print_job_manager.h"
5+
#include "chrome/browser/printing/print_job_manager.h"
66

7-
#include "content/nw/src/browser/printing/print_job.h"
8-
#include "content/nw/src/browser/printing/printer_query.h"
9-
#include "content/public/browser/notification_types.h"
7+
#include "chrome/browser/chrome_notification_types.h"
8+
#include "chrome/browser/printing/print_job.h"
9+
#include "chrome/browser/printing/printer_query.h"
10+
#include "content/public/browser/browser_thread.h"
1011
#include "content/public/browser/notification_service.h"
1112
#include "printing/printed_document.h"
1213
#include "printing/printed_page.h"
1314

1415
namespace printing {
1516

16-
PrintJobManager::PrintJobManager() {
17-
registrar_.Add(this, content::NOTIFICATION_PRINT_JOB_EVENT,
18-
content::NotificationService::AllSources());
17+
PrintQueriesQueue::PrintQueriesQueue() {
1918
}
2019

21-
PrintJobManager::~PrintJobManager() {
20+
PrintQueriesQueue::~PrintQueriesQueue() {
2221
base::AutoLock lock(lock_);
2322
queued_queries_.clear();
2423
}
2524

26-
void PrintJobManager::OnQuit() {
27-
StopJobs(true);
28-
registrar_.RemoveAll();
29-
}
30-
31-
void PrintJobManager::StopJobs(bool wait_for_finish) {
32-
// Copy the array since it can be modified in transit.
33-
PrintJobs to_stop;
34-
to_stop.swap(current_jobs_);
35-
36-
for (PrintJobs::const_iterator job = to_stop.begin(); job != to_stop.end();
37-
++job) {
38-
// Wait for two minutes for the print job to be spooled.
39-
if (wait_for_finish)
40-
(*job)->FlushJob(base::TimeDelta::FromMinutes(2));
41-
(*job)->Stop();
42-
}
43-
}
44-
45-
void PrintJobManager::SetPrintDestination(
46-
PrintDestinationInterface* destination) {
25+
void PrintQueriesQueue::SetDestination(PrintDestinationInterface* destination) {
26+
base::AutoLock lock(lock_);
4727
destination_ = destination;
4828
}
4929

50-
void PrintJobManager::QueuePrinterQuery(PrinterQuery* job) {
30+
void PrintQueriesQueue::QueuePrinterQuery(PrinterQuery* job) {
5131
base::AutoLock lock(lock_);
5232
DCHECK(job);
5333
queued_queries_.push_back(make_scoped_refptr(job));
5434
DCHECK(job->is_valid());
5535
}
5636

57-
void PrintJobManager::PopPrinterQuery(int document_cookie,
58-
scoped_refptr<PrinterQuery>* job) {
37+
scoped_refptr<PrinterQuery> PrintQueriesQueue::PopPrinterQuery(
38+
int document_cookie) {
5939
base::AutoLock lock(lock_);
6040
for (PrinterQueries::iterator itr = queued_queries_.begin();
61-
itr != queued_queries_.end();
62-
++itr) {
63-
PrinterQuery* current_query = *itr;
64-
if (current_query->cookie() == document_cookie &&
65-
!current_query->is_callback_pending()) {
66-
*job = current_query;
41+
itr != queued_queries_.end(); ++itr) {
42+
if ((*itr)->cookie() == document_cookie && !(*itr)->is_callback_pending()) {
43+
scoped_refptr<printing::PrinterQuery> current_query(*itr);
6744
queued_queries_.erase(itr);
6845
DCHECK(current_query->is_valid());
69-
return;
46+
return current_query;
7047
}
7148
}
49+
return NULL;
50+
}
51+
52+
scoped_refptr<PrinterQuery> PrintQueriesQueue::CreatePrinterQuery() {
53+
scoped_refptr<PrinterQuery> job = new printing::PrinterQuery;
54+
base::AutoLock lock(lock_);
55+
job->SetWorkerDestination(destination_);
56+
return job;
57+
}
58+
59+
void PrintQueriesQueue::Shutdown() {
60+
PrinterQueries queries_to_stop;
61+
{
62+
base::AutoLock lock(lock_);
63+
queued_queries_.swap(queries_to_stop);
64+
destination_ = NULL;
65+
}
66+
// Stop all pending queries, requests to generate print preview do not have
67+
// corresponding PrintJob, so any pending preview requests are not covered
68+
// by PrintJobManager::StopJobs and should be stopped explicitly.
69+
for (PrinterQueries::iterator itr = queries_to_stop.begin();
70+
itr != queries_to_stop.end(); ++itr) {
71+
(*itr)->message_loop()->PostTask(
72+
FROM_HERE, base::Bind(&PrinterQuery::StopWorker, *itr));
73+
}
74+
}
75+
76+
PrintJobManager::PrintJobManager() : is_shutdown_(false) {
77+
registrar_.Add(this, chrome::NOTIFICATION_PRINT_JOB_EVENT,
78+
content::NotificationService::AllSources());
79+
}
80+
81+
PrintJobManager::~PrintJobManager() {
82+
}
83+
84+
scoped_refptr<PrintQueriesQueue> PrintJobManager::queue() {
85+
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
86+
if (!queue_)
87+
queue_ = new PrintQueriesQueue();
88+
return queue_;
89+
}
90+
91+
void PrintJobManager::Shutdown() {
92+
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
93+
DCHECK(!is_shutdown_);
94+
is_shutdown_ = true;
95+
registrar_.RemoveAll();
96+
StopJobs(true);
97+
if (queue_)
98+
queue_->Shutdown();
99+
queue_ = NULL;
100+
}
101+
102+
void PrintJobManager::StopJobs(bool wait_for_finish) {
103+
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
104+
// Copy the array since it can be modified in transit.
105+
PrintJobs to_stop;
106+
to_stop.swap(current_jobs_);
107+
108+
for (PrintJobs::const_iterator job = to_stop.begin(); job != to_stop.end();
109+
++job) {
110+
// Wait for two minutes for the print job to be spooled.
111+
if (wait_for_finish)
112+
(*job)->FlushJob(base::TimeDelta::FromMinutes(2));
113+
(*job)->Stop();
114+
}
72115
}
73116

74117
void PrintJobManager::Observe(int type,
75118
const content::NotificationSource& source,
76119
const content::NotificationDetails& details) {
120+
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
77121
switch (type) {
78-
case content::NOTIFICATION_PRINT_JOB_EVENT: {
122+
case chrome::NOTIFICATION_PRINT_JOB_EVENT: {
79123
OnPrintJobEvent(content::Source<PrintJob>(source).ptr(),
80124
*content::Details<JobEventDetails>(details).ptr());
81125
break;

0 commit comments

Comments
 (0)