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 | 8 |
9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 | 89 |
90 // static | 90 // static |
91 GoogleServiceAuthError GoogleServiceAuthError::FromClientLoginCaptchaChallenge( | 91 GoogleServiceAuthError GoogleServiceAuthError::FromClientLoginCaptchaChallenge( |
92 const std::string& captcha_token, | 92 const std::string& captcha_token, |
93 const GURL& captcha_image_url, | 93 const GURL& captcha_image_url, |
94 const GURL& captcha_unlock_url) { | 94 const GURL& captcha_unlock_url) { |
95 return GoogleServiceAuthError(CAPTCHA_REQUIRED, captcha_token, GURL(), | 95 return GoogleServiceAuthError(CAPTCHA_REQUIRED, captcha_token, GURL(), |
96 captcha_image_url, captcha_unlock_url, 0, 0); | 96 captcha_image_url, captcha_unlock_url, 0, 0); |
97 } | 97 } |
98 | 98 |
99 // static | |
100 GoogleServiceAuthError GoogleServiceAuthError::FromCaptchaChallenge( | |
101 const std::string& captcha_token, | |
102 const GURL& captcha_audio_url, | |
103 const GURL& captcha_image_url, | |
104 int image_width, | |
105 int image_height) { | |
106 return GoogleServiceAuthError(CAPTCHA_REQUIRED, captcha_token, | |
107 captcha_audio_url, captcha_image_url, | |
108 GURL(), image_width, image_height); | |
109 } | |
110 | |
111 // static | |
112 GoogleServiceAuthError GoogleServiceAuthError::FromSecondFactorChallenge( | |
113 const std::string& captcha_token, | |
114 const std::string& prompt_text, | |
115 const std::string& alternate_text, | |
116 int field_length) { | |
117 return GoogleServiceAuthError(TWO_FACTOR, captcha_token, prompt_text, | |
118 alternate_text, field_length); | |
119 } | |
120 | |
121 // static | |
122 GoogleServiceAuthError GoogleServiceAuthError::FromClientOAuthError( | |
123 const std::string& data) { | |
124 scoped_ptr<base::Value> value(base::JSONReader::Read(data)); | |
125 if (!value.get() || value->GetType() != base::Value::TYPE_DICTIONARY) | |
126 return GoogleServiceAuthError(CONNECTION_FAILED, 0); | |
127 | |
128 DictionaryValue* dict = static_cast<DictionaryValue*>(value.get()); | |
129 | |
130 std::string cause; | |
131 if (!dict->GetStringWithoutPathExpansion("cause", &cause)) | |
132 return GoogleServiceAuthError(CONNECTION_FAILED, 0); | |
133 | |
134 // The explanation field is optional. | |
135 std::string explanation; | |
136 if (!dict->GetStringWithoutPathExpansion("explanation", &explanation)) | |
137 explanation.clear(); | |
138 | |
139 return GoogleServiceAuthError(explanation); | |
140 } | |
141 | |
142 GoogleServiceAuthError GoogleServiceAuthError::AuthErrorNone() { | 99 GoogleServiceAuthError GoogleServiceAuthError::AuthErrorNone() { |
143 return GoogleServiceAuthError(NONE); | 100 return GoogleServiceAuthError(NONE); |
144 } | 101 } |
145 | 102 |
146 GoogleServiceAuthError::State GoogleServiceAuthError::state() const { | 103 GoogleServiceAuthError::State GoogleServiceAuthError::state() const { |
147 return state_; | 104 return state_; |
148 } | 105 } |
149 | 106 |
150 const GoogleServiceAuthError::Captcha& GoogleServiceAuthError::captcha() const { | 107 const GoogleServiceAuthError::Captcha& GoogleServiceAuthError::captcha() const { |
151 return captcha_; | 108 return captcha_; |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 GoogleServiceAuthError::GoogleServiceAuthError( | 233 GoogleServiceAuthError::GoogleServiceAuthError( |
277 State s, | 234 State s, |
278 const std::string& captcha_token, | 235 const std::string& captcha_token, |
279 const std::string& prompt_text, | 236 const std::string& prompt_text, |
280 const std::string& alternate_text, | 237 const std::string& alternate_text, |
281 int field_length) | 238 int field_length) |
282 : state_(s), | 239 : state_(s), |
283 second_factor_(captcha_token, prompt_text, alternate_text, field_length), | 240 second_factor_(captcha_token, prompt_text, alternate_text, field_length), |
284 network_error_(0) { | 241 network_error_(0) { |
285 } | 242 } |
OLD | NEW |