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

Side by Side Diff: chrome/common/net/gaia/google_service_auth_error.h

Issue 3186020: Use a generic error instead of a dcheck. (Closed)
Patch Set: fix include name Created 10 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 // A GoogleServiceAuthError is immutable, plain old data representing an 5 // A GoogleServiceAuthError is immutable, plain old data representing an
6 // error from an attempt to authenticate with a Google service. 6 // error from an attempt to authenticate with a Google service.
7 // It could be from Google Accounts itself, or any service using Google 7 // It could be from Google Accounts itself, or any service using Google
8 // Accounts (e.g expired credentials). It may contain additional data such as 8 // Accounts (e.g expired credentials). It may contain additional data such as
9 // captcha challenges. 9 // captcha challenges.
10 10
11 // A GoogleServiceAuthError without additional data is just a State, defined 11 // A GoogleServiceAuthError without additional data is just a State, defined
12 // below. A case could be made to have this relation implicit, to allow raising 12 // below. A case could be made to have this relation implicit, to allow raising
13 // error events concisely by doing OnAuthError(GoogleServiceAuthError::NONE), 13 // error events concisely by doing OnAuthError(GoogleServiceAuthError::NONE),
14 // for example. But the truth is this class is ever so slightly more than a 14 // for example. But the truth is this class is ever so slightly more than a
15 // transparent wrapper around 'State' due to additional Captcha data 15 // transparent wrapper around 'State' due to additional Captcha data
16 // (e.g consider operator=), and this would violate the style guide. Thus, 16 // (e.g consider operator=), and this would violate the style guide. Thus,
17 // you must explicitly use the constructor when all you have is a State. 17 // you must explicitly use the constructor when all you have is a State.
18 // The good news is the implementation nests the enum inside a class, so you 18 // The good news is the implementation nests the enum inside a class, so you
19 // may forward declare and typedef GoogleServiceAuthError to something shorter 19 // may forward declare and typedef GoogleServiceAuthError to something shorter
20 // in the comfort of your own translation unit. 20 // in the comfort of your own translation unit.
21 21
22 #ifndef CHROME_COMMON_NET_GAIA_GOOGLE_SERVICE_AUTH_ERROR_H_ 22 #ifndef CHROME_COMMON_NET_GAIA_GOOGLE_SERVICE_AUTH_ERROR_H_
23 #define CHROME_COMMON_NET_GAIA_GOOGLE_SERVICE_AUTH_ERROR_H_ 23 #define CHROME_COMMON_NET_GAIA_GOOGLE_SERVICE_AUTH_ERROR_H_
24 #pragma once 24 #pragma once
25 25
26 #include <string> 26 #include <string>
27 #include "base/logging.h" 27 #include "base/logging.h"
28 #include "googleurl/src/gurl.h" 28 #include "googleurl/src/gurl.h"
29 #include "net/base/net_errors.h"
29 30
30 class GoogleServiceAuthError { 31 class GoogleServiceAuthError {
31 public: 32 public:
32 enum State { 33 enum State {
33 // The user is authenticated. 34 // The user is authenticated.
34 NONE = 0, 35 NONE = 0,
35 36
36 // The password is valid but we need two factor to get a token. 37 // The password is valid but we need two factor to get a token.
37 TWO_FACTOR, 38 TWO_FACTOR,
38 39
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 captcha_.token == b.captcha_.token && 77 captcha_.token == b.captcha_.token &&
77 captcha_.image_url == b.captcha_.image_url && 78 captcha_.image_url == b.captcha_.image_url &&
78 captcha_.unlock_url == b.captcha_.unlock_url); 79 captcha_.unlock_url == b.captcha_.unlock_url);
79 } 80 }
80 81
81 // Construct a GoogleServiceAuthError from a State with no additional data. 82 // Construct a GoogleServiceAuthError from a State with no additional data.
82 explicit GoogleServiceAuthError(State s) 83 explicit GoogleServiceAuthError(State s)
83 : state_(s), 84 : state_(s),
84 captcha_("", GURL(), GURL()), 85 captcha_("", GURL(), GURL()),
85 network_error_(0) { 86 network_error_(0) {
86 DCHECK(s != CONNECTION_FAILED); 87 // If the caller has no idea, then we just set it to a generic failure.
88 if (s == CONNECTION_FAILED) {
89 network_error_ = net::ERR_FAILED;
90 }
87 } 91 }
88 92
89 // Construct a GoogleServiceAuthError from a network error. 93 // Construct a GoogleServiceAuthError from a network error.
90 // It will be created with CONNECTION_FAILED set. 94 // It will be created with CONNECTION_FAILED set.
91 static GoogleServiceAuthError FromConnectionError(int error) { 95 static GoogleServiceAuthError FromConnectionError(int error) {
92 return GoogleServiceAuthError(CONNECTION_FAILED, error); 96 return GoogleServiceAuthError(CONNECTION_FAILED, error);
93 } 97 }
94 98
95 // Construct a CAPTCHA_REQUIRED error with CAPTCHA challenge data. 99 // Construct a CAPTCHA_REQUIRED error with CAPTCHA challenge data.
96 static GoogleServiceAuthError FromCaptchaChallenge( 100 static GoogleServiceAuthError FromCaptchaChallenge(
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 captcha_(captcha_token, captcha_image_url, captcha_unlock_url), 134 captcha_(captcha_token, captcha_image_url, captcha_unlock_url),
131 network_error_(0) { 135 network_error_(0) {
132 } 136 }
133 137
134 State state_; 138 State state_;
135 Captcha captcha_; 139 Captcha captcha_;
136 int network_error_; 140 int network_error_;
137 }; 141 };
138 142
139 #endif // CHROME_COMMON_NET_GAIA_GOOGLE_SERVICE_AUTH_ERROR_H_ 143 #endif // CHROME_COMMON_NET_GAIA_GOOGLE_SERVICE_AUTH_ERROR_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698