Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3971)

Unified Diff: chrome/browser/local_discovery/privet_http_impl.cc

Issue 59033010: Initial support for /privet/printer/createjob (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/local_discovery/privet_http_impl.cc
diff --git a/chrome/browser/local_discovery/privet_http_impl.cc b/chrome/browser/local_discovery/privet_http_impl.cc
index 28575a36c7623d1c4901119251403e9935c3d8b4..f312553b9e989c67411fa9290e5b4d07b9d517b8 100644
--- a/chrome/browser/local_discovery/privet_http_impl.cc
+++ b/chrome/browser/local_discovery/privet_http_impl.cc
@@ -25,12 +25,15 @@ const char kPrivetURLValueOffline[] = "1";
const char kPrivetContentTypePDF[] = "application/pdf";
const char kPrivetContentTypePWGRaster[] = "image/pwg-raster";
+const char kPrivetContentTypeCJT[] = "application/json";
const char kPrivetCDDKeySupportedContentTypes[] =
"printer.supported_content_type";
const char kPrivetCDDKeyContentType[] = "content_type";
+const char kPrivetKeyJobID[] = "job_id";
+
const int kPrivetCancelationTimeoutSeconds = 3;
GURL CreatePrivetURL(const std::string& path) {
@@ -365,10 +368,6 @@ PrivetLocalPrintOperationImpl::~PrivetLocalPrintOperationImpl() {
void PrivetLocalPrintOperationImpl::Start() {
DCHECK(!started_);
- current_request_ =
- base::Bind(&PrivetLocalPrintOperationImpl::StartInitialRequest,
- base::Unretained(this));
-
// We need to get the /info response so we can know which APIs are available.
// TODO(noamsml): Use cached info when available.
info_operation_ = privet_client_->CreateInfoOperation(this);
@@ -377,11 +376,6 @@ void PrivetLocalPrintOperationImpl::Start() {
started_ = true;
}
-void PrivetLocalPrintOperationImpl::StartCurrentRequest() {
- DCHECK(!current_request_.is_null());
- current_request_.Run();
-}
-
void PrivetLocalPrintOperationImpl::OnPrivetInfoDone(
PrivetInfoOperation* operation,
int http_code,
@@ -411,7 +405,7 @@ void PrivetLocalPrintOperationImpl::OnPrivetInfoDone(
return;
}
- StartCurrentRequest();
+ StartInitialRequest();
} else {
delegate_->OnPrivetPrintingError(this, http_code);
}
@@ -430,7 +424,7 @@ void PrivetLocalPrintOperationImpl::StartInitialRequest() {
void PrivetLocalPrintOperationImpl::GetCapabilities() {
current_response_ = base::Bind(
- &PrivetLocalPrintOperationImpl::OnCapabilities,
+ &PrivetLocalPrintOperationImpl::OnCapabilitiesResponse,
base::Unretained(this));
url_fetcher_= privet_client_->CreateURLFetcher(
@@ -440,6 +434,18 @@ void PrivetLocalPrintOperationImpl::GetCapabilities() {
url_fetcher_->Start();
}
+void PrivetLocalPrintOperationImpl::DoCreatejob() {
+ current_response_ = base::Bind(
+ &PrivetLocalPrintOperationImpl::OnCreatejobResponse,
+ base::Unretained(this));
+
+ url_fetcher_= privet_client_->CreateURLFetcher(
+ CreatePrivetURL(kPrivetCreatejobPath), net::URLFetcher::POST, this);
+ url_fetcher_->SetUploadData(kPrivetContentTypeCJT, ticket_);
+
+ url_fetcher_->Start();
+}
+
void PrivetLocalPrintOperationImpl::DoSubmitdoc() {
current_response_ = base::Bind(
&PrivetLocalPrintOperationImpl::OnSubmitdocResponse,
@@ -459,6 +465,12 @@ void PrivetLocalPrintOperationImpl::DoSubmitdoc() {
jobname_);
}
+ if (!jobid_.empty()) {
+ url = net::AppendQueryParameter(url,
+ kPrivetKeyJobID,
+ jobid_);
+ }
+
if (offline_) {
url = net::AppendQueryParameter(url,
kPrivetURLKeyOffline,
@@ -476,7 +488,7 @@ void PrivetLocalPrintOperationImpl::DoSubmitdoc() {
url_fetcher_->Start();
}
-void PrivetLocalPrintOperationImpl::OnCapabilities(
+void PrivetLocalPrintOperationImpl::OnCapabilitiesResponse(
const base::DictionaryValue* value) {
const base::ListValue* supported_content_types;
use_pdf_ = false;
@@ -511,6 +523,15 @@ void PrivetLocalPrintOperationImpl::OnSubmitdocResponse(
delegate_->OnPrivetPrintingDone(this);
}
+void PrivetLocalPrintOperationImpl::OnCreatejobResponse(
+ const base::DictionaryValue* value) {
+ // Try to get job ID from value. If not, jobid_ will be empty and we will use
+ // simple printing.
+ value->GetString(kPrivetKeyJobID, &jobid_);
+
+ DoSubmitdoc();
+}
+
PrivetHTTPClient* PrivetLocalPrintOperationImpl::GetHTTPClient() {
return privet_client_;
}
@@ -543,11 +564,12 @@ void PrivetLocalPrintOperationImpl::OnNeedPrivetToken(
void PrivetLocalPrintOperationImpl::SendData(const std::string& data) {
DCHECK(started_);
data_ = data;
- current_request_ = base::Bind(
- &PrivetLocalPrintOperationImpl::DoSubmitdoc,
- base::Unretained(this));
- StartCurrentRequest();
+ if (has_extended_workflow_ && !ticket_.empty()) {
+ DoCreatejob();
+ } else {
+ DoSubmitdoc();
+ }
}
void PrivetLocalPrintOperationImpl::SetTicket(const std::string& ticket) {
« no previous file with comments | « chrome/browser/local_discovery/privet_http_impl.h ('k') | chrome/browser/local_discovery/privet_http_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698