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

Unified Diff: cloud_print/gcp20/prototype/cloud_print_response_parser.cc

Issue 19866002: GCP2.0 Device: Receiving printjobs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@confirmation
Patch Set: Created 7 years, 5 months 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: cloud_print/gcp20/prototype/cloud_print_response_parser.cc
diff --git a/cloud_print/gcp20/prototype/cloud_print_response_parser.cc b/cloud_print/gcp20/prototype/cloud_print_response_parser.cc
index fa2c5f7f83ffd0c95caaa09331becd953b6da3b4..288ceb5d207c25d410834c9b1ec9ff5413a5c29c 100644
--- a/cloud_print/gcp20/prototype/cloud_print_response_parser.cc
+++ b/cloud_print/gcp20/prototype/cloud_print_response_parser.cc
@@ -10,6 +10,12 @@
namespace cloud_print_response_parser {
+Printjob::Printjob() {
+}
+
+Printjob::~Printjob() {
+}
+
// Parses json base::Value to base::DictionaryValue and checks |success| status.
// Returns |true| on success.
bool GetJsonDictinaryAndCheckSuccess(base::Value* json,
@@ -129,5 +135,57 @@ bool ParseRegisterCompleteResponse(const std::string& response,
return true;
}
+bool ParseFetchResponse(const std::string& response,
+ const ErrorCallback error_callback,
+ std::vector<Printjob>* list_result) {
+ scoped_ptr<base::Value> json(base::JSONReader::Read(response));
+ base::DictionaryValue* response_dictionary = NULL;
+
+ if (!json || !json->GetAsDictionary(&response_dictionary)) {
+ error_callback.Run("No JSON dictionary response received.");
+ return false;
+ }
+
+ bool success = false;
+ if (!response_dictionary->GetBoolean("success", &success)) {
+ error_callback.Run("Cannot parse success state.");
+ return false;
+ }
+
+ if (!success) { // Let's suppose we have no jobs to proceed.
+ list_result->clear();
+ return true;
+ }
+
+ if (!GetJsonDictinaryAndCheckSuccess(json.get(), error_callback,
+ &response_dictionary)) {
+ return false;
+ }
+
+ base::ListValue* jobs = NULL;
+ if (!response_dictionary->GetList("jobs", &jobs)) {
+ error_callback.Run("Cannot parse jobs list.");
+ return false;
+ }
+
+ std::vector<Printjob> list(jobs->GetSize());
+ for (size_t idx = 0; idx < list.size(); ++idx) {
+ base::DictionaryValue* job = NULL;
+ jobs->GetDictionary(idx, &job);
+ if (!job->GetString("id", &list[idx].jobid) ||
+ !job->GetString("createTime", &list[idx].create_time) ||
+ !job->GetString("fileUrl", &list[idx].file_url) ||
+ !job->GetString("ticketUrl", &list[idx].ticket_url) ||
+ !job->GetString("title", &list[idx].title)) {
+ error_callback.Run("Cannot parse job info.");
+ return false;
+ }
+ }
+
+ *list_result = list;
+
+ return true;
+}
+
} // namespace cloud_print_response_parser

Powered by Google App Engine
This is Rietveld 408576698