Skip to content

Commit

Permalink
Added ChromeUtilityMsg_GetPrinterSemanticCapsAndDefaults message and …
Browse files Browse the repository at this point in the history
…handler.

BUG=317027
NOTRY=true

Review URL: https://codereview.chromium.org/155223002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@249554 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
vitalybuka@chromium.org committed Feb 7, 2014
1 parent c1adff7 commit dfca37b
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 2 deletions.
49 changes: 49 additions & 0 deletions chrome/common/chrome_utility_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,35 @@ IPC_STRUCT_TRAITS_BEGIN(printing::PrinterCapsAndDefaults)
IPC_STRUCT_TRAITS_MEMBER(defaults_mime_type)
IPC_STRUCT_TRAITS_END()

IPC_ENUM_TRAITS(printing::DuplexMode)

#if defined(OS_WIN)
IPC_STRUCT_TRAITS_BEGIN(printing::PrinterSemanticCapsAndDefaults::Paper)
IPC_STRUCT_TRAITS_MEMBER(name)
IPC_STRUCT_TRAITS_MEMBER(size_um)
IPC_STRUCT_TRAITS_END()
#endif

IPC_STRUCT_TRAITS_BEGIN(printing::PrinterSemanticCapsAndDefaults)
IPC_STRUCT_TRAITS_MEMBER(color_changeable)
IPC_STRUCT_TRAITS_MEMBER(color_default)
#if defined(USE_CUPS)
IPC_STRUCT_TRAITS_MEMBER(color_model)
IPC_STRUCT_TRAITS_MEMBER(bw_model)
#endif
#if defined(OS_WIN)
IPC_STRUCT_TRAITS_MEMBER(collate_capable)
IPC_STRUCT_TRAITS_MEMBER(collate_default)
IPC_STRUCT_TRAITS_MEMBER(copies_capable)
IPC_STRUCT_TRAITS_MEMBER(papers)
IPC_STRUCT_TRAITS_MEMBER(default_paper)
IPC_STRUCT_TRAITS_MEMBER(dpis)
IPC_STRUCT_TRAITS_MEMBER(default_dpi)
#endif
IPC_STRUCT_TRAITS_MEMBER(duplex_capable)
IPC_STRUCT_TRAITS_MEMBER(duplex_default)
IPC_STRUCT_TRAITS_END()

