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

Side by Side Diff: chrome/common/net/gaia/authentication_fetcher.cc

Issue 6894027: Initial refactoring complete Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Fixed some tests that were broken by previous refactoring Created 9 years, 8 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/common/net/gaia/authentication_fetcher.h"
6
7 #include <string>
8 #include <utility>
9 #include <vector>
10
11 #include "base/logging.h"
12 #include "base/string_split.h"
13 #include "base/string_util.h"
14 #include "chrome/browser/net/gaia/authentication_service.h"
15 #include "chrome/common/net/gaia/gaia_auth_fetcher.h"
16 #include "chrome/common/net/gaia/gaia_constants.h"
17 #include "chrome/common/net/gaia/google_service_auth_error.h"
18 #include "chrome/common/net/gaia/authentication_consumer_oauth.h"
19 #include "chrome/common/net/gaia/authentication_fetcher_oauth.h"
20 #include "chrome/common/net/http_return.h"
21 #include "net/base/load_flags.h"
22 #include "net/url_request/url_request_context_getter.h"
23 #include "net/url_request/url_request_status.h"
24 #include "third_party/libjingle/source/talk/base/urlencode.h"
25
26 // TODO(chron): Add sourceless version of this formatter.
27 // static
28 const char AuthenticationFetcher::kAuthenticationFormat[] =
29 "Email=%s&"
30 "Passwd=%s&"
31 "PersistentCookie=%s&"
32 "accountType=%s&"
33 "source=%s&"
34 "service=%s";
35 // static
36 const char AuthenticationFetcher::kAuthenticationCaptchaFormat[] =
37 "Email=%s&"
38 "Passwd=%s&"
39 "PersistentCookie=%s&"
40 "accountType=%s&"
41 "source=%s&"
42 "service=%s&"
43 "logintoken=%s&"
44 "logincaptcha=%s";
45 // static
46 const char AuthenticationFetcher::kIssueAuthTokenFormat[] =
47 "SID=%s&"
48 "LSID=%s&"
49 "service=%s&"
50 "Session=%s";
51 // static
52 const char AuthenticationFetcher::kGetUserInfoFormat[] =
53 "LSID=%s";
54
55 // static
56 const char AuthenticationFetcher::kAccountDeletedError[] = "AccountDeleted";
57 // static
58 const char AuthenticationFetcher::kAccountDisabledError[] = "AccountDisabled";
59 // static
60 const char AuthenticationFetcher::kBadAuthenticationError[] =
61 "BadAuthentication";
62 // static
63 const char AuthenticationFetcher::kCaptchaError[] = "CaptchaRequired";
64 // static
65 const char AuthenticationFetcher::kServiceUnavailableError[] =
66 "ServiceUnavailable";
67 // static
68 const char AuthenticationFetcher::kErrorParam[] = "Error";
69 // static
70 const char AuthenticationFetcher::kErrorUrlParam[] = "Url";
71 // static
72 const char AuthenticationFetcher::kCaptchaUrlParam[] = "CaptchaUrl";
73 // static
74 const char AuthenticationFetcher::kCaptchaTokenParam[] = "CaptchaToken";
75 // static
76 const char AuthenticationFetcher::kCaptchaUrlPrefix[] =
77 "http://www.google.com/accounts/";
78
79 // static
80 const char AuthenticationFetcher::kCookiePersistence[] = "true";
81 // static
82 // TODO(johnnyg): When hosted accounts are supported by sync,
83 // we can always use "HOSTED_OR_GOOGLE"
84 const char AuthenticationFetcher::kAccountTypeHostedOrGoogle[] =
85 "HOSTED_OR_GOOGLE";
86 const char AuthenticationFetcher::kAccountTypeGoogle[] =
87 "GOOGLE";
88
89 // static
90 const char AuthenticationFetcher::kSecondFactor[] = "Info=InvalidSecondFactor";
91
92 // TODO(chron): These urls are also in auth_response_handler.h.
93 // The URLs for different calls in the Google Accounts programmatic login API.
94 const char AuthenticationFetcher::kAuthenticationUrl[] =
95 "https://www.google.com/accounts/ClientLogin";
96 const char AuthenticationFetcher::kIssueAuthTokenUrl[] =
97 "https://www.google.com/accounts/IssueAuthToken";
98 const char AuthenticationFetcher::kGetUserInfoUrl[] =
99 "https://www.google.com/accounts/GetUserInfo";
100
101 AuthenticationFetcher::AuthenticationFetcher(
102 AuthenticationConsumer* consumer,
103 const std::string& source,
104 net::URLRequestContextGetter* getter)
105 : consumer_(consumer),
106 getter_(getter),
107 source_(source),
108 fetch_pending_(false) {}
109
110 AuthenticationFetcher::~AuthenticationFetcher() {}
111
112 bool AuthenticationFetcher::HasPendingFetch() const {
113 return fetch_pending_;
114 }
115
116 void AuthenticationFetcher::CancelRequest() {
117 fetcher_.reset();
118 fetch_pending_ = false;
119 }
120
121 void AuthenticationFetcher::ClearPending() {
122 fetch_pending_ = false;
123 }
124
125 void AuthenticationFetcher::SetPending() {
126 fetch_pending_ = true;
127 }
128
129 // static
130 AuthenticationFetcher* AuthenticationFetcher::CreateAuthenticationFetcher(
131 const std::string& variant,
132 AuthenticationConsumer* consumer,
133 const std::string& source,
134 net::URLRequestContextGetter* getter) {
135 if (variant == AuthenticationService::kClientLoginVariant) {
136 return new GaiaAuthFetcher(
137 static_cast<GaiaAuthConsumer*>(consumer), source, getter);
138 }
139 if (variant == AuthenticationService::kOAuthVariant) {
140 return new AuthenticationFetcherOAuth(
141 static_cast<AuthenticationConsumerOAuth*>(consumer), source, getter);
142 }
143 NOTREACHED();
144 return NULL;
145 }
146
147 // static
148 URLFetcher* AuthenticationFetcher::CreateAuthenticationFetcher(
149 net::URLRequestContextGetter* getter,
150 const std::string& body,
151 const GURL& gaia_gurl,
152 URLFetcher::Delegate* delegate) {
153
154 URLFetcher* to_return =
155 URLFetcher::Create(0,
156 gaia_gurl,
157 URLFetcher::POST,
158 delegate);
159 to_return->set_request_context(getter);
160 to_return->set_load_flags(net::LOAD_DO_NOT_SEND_COOKIES);
161 to_return->set_upload_data("application/x-www-form-urlencoded", body);
162 return to_return;
163 }
OLDNEW
« no previous file with comments | « chrome/common/net/gaia/authentication_fetcher.h ('k') | chrome/common/net/gaia/authentication_fetcher_oauth.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698