summaryrefslogtreecommitdiffstats
path: root/cloud_print
diff options
context:
space:
mode:
authormaksymb@chromium.org <maksymb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-02 23:08:44 +0000
committermaksymb@chromium.org <maksymb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-02 23:08:44 +0000
commitc0cf5577044fb84147a0786dd2298c862dc03195 (patch)
tree00e89636e7162a0be098098b3a869813c060b365 /cloud_print
parentcd1acaf40582e67a0ee35aabf10e51c8999ec059 (diff)
downloadchromium_src-c0cf5577044fb84147a0786dd2298c862dc03195.zip
chromium_src-c0cf5577044fb84147a0786dd2298c862dc03195.tar.gz
chromium_src-c0cf5577044fb84147a0786dd2298c862dc03195.tar.bz2
Replaced HTTP-errors with Privet errors.
BUG= Review URL: https://chromiumcodereview.appspot.com/21206004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@215391 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cloud_print')
-rw-r--r--cloud_print/gcp20/prototype/privet_http_server.cc80
-rw-r--r--cloud_print/gcp20/prototype/privet_http_server.h3
2 files changed, 35 insertions, 48 deletions
diff --git a/cloud_print/gcp20/prototype/privet_http_server.cc b/cloud_print/gcp20/prototype/privet_http_server.cc
index 58e35a8..b29b8e3 100644
--- a/cloud_print/gcp20/prototype/privet_http_server.cc
+++ b/cloud_print/gcp20/prototype/privet_http_server.cc
@@ -117,7 +117,7 @@ void PrivetHttpServer::OnHttpRequest(int connection_id,
if (url.path() != "/privet/info" &&
!delegate_->CheckXPrivetTokenHeader(iter->second)) {
- server_->Send(connection_id, net::HTTP_BAD_REQUEST,
+ server_->Send(connection_id, net::HTTP_OK,
"{\"error\":\"invalid_x_privet_token\"}",
"application/json");
return;
@@ -127,7 +127,6 @@ void PrivetHttpServer::OnHttpRequest(int connection_id,
std::string response;
net::HttpStatusCode status_code =
ProcessHttpRequest(url, info.data, &response);
- // TODO(maksymb): Add checking for right |info.method| in query.
server_->Send(connection_id, status_code, response, "application/json");
}
@@ -243,86 +242,75 @@ scoped_ptr<base::DictionaryValue> PrivetHttpServer::ProcessRegister(
}
std::string action;
- if (!net::GetValueForKeyInQuery(url, "action", &action)) {
- *status_code = net::HTTP_BAD_REQUEST;
- return scoped_ptr<base::DictionaryValue>();
- }
-
- // TODO(maksymb): Is there a possibility |user| to be empty?
std::string user;
- if (!net::GetValueForKeyInQuery(url, "user", &user) || user.empty()) {
- *status_code = net::HTTP_BAD_REQUEST;
- return scoped_ptr<base::DictionaryValue>();
- }
+ bool params_present =
+ net::GetValueForKeyInQuery(url, "action", &action) &&
+ net::GetValueForKeyInQuery(url, "user", &user) &&
+ !user.empty();
- RegistrationErrorStatus status = REG_ERROR_NO_RESULT;
+ RegistrationErrorStatus status = REG_ERROR_INVALID_PARAMS;
scoped_ptr<base::DictionaryValue> response(new DictionaryValue);
- response->SetString("action", action);
- response->SetString("user", user);
-
- if (action == "start")
- status = delegate_->RegistrationStart(user);
-
- if (action == "getClaimToken") {
- std::string token;
- std::string claim_url;
- status = delegate_->RegistrationGetClaimToken(user, &token, &claim_url);
- response->SetString("token", token);
- response->SetString("claim_url", claim_url);
- }
- if (action == "complete") {
- std::string device_id;
- status = delegate_->RegistrationComplete(user, &device_id);
- response->SetString("device_id", device_id);
- }
+ if (params_present) {
+ response->SetString("action", action);
+ response->SetString("user", user);
- if (action == "cancel")
- status = delegate_->RegistrationCancel(user);
+ if (action == "start")
+ status = delegate_->RegistrationStart(user);
+
+ if (action == "getClaimToken") {
+ std::string token;
+ std::string claim_url;
+ status = delegate_->RegistrationGetClaimToken(user, &token, &claim_url);
+ response->SetString("token", token);
+ response->SetString("claim_url", claim_url);
+ }
+
+ if (action == "complete") {
+ std::string device_id;
+ status = delegate_->RegistrationComplete(user, &device_id);
+ response->SetString("device_id", device_id);
+ }
+
+ if (action == "cancel")
+ status = delegate_->RegistrationCancel(user);
+ }
if (status != REG_ERROR_OK)
response.reset();
- ProcessRegistrationStatus(status, status_code, &response);
+ ProcessRegistrationStatus(status, &response);
+ *status_code = net::HTTP_OK;
return response.Pass();
}
void PrivetHttpServer::ProcessRegistrationStatus(
RegistrationErrorStatus status,
- net::HttpStatusCode *status_code,
scoped_ptr<base::DictionaryValue>* current_response) const {
switch (status) {
case REG_ERROR_OK:
- *status_code = net::HTTP_OK;
DCHECK(*current_response) << "Response shouldn't be empty.";
break;
- case REG_ERROR_NO_RESULT:
- *status_code = net::HTTP_BAD_REQUEST;
- current_response->reset();
- break;
+ case REG_ERROR_INVALID_PARAMS:
+ *current_response = CreateError("invalid_params");
+ break;
case REG_ERROR_DEVICE_BUSY:
- *status_code = net::HTTP_OK;
*current_response = CreateErrorWithTimeout("device_busy", 30);
break;
case REG_ERROR_PENDING_USER_ACTION:
- *status_code = net::HTTP_OK;
*current_response = CreateErrorWithTimeout("pending_user_action", 30);
break;
case REG_ERROR_USER_CANCEL:
- *status_code = net::HTTP_OK;
*current_response = CreateError("user_cancel");
break;
case REG_ERROR_CONFIRMATION_TIMEOUT:
- *status_code = net::HTTP_OK;
*current_response = CreateError("confirmation_timeout");
break;
case REG_ERROR_INVALID_ACTION:
- *status_code = net::HTTP_OK;
*current_response = CreateError("invalid_action");
break;
case REG_ERROR_SERVER_ERROR: {
- *status_code = net::HTTP_OK;
std::string description;
delegate_->GetRegistrationServerError(&description);
*current_response = CreateErrorWithDescription("server_error",
diff --git a/cloud_print/gcp20/prototype/privet_http_server.h b/cloud_print/gcp20/prototype/privet_http_server.h
index 7c043b0..fc80d90 100644
--- a/cloud_print/gcp20/prototype/privet_http_server.h
+++ b/cloud_print/gcp20/prototype/privet_http_server.h
@@ -22,8 +22,8 @@ class PrivetHttpServer: public net::HttpServer::Delegate {
// TODO(maksymb): Move this enum to some namespace instead of this class.
enum RegistrationErrorStatus {
REG_ERROR_OK,
- REG_ERROR_NO_RESULT, // default value, never set.
+ REG_ERROR_INVALID_PARAMS,
REG_ERROR_DEVICE_BUSY,
REG_ERROR_PENDING_USER_ACTION,
REG_ERROR_USER_CANCEL,
@@ -146,7 +146,6 @@ class PrivetHttpServer: public net::HttpServer::Delegate {
// |current_response| with error or empty response.
void ProcessRegistrationStatus(
RegistrationErrorStatus status,
- net::HttpStatusCode *status_code,
scoped_ptr<base::DictionaryValue>* current_response) const;
// Port for listening.