summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvitalybuka@chromium.org <vitalybuka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-21 19:34:54 +0000
committervitalybuka@chromium.org <vitalybuka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-21 19:34:54 +0000
commit72ca2f71ab6843b124383ab7b81f4da4bd702c03 (patch)
treebe42a0538027379e9a3d42a43dd0c26667965423
parentfcfdc8ed97e82d1ea87b7f4b8c7cd21092e2fa66 (diff)
downloadchromium_src-72ca2f71ab6843b124383ab7b81f4da4bd702c03.zip
chromium_src-72ca2f71ab6843b124383ab7b81f4da4bd702c03.tar.gz
chromium_src-72ca2f71ab6843b124383ab7b81f4da4bd702c03.tar.bz2
Improvements in GCP 2.0 prototype.
Fixed path to store print jobs, path format was not compatible with windows. CDD updated with more capabilities. Save/Load CDD to state file to allow manual edits. Review URL: https://codereview.chromium.org/78713008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@236571 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--cloud_print/gcp20/prototype/print_job_handler.cc37
-rw-r--r--cloud_print/gcp20/prototype/print_job_handler.h1
-rw-r--r--cloud_print/gcp20/prototype/printer.cc166
-rw-r--r--cloud_print/gcp20/prototype/printer.h7
-rw-r--r--cloud_print/gcp20/prototype/printer_state.cc10
-rw-r--r--cloud_print/gcp20/prototype/printer_state.h5
-rw-r--r--cloud_print/gcp20/prototype/printer_unittest.cc3
-rw-r--r--cloud_print/gcp20/prototype/privet_http_server.cc3
-rw-r--r--cloud_print/gcp20/prototype/privet_http_server.h2
-rw-r--r--tools/gritsettings/resource_ids9
10 files changed, 141 insertions, 102 deletions
diff --git a/cloud_print/gcp20/prototype/print_job_handler.cc b/cloud_print/gcp20/prototype/print_job_handler.cc
index 5666143..8f457e1 100644
--- a/cloud_print/gcp20/prototype/print_job_handler.cc
+++ b/cloud_print/gcp20/prototype/print_job_handler.cc
@@ -153,9 +153,6 @@ LocalPrintJob::SaveResult PrintJobHandler::CompleteLocalPrintJob(
return LocalPrintJob::SAVE_INVALID_PRINT_JOB;
}
- std::string suffix = StringPrintf("%s:%s",
- job.user_name.c_str(),
- job.client_name.c_str());
std::string file_extension;
// TODO(maksymb): Gather together this type checking with Printer
// supported types in kCdd.
@@ -177,7 +174,6 @@ LocalPrintJob::SaveResult PrintJobHandler::CompleteLocalPrintJob(
current_job->second.ticket,
base::Time::Now(),
StringPrintf("%s", job_id.c_str()),
- suffix,
current_job->second.data.job_name, file_extension)) {
SetJobState(job_id, LocalPrintJob::STATE_ABORTED);
*error_description_out = "IO error";
@@ -214,9 +210,6 @@ bool PrintJobHandler::SavePrintJob(const std::string& content,
const std::string& ticket,
const base::Time& create_time,
const std::string& id,
- const std::string& job_name_suffix,
- // suffix is not extension
- // it may be used to mark local printer jobs
const std::string& title,
const std::string& file_extension) {
VLOG(1) << "Printing printjob: \"" + title + "\"";
@@ -224,29 +217,21 @@ bool PrintJobHandler::SavePrintJob(const std::string& content,
if (!base::DirectoryExists(directory) &&
!file_util::CreateDirectory(directory)) {
- LOG(WARNING) << "Cannot create directory: " << directory.value();
return false;
}
base::Time::Exploded create_time_exploded;
create_time.UTCExplode(&create_time_exploded);
- std::string job_name =
- StringPrintf("%.4d%.2d%.2d-%.2d:%.2d:%.2d-%.3dms.%s",
- create_time_exploded.year,
- create_time_exploded.month,
- create_time_exploded.day_of_month,
- create_time_exploded.hour,
- create_time_exploded.minute,
- create_time_exploded.second,
- create_time_exploded.millisecond,
- id.c_str());
- if (!job_name_suffix.empty())
- job_name += "." + job_name_suffix;
- directory = directory.AppendASCII(job_name);
-
- if (!base::DirectoryExists(directory) &&
- !file_util::CreateDirectory(directory)) {
- LOG(WARNING) << "Cannot create directory: " << directory.value();
+ base::FilePath::StringType job_prefix =
+ StringPrintf(FILE_PATH_LITERAL("%.4d%.2d%.2d-%.2d%.2d%.2d_"),
+ create_time_exploded.year,
+ create_time_exploded.month,
+ create_time_exploded.day_of_month,
+ create_time_exploded.hour,
+ create_time_exploded.minute,
+ create_time_exploded.second);
+ if (!file_util::CreateTemporaryDirInDir(directory, job_prefix, &directory)) {
+ LOG(WARNING) << "Cannot create directory for " << job_prefix;
return false;
}
@@ -266,7 +251,7 @@ bool PrintJobHandler::SavePrintJob(const std::string& content,
return false;
}
- LOG(INFO) << "Saved printjob: " << job_name << ": " << title;
+ LOG(INFO) << "Job saved at " << directory.value();
return true;
}
diff --git a/cloud_print/gcp20/prototype/print_job_handler.h b/cloud_print/gcp20/prototype/print_job_handler.h
index 61c043a..1156803 100644
--- a/cloud_print/gcp20/prototype/print_job_handler.h
+++ b/cloud_print/gcp20/prototype/print_job_handler.h
@@ -58,7 +58,6 @@ class PrintJobHandler : public base::SupportsWeakPtr<PrintJobHandler> {
const std::string& ticket,
const base::Time& create_time,
const std::string& id,
- const std::string& job_name_suffix,
const std::string& title,
const std::string& file_extension);
diff --git a/cloud_print/gcp20/prototype/printer.cc b/cloud_print/gcp20/prototype/printer.cc
index 11b4f41..cafb446 100644
--- a/cloud_print/gcp20/prototype/printer.cc
+++ b/cloud_print/gcp20/prototype/printer.cc
@@ -16,6 +16,7 @@
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/strings/string_number_conversions.h"
+#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "cloud_print/gcp20/prototype/command_line_reader.h"
#include "cloud_print/gcp20/prototype/local_settings.h"
@@ -49,60 +50,88 @@ const int kReconnectTimeout = 5; // in seconds
const double kTimeToNextAccessTokenUpdate = 0.8; // relatively to living time.
const char kCdd[] =
-"{\n"
-" \"version\": \"1.0\",\n"
-" \"printer\": {\n"
-" \"supported_content_type\": [\n"
-" {\n"
-" \"content_type\": \"application/pdf\"\n"
-" },\n"
-" {\n"
-" \"content_type\": \"image/pwg-raster\"\n"
-" },\n"
-" {\n"
-" \"content_type\": \"image/jpeg\"\n"
-" }\n"
-" ],\n"
-" \"color\": {\n"
-" \"option\": [\n"
-" {\n"
-" \"is_default\": true,\n"
-" \"type\": \"STANDARD_COLOR\",\n"
-" \"vendor_id\": \"CMYK\"\n"
-" },\n"
-" {\n"
-" \"is_default\": false,\n"
-" \"type\": \"STANDARD_MONOCHROME\",\n"
-" \"vendor_id\": \"Gray\"\n"
-" }\n"
-" ]\n"
-" },\n"
-" \"vendor_capability\": [\n"
-" {\n"
-" \"id\": \"psk:MediaType\",\n"
-" \"display_name\": \"Media Type\",\n"
-" \"type\": \"SELECT\",\n"
-" \"select_cap\": {\n"
-" \"option\": [\n"
-" {\n"
-" \"value\": \"psk:Plain\",\n"
-" \"display_name\": \"Plain Paper\",\n"
-" \"is_default\": true\n"
-" },\n"
-" {\n"
-" \"value\": \"ns0000:Glossy\",\n"
-" \"display_name\": \"Glossy Photo\",\n"
-" \"is_default\": false\n"
-" }\n"
-" ]\n"
-" }\n"
-" }\n"
-" ],\n"
-" \"reverse_order\": {\n"
-" \"default\": false\n"
-" }\n"
-" }\n"
-"}\n";
+"{"
+" 'version': '1.0',"
+" 'printer': {"
+" 'supported_content_type': ["
+" {"
+" 'content_type': 'application/pdf'"
+" },"
+" {"
+" 'content_type': 'image/pwg-raster'"
+" },"
+" {"
+" 'content_type': 'image/jpeg'"
+" }"
+" ],"
+" 'color': {"
+" 'option': ["
+" {"
+" 'is_default': true,"
+" 'type': 'STANDARD_COLOR',"
+" 'vendor_id': 'CMYK'"
+" },"
+" {"
+" 'is_default': false,"
+" 'type': 'STANDARD_MONOCHROME',"
+" 'vendor_id': 'Gray'"
+" }"
+" ]"
+" },"
+" 'dpi': {"
+" 'option': [ {"
+" 'horizontal_dpi': 300,"
+" 'is_default': true,"
+" 'vertical_dpi': 300"
+" }, {"
+" 'horizontal_dpi': 600,"
+" 'is_default': false,"
+" 'vertical_dpi': 600"
+" } ]"
+" },"
+" 'duplex': {"
+" 'option': [ {"
+" 'is_default': true,"
+" 'type': 'NO_DUPLEX'"
+" }, {"
+" 'is_default': false,"
+" 'type': 'SHORT_EDGE'"
+" }, {"
+" 'is_default': false,"
+" 'type': 'LONG_EDGE'"
+" } ]"
+" },"
+" 'media_size': {"
+" 'option': [ {"
+" 'custom_display_name': 'A4',"
+" 'height_microns': 297000,"
+" 'is_continuous_feed': false,"
+" 'is_default': false,"
+" 'name': 'A4',"
+" 'width_microns': 210000"
+" }, {"
+" 'custom_display_name': 'Letter',"
+" 'height_microns': 279400,"
+" 'is_continuous_feed': false,"
+" 'is_default': true,"
+" 'name': 'LETTER',"
+" 'width_microns': 215900"
+" } ]"
+" },"
+" 'page_orientation': {"
+" 'option': [ {"
+" 'is_default': true,"
+" 'type': 'PORTRAIT'"
+" }, {"
+" 'is_default': false,"
+" 'type': 'LANDSCAPE'"
+" } ]"
+" },"
+" 'reverse_order': {"
+" 'default': false"
+" }"
+" }"
+"}";
// Returns local IP address number of first interface found (except loopback).
// Return value is empty if no interface found. Possible interfaces names are
@@ -189,7 +218,11 @@ void Printer::Stop() {
}
std::string Printer::GetRawCdd() {
- return kCdd;
+ std::string json_str;
+ base::JSONWriter::WriteWithOptions(&GetCapabilities(),
+ base::JSONWriter::OPTIONS_PRETTY_PRINT,
+ &json_str);
+ return json_str;
}
void Printer::OnAuthError() {
@@ -239,7 +272,7 @@ PrivetHttpServer::RegistrationErrorStatus Printer::RegistrationStart(
}
requester_->StartRegistration(GenerateProxyId(), kPrinterName, user,
- state_.local_settings, kCdd);
+ state_.local_settings, GetRawCdd());
return PrivetHttpServer::REG_ERROR_OK;
}
@@ -377,11 +410,16 @@ bool Printer::CheckXPrivetTokenHeader(const std::string& token) const {
return xtoken_.CheckValidXToken(token);
}
-scoped_ptr<base::DictionaryValue> Printer::GetCapabilities() {
- scoped_ptr<base::Value> value(base::JSONReader::Read(kCdd));
- base::DictionaryValue* dictionary_value = NULL;
- value->GetAsDictionary(&dictionary_value);
- return scoped_ptr<base::DictionaryValue>(dictionary_value->DeepCopy());
+const base::DictionaryValue& Printer::GetCapabilities() {
+ if (!state_.cdd.get()) {
+ std::string cdd_string;
+ ReplaceChars(kCdd, "'", "\"", &cdd_string);
+ scoped_ptr<base::Value> json_val(base::JSONReader::Read(cdd_string));
+ base::DictionaryValue* json = NULL;
+ CHECK(json_val->GetAsDictionary(&json));
+ state_.cdd.reset(json->DeepCopy());
+ }
+ return *state_.cdd;
}
LocalPrintJob::CreateResult Printer::CreateJob(const std::string& ticket,
@@ -494,7 +532,7 @@ void Printer::OnPrintJobsAvailable(const std::vector<Job>& jobs) {
void Printer::OnPrintJobDownloaded(const Job& job) {
VLOG(3) << "Function: " << __FUNCTION__;
print_job_handler_->SavePrintJob(job.file, job.ticket, job.create_time,
- job.job_id, "remote", job.title, "pdf");
+ job.job_id, job.title, "pdf");
requester_->SendPrintJobDone(job.job_id);
}
@@ -746,7 +784,8 @@ std::vector<std::string> Printer::CreateTxt() const {
return txt;
}
-void Printer::SaveToFile() const {
+void Printer::SaveToFile() {
+ GetCapabilities(); // Make sure capabilities created.
base::FilePath file_path;
file_path = file_path.AppendASCII(
command_line_reader::ReadStatePath(kPrinterStatePathDefault));
@@ -772,6 +811,7 @@ bool Printer::LoadFromFile() {
if (printer_state::LoadFromFile(file_path, &state_)) {
LOG(INFO) << "Printer state loaded from file";
+ SaveToFile();
} else {
LOG(INFO) << "Reading/parsing printer state from file failed";
}
diff --git a/cloud_print/gcp20/prototype/printer.h b/cloud_print/gcp20/prototype/printer.h
index 69e8874..ab999b3 100644
--- a/cloud_print/gcp20/prototype/printer.h
+++ b/cloud_print/gcp20/prototype/printer.h
@@ -51,8 +51,7 @@ class Printer : public base::SupportsWeakPtr<Printer>,
CONNECTING
};
- // For testing purposes.
- static std::string GetRawCdd();
+ std::string GetRawCdd();
// PrivetHttpServer::Delegate methods:
virtual PrivetHttpServer::RegistrationErrorStatus RegistrationStart(
@@ -71,7 +70,7 @@ class Printer : public base::SupportsWeakPtr<Printer>,
virtual bool IsRegistered() const OVERRIDE;
virtual bool IsLocalPrintingAllowed() const OVERRIDE;
virtual bool CheckXPrivetTokenHeader(const std::string& token) const OVERRIDE;
- virtual scoped_ptr<base::DictionaryValue> GetCapabilities() OVERRIDE;
+ virtual const base::DictionaryValue& GetCapabilities() OVERRIDE;
virtual LocalPrintJob::CreateResult CreateJob(
const std::string& ticket,
std::string* job_id,
@@ -173,7 +172,7 @@ class Printer : public base::SupportsWeakPtr<Printer>,
std::vector<std::string> CreateTxt() const;
// Saving and loading registration info from file.
- void SaveToFile() const;
+ void SaveToFile();
bool LoadFromFile();
// Adds |OnIdle| method to the MessageLoop.
diff --git a/cloud_print/gcp20/prototype/printer_state.cc b/cloud_print/gcp20/prototype/printer_state.cc
index 0c1ab09..156ebe4 100644
--- a/cloud_print/gcp20/prototype/printer_state.cc
+++ b/cloud_print/gcp20/prototype/printer_state.cc
@@ -22,6 +22,7 @@ const char kAccessToken[] = "access_token";
const char kAccessTokenUpdate[] = "access_token_update";
const char kLocalSettings[] = "local_settings";
+const char kCdd[] = "cdd";
const char kLocalSettingsLocalDiscovery[] = "local_discovery";
const char kLocalSettingsAccessTokenEnabled[] = "access_token_enabled";
const char kLocalSettingsLocalPrintingEnabled[] =
@@ -66,6 +67,9 @@ bool SaveToFile(const base::FilePath& path, const PrinterState& state) {
json.SetBoolean(kRegistered, false);
}
+ if (state.cdd.get())
+ json.Set(kCdd, state.cdd->DeepCopy());
+
std::string json_str;
base::JSONWriter::WriteWithOptions(&json,
base::JSONWriter::OPTIONS_PRETTY_PRINT,
@@ -151,6 +155,10 @@ bool LoadFromFile(const base::FilePath& path, PrinterState* state) {
}
}
+ base::DictionaryValue* cdd_dict = NULL;
+ if (!json->GetDictionary(kCdd, &cdd_dict))
+ LOG(WARNING) << "Cannot read |cdd|. Reset to default.";
+
*state = PrinterState();
state->registration_state = PrinterState::REGISTERED;
state->user = user;
@@ -160,6 +168,8 @@ bool LoadFromFile(const base::FilePath& path, PrinterState* state) {
state->access_token = access_token;
state->access_token_update = base::Time::FromTimeT(access_token_update);
state->local_settings = local_settings;
+ if (cdd_dict)
+ state->cdd.reset(cdd_dict->DeepCopy());
return true;
}
diff --git a/cloud_print/gcp20/prototype/printer_state.h b/cloud_print/gcp20/prototype/printer_state.h
index 6ad0554..50638dc 100644
--- a/cloud_print/gcp20/prototype/printer_state.h
+++ b/cloud_print/gcp20/prototype/printer_state.h
@@ -7,13 +7,13 @@
#include <string>
+#include "base/memory/linked_ptr.h"
#include "base/time/time.h"
#include "cloud_print/gcp20/prototype/local_settings.h"
namespace base {
-
+class DictionaryValue;
class FilePath;
-
} // namespace base
struct PrinterState {
@@ -51,6 +51,7 @@ struct PrinterState {
std::string device_id;
std::string xmpp_jid;
LocalSettings local_settings;
+ linked_ptr<base::DictionaryValue> cdd;
// Last valid |access_token|.
std::string access_token;
diff --git a/cloud_print/gcp20/prototype/printer_unittest.cc b/cloud_print/gcp20/prototype/printer_unittest.cc
index afce69b..04205ce 100644
--- a/cloud_print/gcp20/prototype/printer_unittest.cc
+++ b/cloud_print/gcp20/prototype/printer_unittest.cc
@@ -13,8 +13,9 @@
TEST(Printer, ValidateCapabilities) {
int error_code;
std::string error_msg;
+ Printer printer;
scoped_ptr<base::Value> value(
- base::JSONReader::ReadAndReturnError(Printer::GetRawCdd(), 0,
+ base::JSONReader::ReadAndReturnError(printer.GetRawCdd(), 0,
&error_code, &error_msg));
ASSERT_TRUE(!!value) << error_msg;
diff --git a/cloud_print/gcp20/prototype/privet_http_server.cc b/cloud_print/gcp20/prototype/privet_http_server.cc
index 161d7d9..d589657 100644
--- a/cloud_print/gcp20/prototype/privet_http_server.cc
+++ b/cloud_print/gcp20/prototype/privet_http_server.cc
@@ -275,8 +275,7 @@ scoped_ptr<base::DictionaryValue> PrivetHttpServer::ProcessCapabilities(
*status_code = net::HTTP_NOT_FOUND;
return scoped_ptr<base::DictionaryValue>();
}
-
- return delegate_->GetCapabilities();
+ return make_scoped_ptr(delegate_->GetCapabilities().DeepCopy());
}
scoped_ptr<base::DictionaryValue> PrivetHttpServer::ProcessCreateJob(
diff --git a/cloud_print/gcp20/prototype/privet_http_server.h b/cloud_print/gcp20/prototype/privet_http_server.h
index eb082c6..4b22e35 100644
--- a/cloud_print/gcp20/prototype/privet_http_server.h
+++ b/cloud_print/gcp20/prototype/privet_http_server.h
@@ -95,7 +95,7 @@ class PrivetHttpServer: public net::HttpServer::Delegate {
virtual bool CheckXPrivetTokenHeader(const std::string& token) const = 0;
// Invoked for getting capabilities.
- virtual scoped_ptr<base::DictionaryValue> GetCapabilities() = 0;
+ virtual const base::DictionaryValue& GetCapabilities() = 0;
// Invoked for creating a job.
virtual LocalPrintJob::CreateResult CreateJob(
diff --git a/tools/gritsettings/resource_ids b/tools/gritsettings/resource_ids
index 29141fe..2155638 100644
--- a/tools/gritsettings/resource_ids
+++ b/tools/gritsettings/resource_ids
@@ -158,8 +158,13 @@
},
"cloud_print/service/win/service_resources.grd": {
"messages": [23600],
- "includes": [23800],
- "structures": [23900],
+ "includes": [23700],
+ "structures": [23750],
+ },
+ "cloud_print/gcp20/prototype/gcp20_device.grd": {
+ "messages": [23800],
+ "includes": [23830],
+ "structures": [23860],
},
"chrome/browser/resources/quota_internals_resources.grd": {
"includes": [24000],