IPC_STRUCT_TRAITS_BEGIN(UpdateManifest::Result)
IPC_STRUCT_TRAITS_MEMBER(extension_id)
IPC_STRUCT_TRAITS_MEMBER(version)
Expand Down Expand Up @@ -169,6 +198,13 @@ IPC_MESSAGE_CONTROL1(ChromeUtilityMsg_ParseJSON,
IPC_MESSAGE_CONTROL1(ChromeUtilityMsg_GetPrinterCapsAndDefaults,
std::string /* printer name */)

// Tells the utility process to get capabilities and defaults for the specified
// printer. Used on Windows to isolate the service process from printer driver
// crashes by executing this in a separate process. This does not run in a
// sandbox. Returns result as printing::PrinterSemanticCapsAndDefaults.
IPC_MESSAGE_CONTROL1(ChromeUtilityMsg_GetPrinterSemanticCapsAndDefaults,
std::string /* printer name */)

#if defined(OS_CHROMEOS)
// Tell the utility process to create a zip file on the given list of files.
IPC_MESSAGE_CONTROL3(ChromeUtilityMsg_CreateZipFile,
Expand Down Expand Up @@ -317,13 +353,26 @@ IPC_MESSAGE_CONTROL1(ChromeUtilityHostMsg_ParseJSON_Failed,
IPC_MESSAGE_CONTROL2(ChromeUtilityHostMsg_GetPrinterCapsAndDefaults_Succeeded,
std::string /* printer name */,
printing::PrinterCapsAndDefaults)

// Reply when the utility process has succeeded in obtaining the printer
// semantic capabilities and defaults.
IPC_MESSAGE_CONTROL2(
ChromeUtilityHostMsg_GetPrinterSemanticCapsAndDefaults_Succeeded,
std::string /* printer name */,
printing::PrinterSemanticCapsAndDefaults)
#endif

// Reply when the utility process has failed to obtain the printer
// capabilities and defaults.
IPC_MESSAGE_CONTROL1(ChromeUtilityHostMsg_GetPrinterCapsAndDefaults_Failed,
std::string /* printer name */)

// Reply when the utility process has failed to obtain the printer
// semantic capabilities and defaults.
IPC_MESSAGE_CONTROL1(
ChromeUtilityHostMsg_GetPrinterSemanticCapsAndDefaults_Failed,
std::string /* printer name */)

#if defined(OS_CHROMEOS)
// Reply when the utility process has succeeded in creating the zip file.
IPC_MESSAGE_CONTROL0(ChromeUtilityHostMsg_CreateZipFile_Succeeded)
Expand Down
60 changes: 59 additions & 1 deletion chrome/service/service_utility_process_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class ServiceSandboxedProcessLauncherDelegate
using content::ChildProcessHost;

namespace {
enum ServiceUtilityProcessHostEvent {
enum ServiceUtilityProcessHostEvent {
SERVICE_UTILITY_STARTED,
SERVICE_UTILITY_DISCONNECTED,
SERVICE_UTILITY_METAFILE_REQUEST,
Expand All @@ -69,6 +69,9 @@ namespace {
SERVICE_UTILITY_CAPS_REQUEST,
SERVICE_UTILITY_CAPS_SUCCEEDED,
SERVICE_UTILITY_CAPS_FAILED,
SERVICE_UTILITY_SEMANTIC_CAPS_REQUEST,
SERVICE_UTILITY_SEMANTIC_CAPS_SUCCEEDED,
SERVICE_UTILITY_SEMANTIC_CAPS_FAILED,
SERVICE_UTILITY_EVENT_MAX,
};
} // namespace
Expand Down Expand Up @@ -128,6 +131,7 @@ bool ServiceUtilityProcessHost::StartRenderPDFPagesToMetafile(
DUPLICATE_SAME_ACCESS);
if (!pdf_file_in_utility_process)
return false;
DCHECK(!waiting_for_reply_);
waiting_for_reply_ = true;
return child_process_host_->Send(
new ChromeUtilityMsg_RenderPDFPagesToMetafile(
Expand All @@ -147,11 +151,27 @@ bool ServiceUtilityProcessHost::StartGetPrinterCapsAndDefaults(
base::FilePath exposed_path;
if (!StartProcess(true, exposed_path))
return false;
DCHECK(!waiting_for_reply_);
waiting_for_reply_ = true;
return child_process_host_->Send(
new ChromeUtilityMsg_GetPrinterCapsAndDefaults(printer_name));
}

bool ServiceUtilityProcessHost::StartGetPrinterSemanticCapsAndDefaults(
const std::string& printer_name) {
UMA_HISTOGRAM_ENUMERATION("CloudPrint.ServiceUtilityProcessHostEvent",
SERVICE_UTILITY_SEMANTIC_CAPS_REQUEST,
SERVICE_UTILITY_EVENT_MAX);
start_time_ = base::Time::Now();
base::FilePath exposed_path;
if (!StartProcess(true, exposed_path))
return false;
DCHECK(!waiting_for_reply_);
waiting_for_reply_ = true;
return child_process_host_->Send(
new ChromeUtilityMsg_GetPrinterSemanticCapsAndDefaults(printer_name));
}

bool ServiceUtilityProcessHost::StartProcess(
bool no_sandbox,
const base::FilePath& exposed_dir) {
Expand Down Expand Up @@ -237,6 +257,12 @@ bool ServiceUtilityProcessHost::OnMessageReceived(const IPC::Message& message) {
OnGetPrinterCapsAndDefaultsSucceeded)
IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_GetPrinterCapsAndDefaults_Failed,
OnGetPrinterCapsAndDefaultsFailed)
IPC_MESSAGE_HANDLER(
ChromeUtilityHostMsg_GetPrinterSemanticCapsAndDefaults_Succeeded,
OnGetPrinterSemanticCapsAndDefaultsSucceeded)
IPC_MESSAGE_HANDLER(
ChromeUtilityHostMsg_GetPrinterSemanticCapsAndDefaults_Failed,
OnGetPrinterSemanticCapsAndDefaultsFailed)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
Expand Down Expand Up @@ -291,6 +317,22 @@ void ServiceUtilityProcessHost::OnGetPrinterCapsAndDefaultsSucceeded(
printer_name, caps_and_defaults));
}

void ServiceUtilityProcessHost::OnGetPrinterSemanticCapsAndDefaultsSucceeded(
const std::string& printer_name,
const printing::PrinterSemanticCapsAndDefaults& caps_and_defaults) {
DCHECK(waiting_for_reply_);
UMA_HISTOGRAM_ENUMERATION("CloudPrint.ServiceUtilityProcessHostEvent",
SERVICE_UTILITY_SEMANTIC_CAPS_SUCCEEDED,
SERVICE_UTILITY_EVENT_MAX);
UMA_HISTOGRAM_TIMES("CloudPrint.ServiceUtilitySemanticCapsTime",
base::Time::Now() - start_time_);
waiting_for_reply_ = false;
client_message_loop_proxy_->PostTask(
FROM_HERE,
base::Bind(&Client::OnGetPrinterSemanticCapsAndDefaults, client_.get(),
true, printer_name, caps_and_defaults));
}

void ServiceUtilityProcessHost::OnGetPrinterCapsAndDefaultsFailed(
const std::string& printer_name) {
DCHECK(waiting_for_reply_);
Expand All @@ -306,6 +348,22 @@ void ServiceUtilityProcessHost::OnGetPrinterCapsAndDefaultsFailed(
printer_name, printing::PrinterCapsAndDefaults()));
}

void ServiceUtilityProcessHost::OnGetPrinterSemanticCapsAndDefaultsFailed(
const std::string& printer_name) {
DCHECK(waiting_for_reply_);
UMA_HISTOGRAM_ENUMERATION("CloudPrint.ServiceUtilityProcessHostEvent",
SERVICE_UTILITY_SEMANTIC_CAPS_FAILED,
SERVICE_UTILITY_EVENT_MAX);
UMA_HISTOGRAM_TIMES("CloudPrint.ServiceUtilitySemanticCapsFailTime",
base::Time::Now() - start_time_);
waiting_for_reply_ = false;
client_message_loop_proxy_->PostTask(
FROM_HERE,
base::Bind(&Client::OnGetPrinterSemanticCapsAndDefaults,
client_.get(), false, printer_name,
printing::PrinterSemanticCapsAndDefaults()));
}

void ServiceUtilityProcessHost::Client::MetafileAvailable(
const base::FilePath& metafile_path,
int highest_rendered_page_number,
Expand Down
21 changes: 20 additions & 1 deletion chrome/service/service_utility_process_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace printing {
class Emf;
struct PageRange;
struct PrinterCapsAndDefaults;
struct PrinterSemanticCapsAndDefaults;
} // namespace printing

// Acts as the service-side host to a utility child process. A
Expand Down Expand Up @@ -61,12 +62,19 @@ class ServiceUtilityProcessHost : public content::ChildProcessHostDelegate {
virtual void OnRenderPDFPagesToMetafileFailed() {}

// Called when the printer capabilities and defaults have been
// retrieved successfully.
// retrieved successfully or if retrieval failed.
virtual void OnGetPrinterCapsAndDefaults(
bool succedded,
const std::string& printer_name,
const printing::PrinterCapsAndDefaults& caps_and_defaults) {}

// Called when the printer capabilities and defaults have been
// retrieved successfully or if retrieval failed.
virtual void OnGetPrinterSemanticCapsAndDefaults(
bool succedded,
const std::string& printer_name,
const printing::PrinterSemanticCapsAndDefaults& caps_and_defaults) {}

protected:
virtual ~Client() {}

Expand Down Expand Up @@ -100,6 +108,12 @@ class ServiceUtilityProcessHost : public content::ChildProcessHostDelegate {
// in a sandbox.
bool StartGetPrinterCapsAndDefaults(const std::string& printer_name);

// Starts a process to get capabilities and defaults for the specified
// printer. Used on Windows to isolate the service process from printer driver
// crashes by executing this in a separate process. The process does not run
// in a sandbox. Returns result as printing::PrinterSemanticCapsAndDefaults.
bool StartGetPrinterSemanticCapsAndDefaults(const std::string& printer_name);

protected:
// Allows this method to be overridden for tests.
virtual base::FilePath GetUtilityProcessCmd();
Expand Down Expand Up @@ -132,6 +146,11 @@ class ServiceUtilityProcessHost : public content::ChildProcessHostDelegate {
const std::string& printer_name,
const printing::PrinterCapsAndDefaults& caps_and_defaults);
void OnGetPrinterCapsAndDefaultsFailed(const std::string& printer_name);
void OnGetPrinterSemanticCapsAndDefaultsSucceeded(
const std::string& printer_name,
const printing::PrinterSemanticCapsAndDefaults& caps_and_defaults);
void OnGetPrinterSemanticCapsAndDefaultsFailed(
const std::string& printer_name);

scoped_ptr<content::ChildProcessHost> child_process_host_;
base::ProcessHandle handle_;
Expand Down
25 changes: 25 additions & 0 deletions chrome/utility/chrome_content_utility_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@ bool ChromeContentUtilityClient::OnMessageReceived(
IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseJSON, OnParseJSON)
IPC_MESSAGE_HANDLER(ChromeUtilityMsg_GetPrinterCapsAndDefaults,
OnGetPrinterCapsAndDefaults)
IPC_MESSAGE_HANDLER(ChromeUtilityMsg_GetPrinterSemanticCapsAndDefaults,
OnGetPrinterSemanticCapsAndDefaults)
IPC_MESSAGE_HANDLER(ChromeUtilityMsg_StartupPing, OnStartupPing)
IPC_MESSAGE_HANDLER(ChromeUtilityMsg_AnalyzeZipFileForDownloadProtection,
OnAnalyzeZipFileForDownloadProtection)
Expand Down Expand Up @@ -747,6 +749,29 @@ void ChromeContentUtilityClient::OnGetPrinterCapsAndDefaults(
ReleaseProcessIfNeeded();
}

void ChromeContentUtilityClient::OnGetPrinterSemanticCapsAndDefaults(
const std::string& printer_name) {
#if defined(ENABLE_FULL_PRINTING)
scoped_refptr<printing::PrintBackend> print_backend =
printing::PrintBackend::CreateInstance(NULL);
printing::PrinterSemanticCapsAndDefaults printer_info;

crash_keys::ScopedPrinterInfo crash_key(
print_backend->GetPrinterDriverInfo(printer_name));

if (print_backend->GetPrinterSemanticCapsAndDefaults(printer_name,
&printer_info)) {
Send(new ChromeUtilityHostMsg_GetPrinterSemanticCapsAndDefaults_Succeeded(
printer_name, printer_info));
} else // NOLINT
#endif
{
Send(new ChromeUtilityHostMsg_GetPrinterSemanticCapsAndDefaults_Failed(
printer_name));
}
ReleaseProcessIfNeeded();
}

void ChromeContentUtilityClient::OnStartupPing() {
Send(new ChromeUtilityHostMsg_ProcessStarted);
// Don't release the process, we assume further messages are on the way.
Expand Down
1 change: 1 addition & 0 deletions chrome/utility/chrome_content_utility_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class ChromeContentUtilityClient : public content::ContentUtilityClient {
base::PlatformFile bitmap_file);

void OnGetPrinterCapsAndDefaults(const std::string& printer_name);
void OnGetPrinterSemanticCapsAndDefaults(const std::string& printer_name);
void OnStartupPing();
void OnAnalyzeZipFileForDownloadProtection(
const IPC::PlatformFileForTransit& zip_file);
Expand Down

0 comments on commit dfca37b

Please sign in to comment.