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 bc2742b0bf5812a59d466b982a9b23d536c785ec..66bcd850f6cad04b8304fd4ef830843932b3f015 100644 |
--- a/cloud_print/gcp20/prototype/cloud_print_response_parser.cc |
+++ b/cloud_print/gcp20/prototype/cloud_print_response_parser.cc |
@@ -197,7 +197,78 @@ bool ParseFetchResponse(const std::string& response, |
} |
*list = job_list; |
+ return true; |
+} |
+ |
+bool ParseLocalSettingsResponse(const std::string& response, |
+ std::string* error_description, |
+ LocalSettings::State* state, |
+ LocalSettings* settings) { |
+ scoped_ptr<base::Value> json(base::JSONReader::Read(response)); |
+ base::DictionaryValue* response_dictionary = NULL; |
+ bool json_success; |
+ std::string message; |
+ if (!GetJsonDictinaryAndCheckSuccess(json.get(), error_description, |
+ &json_success, &message, |
+ &response_dictionary)) { |
+ return false; |
+ } |
+ |
+ if (!json_success) { // Let's suppose our printer was deleted. |
+ *state = LocalSettings::PRINTER_DELETED; |
+ return true; |
+ } |
+ |
+ base::ListValue* list = NULL; |
+ if (!response_dictionary->GetList("printers", &list)) { |
+ *error_description = "No printers list specified."; |
+ return false; |
+ } |
+ |
+ base::DictionaryValue* printer = NULL; |
+ if (!list->GetDictionary(0, &printer)) { |
+ *error_description = "Printers list is empty or printer is not dictionary."; |
+ return false; |
+ } |
+ |
+ base::DictionaryValue* local_settings_dict = NULL; |
+ if (!printer->GetDictionary("local_settings", &local_settings_dict)) { |
+ *error_description = "No local_settings found."; |
+ return false; |
+ } |
+ |
+ base::DictionaryValue* current = NULL; |
+ if (!local_settings_dict->GetDictionary("current", ¤t)) { |
+ *error_description = "No *current* local settings found."; |
+ return false; |
+ } |
+ |
+ LocalSettings::State settings_state; |
+ base::DictionaryValue* pending = NULL; |
+ base::DictionaryValue* settings_to_parse = NULL; |
+ if (local_settings_dict->GetDictionary("pending", &pending)) { |
+ settings_to_parse = pending; |
+ settings_state = LocalSettings::PENDING; |
+ } else { |
+ settings_to_parse = current; |
+ settings_state = LocalSettings::CURRENT; |
+ } |
+ |
+ LocalSettings local_settings; |
+ if (!settings_to_parse->GetBoolean("local_discovery", |
+ &local_settings.local_discovery) || |
+ !settings_to_parse->GetBoolean("access_token_enabled", |
+ &local_settings.access_token_enabled) || |
+ !settings_to_parse->GetBoolean("printer/local_printing_enabled", |
+ &local_settings.local_printing_enabled) || |
+ !settings_to_parse->GetInteger("xmpp_timeout_value", |
+ &local_settings.xmpp_timeout_value)) { |
+ *error_description = "Cannot parse local_settings info."; |
+ return false; |
+ } |
+ *state = settings_state; |
+ *settings = local_settings; |
return true; |
} |