OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cloud_print/gcp20/prototype/printer.h" | 5 #include "cloud_print/gcp20/prototype/printer.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 info->model = "Prototype"; | 335 info->model = "Prototype"; |
336 info->serial_number = "2.3.5.7.13.17.19.31.61.89.107.127.521.607.1279.2203"; | 336 info->serial_number = "2.3.5.7.13.17.19.31.61.89.107.127.521.607.1279.2203"; |
337 info->firmware = "3.7.31.127.8191.131071.524287.2147483647"; | 337 info->firmware = "3.7.31.127.8191.131071.524287.2147483647"; |
338 info->uptime = static_cast<int>((base::Time::Now() - starttime_).InSeconds()); | 338 info->uptime = static_cast<int>((base::Time::Now() - starttime_).InSeconds()); |
339 | 339 |
340 info->x_privet_token = xtoken_.GenerateXToken(); | 340 info->x_privet_token = xtoken_.GenerateXToken(); |
341 | 341 |
342 // TODO(maksymb): Create enum for available APIs and replace | 342 // TODO(maksymb): Create enum for available APIs and replace |
343 // this API text names with constants from enum. API text names should be only | 343 // this API text names with constants from enum. API text names should be only |
344 // known in PrivetHttpServer. | 344 // known in PrivetHttpServer. |
345 if (state_.registration_state == PrinterState::UNREGISTERED) { | 345 if (!IsRegistered()) { |
346 info->api.push_back("/privet/register"); | 346 info->api.push_back("/privet/register"); |
347 } else { | 347 } else { |
348 if (IsLocalPrintingAllowed()) | 348 info->api.push_back("/privet/capabilities"); |
| 349 if (IsLocalPrintingAllowed()) { |
| 350 info->api.push_back("/privet/printer/createjob"); |
349 info->api.push_back("/privet/printer/submitdoc"); | 351 info->api.push_back("/privet/printer/submitdoc"); |
350 info->api.push_back("/privet/capabilities"); | 352 info->api.push_back("/privet/printer/jobstate"); |
| 353 } |
351 } | 354 } |
352 | 355 |
353 info->type.push_back("printer"); | 356 info->type.push_back("printer"); |
354 } | 357 } |
355 | 358 |
356 bool Printer::IsRegistered() const { | 359 bool Printer::IsRegistered() const { |
357 return state_.registration_state == PrinterState::REGISTERED; | 360 return state_.registration_state == PrinterState::REGISTERED; |
358 } | 361 } |
359 | 362 |
360 bool Printer::IsLocalPrintingAllowed() const { | 363 bool Printer::IsLocalPrintingAllowed() const { |
361 return state_.local_settings.local_printing_enabled; | 364 return state_.local_settings.local_printing_enabled; |
362 } | 365 } |
363 | 366 |
364 bool Printer::CheckXPrivetTokenHeader(const std::string& token) const { | 367 bool Printer::CheckXPrivetTokenHeader(const std::string& token) const { |
365 return xtoken_.CheckValidXToken(token); | 368 return xtoken_.CheckValidXToken(token); |
366 } | 369 } |
367 | 370 |
368 scoped_ptr<base::DictionaryValue> Printer::GetCapabilities() { | 371 scoped_ptr<base::DictionaryValue> Printer::GetCapabilities() { |
369 scoped_ptr<base::Value> value(base::JSONReader::Read(kCdd)); | 372 scoped_ptr<base::Value> value(base::JSONReader::Read(kCdd)); |
370 base::DictionaryValue* dictionary_value = NULL; | 373 base::DictionaryValue* dictionary_value = NULL; |
371 value->GetAsDictionary(&dictionary_value); | 374 value->GetAsDictionary(&dictionary_value); |
372 return scoped_ptr<base::DictionaryValue>(dictionary_value->DeepCopy()); | 375 return scoped_ptr<base::DictionaryValue>(dictionary_value->DeepCopy()); |
373 } | 376 } |
374 | 377 |
375 void Printer::CreateJob(const std::string& ticket) { | 378 LocalPrintJob::CreateResult Printer::CreateJob(const std::string& ticket, |
376 // TODO(maksymb): Implement advanced printing | 379 std::string* job_id, |
377 NOTIMPLEMENTED(); | 380 int* expires_in, |
| 381 int* error_timeout, |
| 382 std::string* error_description) { |
| 383 return print_job_handler_->CreatePrintJob(ticket, job_id, expires_in, |
| 384 error_timeout, error_description); |
378 } | 385 } |
379 | 386 |
380 LocalPrintJob::SaveResult Printer::SubmitDoc(const LocalPrintJob& job, | 387 LocalPrintJob::SaveResult Printer::SubmitDoc(const LocalPrintJob& job, |
381 std::string* job_id, | 388 std::string* job_id, |
| 389 int* expires_in, |
382 std::string* error_description, | 390 std::string* error_description, |
383 int* timeout) { | 391 int* timeout) { |
384 return print_job_handler_->SaveLocalPrintJob(job, job_id, error_description, | 392 return print_job_handler_->SaveLocalPrintJob(job, job_id, expires_in, |
385 timeout); | 393 error_description, timeout); |
386 } | 394 } |
387 | 395 |
388 void Printer::GetJobStatus(int job_id) { | 396 LocalPrintJob::SaveResult Printer::SubmitDocWithId( |
389 // TODO(maksymb): Implement advanced printing | 397 const LocalPrintJob& job, |
390 NOTIMPLEMENTED(); | 398 const std::string& job_id, |
| 399 int* expires_in, |
| 400 std::string* error_description, |
| 401 int* timeout) { |
| 402 return print_job_handler_->CompleteLocalPrintJob(job, job_id, expires_in, |
| 403 error_description, timeout); |
| 404 } |
| 405 |
| 406 bool Printer::GetJobState(const std::string& id, LocalPrintJob::Info* info) { |
| 407 return print_job_handler_->GetJobState(id, info); |
391 } | 408 } |
392 | 409 |
393 void Printer::OnRegistrationStartResponseParsed( | 410 void Printer::OnRegistrationStartResponseParsed( |
394 const std::string& registration_token, | 411 const std::string& registration_token, |
395 const std::string& complete_invite_url, | 412 const std::string& complete_invite_url, |
396 const std::string& device_id) { | 413 const std::string& device_id) { |
397 state_.registration_state = PrinterState::REGISTRATION_CLAIM_TOKEN_READY; | 414 state_.registration_state = PrinterState::REGISTRATION_CLAIM_TOKEN_READY; |
398 state_.device_id = device_id; | 415 state_.device_id = device_id; |
399 state_.registration_token = registration_token; | 416 state_.registration_token = registration_token; |
400 state_.complete_invite_url = complete_invite_url; | 417 state_.complete_invite_url = complete_invite_url; |
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
888 dns_server_.UpdateMetadata(CreateTxt()); | 905 dns_server_.UpdateMetadata(CreateTxt()); |
889 | 906 |
890 if (connection_state_ == OFFLINE) { | 907 if (connection_state_ == OFFLINE) { |
891 requester_.reset(); | 908 requester_.reset(); |
892 xmpp_listener_.reset(); | 909 xmpp_listener_.reset(); |
893 } | 910 } |
894 | 911 |
895 return true; | 912 return true; |
896 } | 913 } |
897 | 914 |
OLD | NEW |