Skip to content

Commit

Permalink
Printer registration using CDD.
Browse files Browse the repository at this point in the history
The code is not enabled yet.

BUG=317027

Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=249967

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@249995 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
vitalybuka@chromium.org committed Feb 9, 2014
1 parent bdf2d43 commit 07021fc
Show file tree
Hide file tree
Showing 8 changed files with 204 additions and 22 deletions.
31 changes: 15 additions & 16 deletions chrome/chrome.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,7 @@
'common',
'common_net',
'../base/base.gyp:base',
'../components/components.gyp:cloud_devices',
'../google_apis/google_apis.gyp:google_apis',
'../jingle/jingle.gyp:notifier',
'../net/net.gyp:net',
Expand All @@ -1037,25 +1038,18 @@
'sources': [
'service/chrome_service_application_mac.h',
'service/chrome_service_application_mac.mm',
'service/service_ipc_server.cc',
'service/service_ipc_server.h',
'service/service_main.cc',
'service/service_process.cc',
'service/service_process.h',
'service/service_process_prefs.cc',
'service/service_process_prefs.h',
'service/service_utility_process_host.cc',
'service/service_utility_process_host.h',
'service/cloud_print/cdd_conversion_win.cc',
'service/cloud_print/cdd_conversion_win.h',
'service/cloud_print/cloud_print_auth.cc',
'service/cloud_print/cloud_print_auth.h',
'service/cloud_print/cloud_print_connector.cc',
'service/cloud_print/cloud_print_connector.h',
'service/cloud_print/cloud_print_service_helpers.cc',
'service/cloud_print/cloud_print_service_helpers.h',
'service/cloud_print/cloud_print_proxy.cc',
'service/cloud_print/cloud_print_proxy.h',
'service/cloud_print/cloud_print_proxy_backend.cc',
'service/cloud_print/cloud_print_proxy_backend.h',
'service/cloud_print/cloud_print_service_helpers.cc',
'service/cloud_print/cloud_print_service_helpers.h',
'service/cloud_print/cloud_print_token_store.cc',
'service/cloud_print/cloud_print_token_store.h',
'service/cloud_print/cloud_print_url_fetcher.cc',
Expand All @@ -1068,22 +1062,27 @@
'service/cloud_print/job_status_updater.h',
'service/cloud_print/print_system.cc',
'service/cloud_print/print_system.h',
'service/cloud_print/print_system_win.cc',
'service/cloud_print/printer_job_handler.cc',
'service/cloud_print/printer_job_handler.h',
'service/cloud_print/printer_job_queue_handler.cc',
'service/cloud_print/printer_job_queue_handler.h',
'service/net/service_url_request_context.cc',
'service/net/service_url_request_context.h',
'service/service_ipc_server.cc',
'service/service_ipc_server.h',
'service/service_main.cc',
'service/service_process.cc',
'service/service_process.h',
'service/service_process_prefs.cc',
'service/service_process_prefs.h',
'service/service_utility_process_host.cc',
'service/service_utility_process_host.h',
],
'include_dirs': [
'..',
],
'conditions': [
['OS=="win"', {
'sources': [
'service/cloud_print/print_system_win.cc',
],
}],
['toolkit_uses_gtk == 1', {
'dependencies': [
'../build/linux/system.gyp:gtk',
Expand Down
1 change: 1 addition & 0 deletions chrome/service/cloud_print/DEPS
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include_rules = [
"+components/cloud_devices",
# sync notifier depends on the common jingle notifier classes.
"+jingle/notifier",
]
113 changes: 113 additions & 0 deletions chrome/service/cloud_print/cdd_conversion_win.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// Copyright 2014 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.

#include "chrome/service/cloud_print/cdd_conversion_win.h"

#include "components/cloud_devices/printer_description.h"
#include "printing/backend/print_backend.h"
#include "printing/backend/win_helper.h"

namespace cloud_print {

std::string CapabilitiesToCdd(
const printing::PrinterSemanticCapsAndDefaults& semantic_info) {
using namespace cloud_devices::printer;
cloud_devices::CloudDeviceDescription description;

ContentTypesCapability content_types;
content_types.AddOption("application/pdf");
content_types.SaveTo(&description);

ColorCapability color;
if (semantic_info.color_default || semantic_info.color_changeable) {
color.AddDefaultOption(Color(STANDARD_COLOR), semantic_info.color_default);
}

if (!semantic_info.color_default || semantic_info.color_changeable) {
color.AddDefaultOption(Color(STANDARD_MONOCHROME),
!semantic_info.color_default);
}
color.SaveTo(&description);

if (semantic_info.duplex_capable) {
DuplexCapability duplex;
duplex.AddDefaultOption(
NO_DUPLEX, semantic_info.duplex_default == printing::SIMPLEX);
duplex.AddDefaultOption(
LONG_EDGE, semantic_info.duplex_default == printing::LONG_EDGE);
duplex.AddDefaultOption(
SHORT_EDGE, semantic_info.duplex_default == printing::SHORT_EDGE);
duplex.SaveTo(&description);
}

if (!semantic_info.papers.empty()) {
Media default_media(semantic_info.default_paper.name,
semantic_info.default_paper.size_um.width(),
semantic_info.default_paper.size_um.height());
default_media.MatchBySize();

MediaCapability media;
bool is_default_set = false;
for (size_t i = 0; i < semantic_info.papers.size(); ++i) {
gfx::Size paper_size = semantic_info.papers[i].size_um;
if (paper_size.width() > paper_size.height())
paper_size.SetSize(paper_size.height(), paper_size.width());
Media new_media(semantic_info.papers[i].name, paper_size.width(),
paper_size.height());
new_media.MatchBySize();
if (new_media.IsValid() && !media.Contains(new_media)) {
if (!default_media.IsValid())
default_media = new_media;
media.AddDefaultOption(new_media, new_media == default_media);
is_default_set = is_default_set || (new_media == default_media);
}
}
if (!is_default_set && default_media.IsValid())
media.AddDefaultOption(default_media, true);

if (media.IsValid()) {
media.SaveTo(&description);
} else {
NOTREACHED();
}
}

if (semantic_info.collate_capable) {
CollateCapability collate;
collate.set_default_value(semantic_info.collate_default);
collate.SaveTo(&description);
}

if (semantic_info.copies_capable) {
CopiesCapability copies;
copies.SaveTo(&description);
}

if (!semantic_info.dpis.empty()) {
DpiCapability dpi;
Dpi default_dpi(semantic_info.default_dpi.width(),
semantic_info.default_dpi.height());
bool is_default_set = false;
for (size_t i = 0; i < semantic_info.dpis.size(); ++i) {
Dpi new_dpi(semantic_info.dpis[i].width(),
semantic_info.dpis[i].height());
if (new_dpi.IsValid() && !dpi.Contains(new_dpi)) {
if (!default_dpi.IsValid())
default_dpi = new_dpi;
dpi.AddDefaultOption(new_dpi, new_dpi == default_dpi);
is_default_set = is_default_set || (new_dpi == default_dpi);
}
}
if (!is_default_set && default_dpi.IsValid())
dpi.AddDefaultOption(default_dpi, true);
if (dpi.IsValid()) {
dpi.SaveTo(&description);
} else {
NOTREACHED();
}
}
return description.ToString();
}

} // namespace cloud_print
21 changes: 21 additions & 0 deletions chrome/service/cloud_print/cdd_conversion_win.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2014 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 CHROME_SERVICE_CLOUD_PRINT_CDD_CONVERSION_WIN_H_
#define CHROME_SERVICE_CLOUD_PRINT_CDD_CONVERSION_WIN_H_

#include <string>

namespace printing {
struct PrinterSemanticCapsAndDefaults;
}

namespace cloud_print {

std::string CapabilitiesToCdd(
const printing::PrinterSemanticCapsAndDefaults& semantic_info);

} // namespace cloud_print

#endif // CHROME_SERVICE_CLOUD_PRINT_CDD_CONVERSION_WIN_H_
4 changes: 4 additions & 0 deletions chrome/service/cloud_print/cloud_print_connector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,10 @@ void CloudPrintConnector::OnReceivePrinterCaps(
settings_.xmpp_ping_timeout_sec()),
mime_boundary, std::string(), &post_data);
post_data += GetPostDataForPrinterInfo(info, mime_boundary);
if (caps_and_defaults.caps_mime_type == kContentTypeCDD) {
net::AddMultipartValueForUpload(kUseCDD, "true", mime_boundary,
std::string(), &post_data);
}
net::AddMultipartValueForUpload(kPrinterCapsValue,
caps_and_defaults.printer_capabilities, mime_boundary,
caps_and_defaults.caps_mime_type, &post_data);
Expand Down
44 changes: 41 additions & 3 deletions chrome/service/cloud_print/print_system_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "base/win/scoped_hdc.h"
#include "chrome/common/cloud_print/cloud_print_constants.h"
#include "chrome/common/crash_keys.h"
#include "chrome/service/cloud_print/cdd_conversion_win.h"
#include "chrome/service/service_process.h"
#include "chrome/service/service_utility_process_host.h"
#include "grit/generated_resources.h"
Expand Down Expand Up @@ -620,15 +621,35 @@ class PrinterCapsHandler : public ServiceUtilityProcessHost::Client {
Release();
}

void Start() {
virtual void OnGetPrinterSemanticCapsAndDefaults(
bool succeeded,
const std::string& printer_name,
const printing::PrinterSemanticCapsAndDefaults& semantic_info) OVERRIDE {
printing::PrinterCapsAndDefaults printer_info;
if (succeeded) {
printer_info.caps_mime_type = kContentTypeCDD;
printer_info.printer_capabilities = CapabilitiesToCdd(semantic_info);
}
callback_.Run(succeeded, printer_name, printer_info);
callback_.Reset();
Release();
}

void StartGetPrinterCapsAndDefaults() {
g_service_process->io_thread()->message_loop_proxy()->PostTask(
FROM_HERE,
base::Bind(&PrinterCapsHandler::GetPrinterCapsAndDefaultsImpl, this,
base::MessageLoopProxy::current()));
}

void StartGetPrinterSemanticCapsAndDefaults() {
g_service_process->io_thread()->message_loop_proxy()->PostTask(
FROM_HERE,
base::Bind(&PrinterCapsHandler::GetPrinterSemanticCapsAndDefaultsImpl,
this, base::MessageLoopProxy::current()));
}

private:
// Called on the service process IO thread.
void GetPrinterCapsAndDefaultsImpl(
const scoped_refptr<base::MessageLoopProxy>&
client_message_loop_proxy) {
Expand All @@ -646,6 +667,23 @@ class PrinterCapsHandler : public ServiceUtilityProcessHost::Client {
}
}

void GetPrinterSemanticCapsAndDefaultsImpl(
const scoped_refptr<base::MessageLoopProxy>&
client_message_loop_proxy) {
DCHECK(g_service_process->io_thread()->message_loop_proxy()->
BelongsToCurrentThread());
scoped_ptr<ServiceUtilityProcessHost> utility_host(
new ServiceUtilityProcessHost(this, client_message_loop_proxy));
if (utility_host->StartGetPrinterSemanticCapsAndDefaults(printer_name_)) {
// The object will self-destruct when the child process dies.
utility_host.release();
} else {
client_message_loop_proxy->PostTask(
FROM_HERE,
base::Bind(&PrinterCapsHandler::OnChildDied, this));
}
}

std::string printer_name_;
PrintSystem::PrinterCapsAndDefaultsCallback callback_;
};
Expand Down Expand Up @@ -714,7 +752,7 @@ void PrintSystemWin::GetPrinterCapsAndDefaults(
PrinterCapsHandler* handler =
new PrinterCapsHandler(printer_name, callback);
handler->AddRef();
handler->Start();
handler->StartGetPrinterCapsAndDefaults();
}

bool PrintSystemWin::IsValidPrinter(const std::string& printer_name) {
Expand Down
4 changes: 4 additions & 0 deletions chrome/service/cloud_print/printer_job_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,10 @@ void PrinterJobHandler::OnReceivePrinterCaps(
// Hashes don't match, we need to upload new capabilities (the defaults
// go for free along with the capabilities)
printer_info_cloud_.caps_hash = caps_hash;
if (caps_and_defaults.caps_mime_type == kContentTypeCDD) {
net::AddMultipartValueForUpload(kUseCDD, "true", mime_boundary,
std::string(), &post_data);
}
net::AddMultipartValueForUpload(kPrinterCapsValue,
caps_and_defaults.printer_capabilities, mime_boundary,
caps_and_defaults.caps_mime_type, &post_data);
Expand Down
8 changes: 5 additions & 3 deletions components/cloud_devices/printer_description.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,15 @@ const int32 kMmToUm = 1000;
const int32 kSizeTrasholdUm = 1000;

#define MAP_CLOUD_PRINT_MEDIA_TYPE(type, width, height, unit_um) \
{ type, #type, width*unit_um, height*unit_um }
{ type, #type, \
static_cast<int>(width * unit_um + 0.5), \
static_cast<int>(height * unit_um + 0.5) }

const struct MadiaDefinition {
MediaType id;
const char* const json_name;
int32 width_um;
int32 height_um;
int width_um;
int height_um;
} kMediaDefinitions[] = {
{ CUSTOM_MEDIA, "CUSTOM" , 0, 0},
MAP_CLOUD_PRINT_MEDIA_TYPE(NA_INDEX_3X5, 3, 5, kInchToUm),
Expand Down

0 comments on commit 07021fc

Please sign in to comment.