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

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

Issue 22555003: GCP2.0 Device: Local settings workflow. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 4 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 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", &current)) {
+ *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;
}
« no previous file with comments | « cloud_print/gcp20/prototype/cloud_print_response_parser.h ('k') | cloud_print/gcp20/prototype/cloud_print_xmpp_listener.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698