| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "google_apis/gaia/google_service_auth_error.h" | 5 #include "google_apis/gaia/google_service_auth_error.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> |
| 8 | 9 |
| 9 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| 10 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/ptr_util.h" |
| 11 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 12 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 13 #include "base/values.h" | 15 #include "base/values.h" |
| 14 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
| 15 | 17 |
| 16 GoogleServiceAuthError::Captcha::Captcha() : image_width(0), image_height(0) { | 18 GoogleServiceAuthError::Captcha::Captcha() : image_width(0), image_height(0) { |
| 17 } | 19 } |
| 18 | 20 |
| 19 GoogleServiceAuthError::Captcha::Captcha( | 21 GoogleServiceAuthError::Captcha::Captcha( |
| 20 const std::string& token, const GURL& audio, const GURL& img, | 22 const std::string& token, const GURL& audio, const GURL& img, |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 #undef STATE_CASE | 192 #undef STATE_CASE |
| 191 default: | 193 default: |
| 192 NOTREACHED(); | 194 NOTREACHED(); |
| 193 break; | 195 break; |
| 194 } | 196 } |
| 195 value->SetString("state", state_str); | 197 value->SetString("state", state_str); |
| 196 if (!error_message_.empty()) { | 198 if (!error_message_.empty()) { |
| 197 value->SetString("errorMessage", error_message_); | 199 value->SetString("errorMessage", error_message_); |
| 198 } | 200 } |
| 199 if (state_ == CAPTCHA_REQUIRED) { | 201 if (state_ == CAPTCHA_REQUIRED) { |
| 200 base::DictionaryValue* captcha_value = new base::DictionaryValue(); | 202 auto captcha_value = base::MakeUnique<base::DictionaryValue>(); |
| 201 value->Set("captcha", captcha_value); | |
| 202 captcha_value->SetString("token", captcha_.token); | 203 captcha_value->SetString("token", captcha_.token); |
| 203 captcha_value->SetString("audioUrl", captcha_.audio_url.spec()); | 204 captcha_value->SetString("audioUrl", captcha_.audio_url.spec()); |
| 204 captcha_value->SetString("imageUrl", captcha_.image_url.spec()); | 205 captcha_value->SetString("imageUrl", captcha_.image_url.spec()); |
| 205 captcha_value->SetString("unlockUrl", captcha_.unlock_url.spec()); | 206 captcha_value->SetString("unlockUrl", captcha_.unlock_url.spec()); |
| 206 captcha_value->SetInteger("imageWidth", captcha_.image_width); | 207 captcha_value->SetInteger("imageWidth", captcha_.image_width); |
| 207 captcha_value->SetInteger("imageHeight", captcha_.image_height); | 208 captcha_value->SetInteger("imageHeight", captcha_.image_height); |
| 209 value->Set("captcha", std::move(captcha_value)); |
| 208 } else if (state_ == CONNECTION_FAILED) { | 210 } else if (state_ == CONNECTION_FAILED) { |
| 209 value->SetString("networkError", net::ErrorToString(network_error_)); | 211 value->SetString("networkError", net::ErrorToString(network_error_)); |
| 210 } else if (state_ == TWO_FACTOR) { | 212 } else if (state_ == TWO_FACTOR) { |
| 211 base::DictionaryValue* two_factor_value = new base::DictionaryValue(); | 213 auto two_factor_value = base::MakeUnique<base::DictionaryValue>(); |
| 212 value->Set("two_factor", two_factor_value); | |
| 213 two_factor_value->SetString("token", second_factor_.token); | 214 two_factor_value->SetString("token", second_factor_.token); |
| 214 two_factor_value->SetString("promptText", second_factor_.prompt_text); | 215 two_factor_value->SetString("promptText", second_factor_.prompt_text); |
| 215 two_factor_value->SetString("alternateText", second_factor_.alternate_text); | 216 two_factor_value->SetString("alternateText", second_factor_.alternate_text); |
| 216 two_factor_value->SetInteger("fieldLength", second_factor_.field_length); | 217 two_factor_value->SetInteger("fieldLength", second_factor_.field_length); |
| 218 value->Set("two_factor", std::move(two_factor_value)); |
| 217 } | 219 } |
| 218 return value; | 220 return value; |
| 219 } | 221 } |
| 220 | 222 |
| 221 std::string GoogleServiceAuthError::ToString() const { | 223 std::string GoogleServiceAuthError::ToString() const { |
| 222 switch (state_) { | 224 switch (state_) { |
| 223 case NONE: | 225 case NONE: |
| 224 return std::string(); | 226 return std::string(); |
| 225 case INVALID_GAIA_CREDENTIALS: | 227 case INVALID_GAIA_CREDENTIALS: |
| 226 return "Invalid credentials."; | 228 return "Invalid credentials."; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 const GURL& captcha_audio_url, | 289 const GURL& captcha_audio_url, |
| 288 const GURL& captcha_image_url, | 290 const GURL& captcha_image_url, |
| 289 const GURL& captcha_unlock_url, | 291 const GURL& captcha_unlock_url, |
| 290 int image_width, | 292 int image_width, |
| 291 int image_height) | 293 int image_height) |
| 292 : state_(s), | 294 : state_(s), |
| 293 captcha_(captcha_token, captcha_audio_url, captcha_image_url, | 295 captcha_(captcha_token, captcha_audio_url, captcha_image_url, |
| 294 captcha_unlock_url, image_width, image_height), | 296 captcha_unlock_url, image_width, image_height), |
| 295 network_error_(0) { | 297 network_error_(0) { |
| 296 } | 298 } |
| OLD | NEW |