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

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

Issue 10630021: Modify experimental identity flow to display scope descriptions and details. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync Created 8 years, 5 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
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 "chrome/common/net/gaia/oauth2_mint_token_flow.h" 5 #include "chrome/common/net/gaia/oauth2_mint_token_flow.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 101
102 OAuth2MintTokenFlow::OAuth2MintTokenFlow( 102 OAuth2MintTokenFlow::OAuth2MintTokenFlow(
103 URLRequestContextGetter* context, 103 URLRequestContextGetter* context,
104 Delegate* delegate, 104 Delegate* delegate,
105 const Parameters& parameters) 105 const Parameters& parameters)
106 : OAuth2ApiCallFlow( 106 : OAuth2ApiCallFlow(
107 context, parameters.login_refresh_token, 107 context, parameters.login_refresh_token,
108 "", std::vector<std::string>()), 108 "", std::vector<std::string>()),
109 context_(context), 109 context_(context),
110 delegate_(delegate), 110 delegate_(delegate),
111 parameters_(parameters) { 111 parameters_(parameters),
112 delete_when_done_(false),
113 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
112 } 114 }
113 115
114 OAuth2MintTokenFlow::~OAuth2MintTokenFlow() { } 116 OAuth2MintTokenFlow::~OAuth2MintTokenFlow() { }
115 117
116 void OAuth2MintTokenFlow::Start() { 118 void OAuth2MintTokenFlow::Start() {
117 if (g_interceptor_for_tests) { 119 if (g_interceptor_for_tests) {
118 std::string auth_token; 120 std::string auth_token;
119 GoogleServiceAuthError error = GoogleServiceAuthError::None(); 121 GoogleServiceAuthError error = GoogleServiceAuthError::None();
120 122
121 // We use PostTask, instead of calling the delegate directly, because the 123 // We use PostTask, instead of calling the delegate directly, because the
122 // message loop will run a few times before we notify the delegate in the 124 // message loop will run a few times before we notify the delegate in the
123 // real implementation. 125 // real implementation.
124 if (g_interceptor_for_tests->DoIntercept(this, &auth_token, &error)) { 126 if (g_interceptor_for_tests->DoIntercept(this, &auth_token, &error)) {
125 MessageLoop::current()->PostTask( 127 MessageLoop::current()->PostTask(
126 FROM_HERE, 128 FROM_HERE,
127 base::Bind(&OAuth2MintTokenFlow::Delegate::OnMintTokenSuccess, 129 base::Bind(&OAuth2MintTokenFlow::ReportSuccess,
128 base::Unretained(delegate_), auth_token)); 130 weak_factory_.GetWeakPtr(), auth_token));
129 } else { 131 } else {
130 MessageLoop::current()->PostTask( 132 MessageLoop::current()->PostTask(
131 FROM_HERE, 133 FROM_HERE,
132 base::Bind(&OAuth2MintTokenFlow::Delegate::OnMintTokenFailure, 134 base::Bind(&OAuth2MintTokenFlow::ReportFailure,
133 base::Unretained(delegate_), error)); 135 weak_factory_.GetWeakPtr(), error));
134 } 136 }
135 return; 137 return;
136 } 138 }
137 139
140
138 OAuth2ApiCallFlow::Start(); 141 OAuth2ApiCallFlow::Start();
139 } 142 }
140 143
141 void OAuth2MintTokenFlow::ReportSuccess(const std::string& access_token) { 144 void OAuth2MintTokenFlow::FireAndForget() {
142 if (delegate_) { 145 delete_when_done_ = true;
143 delegate_->OnMintTokenSuccess(access_token); 146 Start();
144 }
145 } 147 }
146 148
147 void OAuth2MintTokenFlow::ReportSuccess(const IssueAdviceInfo& issue_advice) { 149 void OAuth2MintTokenFlow::ReportSuccess(const std::string& access_token) {
148 if (delegate_) { 150 if (delegate_)
151 delegate_->OnMintTokenSuccess(access_token);
152
153 if (delete_when_done_)
154 delete this;
155 }
156
157 void OAuth2MintTokenFlow::ReportIssueAdviceSuccess(
158 const IssueAdviceInfo& issue_advice) {
159 if (delegate_)
149 delegate_->OnIssueAdviceSuccess(issue_advice); 160 delegate_->OnIssueAdviceSuccess(issue_advice);
150 } 161
162 if (delete_when_done_)
163 delete this;
151 } 164 }
152 165
153 void OAuth2MintTokenFlow::ReportFailure( 166 void OAuth2MintTokenFlow::ReportFailure(
154 const GoogleServiceAuthError& error) { 167 const GoogleServiceAuthError& error) {
155 if (delegate_) { 168 if (delegate_)
156 delegate_->OnMintTokenFailure(error); 169 delegate_->OnMintTokenFailure(error);
157 } 170
171 if (delete_when_done_)
172 delete this;
158 } 173 }
159 174
160 GURL OAuth2MintTokenFlow::CreateApiCallUrl() { 175 GURL OAuth2MintTokenFlow::CreateApiCallUrl() {
161 return GURL(GaiaUrls::GetInstance()->oauth2_issue_token_url()); 176 return GURL(GaiaUrls::GetInstance()->oauth2_issue_token_url());
162 } 177 }
163 178
164 std::string OAuth2MintTokenFlow::CreateApiCallBody() { 179 std::string OAuth2MintTokenFlow::CreateApiCallBody() {
165 const char* force_value = 180 const char* force_value =
166 (parameters_.mode == MODE_MINT_TOKEN_FORCE || 181 (parameters_.mode == MODE_MINT_TOKEN_FORCE ||
167 parameters_.mode == MODE_RECORD_GRANT) 182 parameters_.mode == MODE_RECORD_GRANT)
(...skipping 26 matching lines...) Expand all
194 } 209 }
195 210
196 std::string issue_advice; 211 std::string issue_advice;
197 if (!dict->GetString(kIssueAdviceKey, &issue_advice)) { 212 if (!dict->GetString(kIssueAdviceKey, &issue_advice)) {
198 ReportFailure(GoogleServiceAuthError::FromConnectionError(101)); 213 ReportFailure(GoogleServiceAuthError::FromConnectionError(101));
199 return; 214 return;
200 } 215 }
201 if (issue_advice == kIssueAdviceValueConsent) { 216 if (issue_advice == kIssueAdviceValueConsent) {
202 IssueAdviceInfo issue_advice; 217 IssueAdviceInfo issue_advice;
203 if (ParseIssueAdviceResponse(dict, &issue_advice)) 218 if (ParseIssueAdviceResponse(dict, &issue_advice))
204 ReportSuccess(issue_advice); 219 ReportIssueAdviceSuccess(issue_advice);
205 else 220 else
206 ReportFailure(GoogleServiceAuthError::FromConnectionError(101)); 221 ReportFailure(GoogleServiceAuthError::FromConnectionError(101));
207 } else { 222 } else {
208 std::string access_token; 223 std::string access_token;
209 if (ParseMintTokenResponse(dict, &access_token)) 224 if (ParseMintTokenResponse(dict, &access_token))
210 ReportSuccess(access_token); 225 ReportSuccess(access_token);
211 else 226 else
212 ReportFailure(GoogleServiceAuthError::FromConnectionError(101)); 227 ReportFailure(GoogleServiceAuthError::FromConnectionError(101));
213 } 228 }
229
230 // |this| may be deleted!
214 } 231 }
215 232
216 void OAuth2MintTokenFlow::ProcessApiCallFailure( 233 void OAuth2MintTokenFlow::ProcessApiCallFailure(
217 const net::URLFetcher* source) { 234 const net::URLFetcher* source) {
218 ReportFailure(CreateAuthError(source->GetStatus())); 235 ReportFailure(CreateAuthError(source->GetStatus()));
219 } 236 }
220 void OAuth2MintTokenFlow::ProcessNewAccessToken( 237 void OAuth2MintTokenFlow::ProcessNewAccessToken(
221 const std::string& access_token) { 238 const std::string& access_token) {
222 // We don't currently store new access tokens. We generate one every time. 239 // We don't currently store new access tokens. We generate one every time.
223 // So we have nothing to do here. 240 // So we have nothing to do here.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 281
265 Tokenize(detail, kDetailSeparators, &entry.details); 282 Tokenize(detail, kDetailSeparators, &entry.details);
266 issue_advice->push_back(entry); 283 issue_advice->push_back(entry);
267 } 284 }
268 285
269 if (!success) 286 if (!success)
270 issue_advice->clear(); 287 issue_advice->clear();
271 288
272 return success; 289 return success;
273 } 290 }
OLDNEW
« no previous file with comments | « chrome/common/net/gaia/oauth2_mint_token_flow.h ('k') | chrome/test/data/extensions/browsertest/scopes/manifest.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698