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/privet_http_server.h" | 5 #include "cloud_print/gcp20/prototype/privet_http_server.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "net/base/ip_endpoint.h" | 10 #include "net/base/ip_endpoint.h" |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 std::string error_description; | 295 std::string error_description; |
296 | 296 |
297 LocalPrintJob::CreateResult result = | 297 LocalPrintJob::CreateResult result = |
298 delegate_->CreateJob(body, &job_id, &expires_in, | 298 delegate_->CreateJob(body, &job_id, &expires_in, |
299 &error_timeout, &error_description); | 299 &error_timeout, &error_description); |
300 | 300 |
301 scoped_ptr<base::DictionaryValue> response; | 301 scoped_ptr<base::DictionaryValue> response; |
302 *status_code = net::HTTP_OK; | 302 *status_code = net::HTTP_OK; |
303 switch (result) { | 303 switch (result) { |
304 case LocalPrintJob::CREATE_SUCCESS: | 304 case LocalPrintJob::CREATE_SUCCESS: |
305 response.reset(new DictionaryValue); | 305 response.reset(new base::DictionaryValue); |
306 response->SetString("job_id", job_id); | 306 response->SetString("job_id", job_id); |
307 response->SetInteger("expires_in", expires_in); | 307 response->SetInteger("expires_in", expires_in); |
308 return response.Pass(); | 308 return response.Pass(); |
309 | 309 |
310 case LocalPrintJob::CREATE_INVALID_TICKET: | 310 case LocalPrintJob::CREATE_INVALID_TICKET: |
311 return CreateError("invalid_ticket"); | 311 return CreateError("invalid_ticket"); |
312 case LocalPrintJob::CREATE_PRINTER_BUSY: | 312 case LocalPrintJob::CREATE_PRINTER_BUSY: |
313 return CreateErrorWithTimeout("printer_busy", error_timeout); | 313 return CreateErrorWithTimeout("printer_busy", error_timeout); |
314 case LocalPrintJob::CREATE_PRINTER_ERROR: | 314 case LocalPrintJob::CREATE_PRINTER_ERROR: |
315 return CreateErrorWithDescription("printer_error", error_description); | 315 return CreateErrorWithDescription("printer_error", error_description); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 std::string error_description; | 347 std::string error_description; |
348 int timeout; | 348 int timeout; |
349 LocalPrintJob::SaveResult status = job_id_present | 349 LocalPrintJob::SaveResult status = job_id_present |
350 ? delegate_->SubmitDocWithId(job, job_id, &expires_in, | 350 ? delegate_->SubmitDocWithId(job, job_id, &expires_in, |
351 &error_description, &timeout) | 351 &error_description, &timeout) |
352 : delegate_->SubmitDoc(job, &job_id, &expires_in, | 352 : delegate_->SubmitDoc(job, &job_id, &expires_in, |
353 &error_description, &timeout); | 353 &error_description, &timeout); |
354 | 354 |
355 // Create response | 355 // Create response |
356 *status_code = net::HTTP_OK; | 356 *status_code = net::HTTP_OK; |
357 scoped_ptr<base::DictionaryValue> response(new DictionaryValue); | 357 scoped_ptr<base::DictionaryValue> response(new base::DictionaryValue); |
358 switch (status) { | 358 switch (status) { |
359 case LocalPrintJob::SAVE_SUCCESS: | 359 case LocalPrintJob::SAVE_SUCCESS: |
360 response->SetString("job_id", job_id); | 360 response->SetString("job_id", job_id); |
361 response->SetInteger("expires_in", expires_in); | 361 response->SetInteger("expires_in", expires_in); |
362 response->SetString("job_type", job.content_type); | 362 response->SetString("job_type", job.content_type); |
363 response->SetString( | 363 response->SetString( |
364 "job_size", | 364 "job_size", |
365 base::StringPrintf("%u", static_cast<uint32>(job.content.size()))); | 365 base::StringPrintf("%u", static_cast<uint32>(job.content.size()))); |
366 if (job_name_present) | 366 if (job_name_present) |
367 response->SetString("job_name", job.job_name); | 367 response->SetString("job_name", job.job_name); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 } | 415 } |
416 | 416 |
417 std::string action; | 417 std::string action; |
418 std::string user; | 418 std::string user; |
419 bool params_present = | 419 bool params_present = |
420 net::GetValueForKeyInQuery(url, "action", &action) && | 420 net::GetValueForKeyInQuery(url, "action", &action) && |
421 net::GetValueForKeyInQuery(url, "user", &user) && | 421 net::GetValueForKeyInQuery(url, "user", &user) && |
422 !user.empty(); | 422 !user.empty(); |
423 | 423 |
424 RegistrationErrorStatus status = REG_ERROR_INVALID_PARAMS; | 424 RegistrationErrorStatus status = REG_ERROR_INVALID_PARAMS; |
425 scoped_ptr<base::DictionaryValue> response(new DictionaryValue); | 425 scoped_ptr<base::DictionaryValue> response(new base::DictionaryValue); |
426 | 426 |
427 if (params_present) { | 427 if (params_present) { |
428 response->SetString("action", action); | 428 response->SetString("action", action); |
429 response->SetString("user", user); | 429 response->SetString("user", user); |
430 | 430 |
431 if (action == "start") | 431 if (action == "start") |
432 status = delegate_->RegistrationStart(user); | 432 status = delegate_->RegistrationStart(user); |
433 | 433 |
434 if (action == "getClaimToken") { | 434 if (action == "getClaimToken") { |
435 std::string token; | 435 std::string token; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 delegate_->GetRegistrationServerError(&description); | 494 delegate_->GetRegistrationServerError(&description); |
495 *current_response = CreateErrorWithDescription("server_error", | 495 *current_response = CreateErrorWithDescription("server_error", |
496 description); | 496 description); |
497 break; | 497 break; |
498 } | 498 } |
499 | 499 |
500 default: | 500 default: |
501 NOTREACHED(); | 501 NOTREACHED(); |
502 }; | 502 }; |
503 } | 503 } |
OLD | NEW |