| 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 "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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 } | 112 } |
| 113 | 113 |
| 114 OAuth2MintTokenFlow::~OAuth2MintTokenFlow() { } | 114 OAuth2MintTokenFlow::~OAuth2MintTokenFlow() { } |
| 115 | 115 |
| 116 void OAuth2MintTokenFlow::Start() { | 116 void OAuth2MintTokenFlow::Start() { |
| 117 AddRef(); // Balanced in ReportSuccess|IssueAdviceSuccess|Failure. |
| 118 |
| 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, this, auth_token)); |
| 128 base::Unretained(delegate_), auth_token)); | |
| 129 } else { | 130 } else { |
| 130 MessageLoop::current()->PostTask( | 131 MessageLoop::current()->PostTask( |
| 131 FROM_HERE, | 132 FROM_HERE, |
| 132 base::Bind(&OAuth2MintTokenFlow::Delegate::OnMintTokenFailure, | 133 base::Bind(&OAuth2MintTokenFlow::ReportFailure, this, error)); |
| 133 base::Unretained(delegate_), error)); | |
| 134 } | 134 } |
| 135 return; | 135 return; |
| 136 } | 136 } |
| 137 | 137 |
| 138 |
| 138 OAuth2ApiCallFlow::Start(); | 139 OAuth2ApiCallFlow::Start(); |
| 139 } | 140 } |
| 140 | 141 |
| 141 void OAuth2MintTokenFlow::ReportSuccess(const std::string& access_token) { | 142 void OAuth2MintTokenFlow::ReportSuccess(const std::string& access_token) { |
| 142 if (delegate_) { | 143 if (delegate_) { |
| 143 delegate_->OnMintTokenSuccess(access_token); | 144 delegate_->OnMintTokenSuccess(access_token); |
| 144 } | 145 } |
| 146 |
| 147 Release(); // Balanced in Start(). |
| 145 } | 148 } |
| 146 | 149 |
| 147 void OAuth2MintTokenFlow::ReportSuccess(const IssueAdviceInfo& issue_advice) { | 150 void OAuth2MintTokenFlow::ReportIssueAdviceSuccess( |
| 151 const IssueAdviceInfo& issue_advice) { |
| 148 if (delegate_) { | 152 if (delegate_) { |
| 149 delegate_->OnIssueAdviceSuccess(issue_advice); | 153 delegate_->OnIssueAdviceSuccess(issue_advice); |
| 150 } | 154 } |
| 155 |
| 156 Release(); // Balanced in Start(). |
| 151 } | 157 } |
| 152 | 158 |
| 153 void OAuth2MintTokenFlow::ReportFailure( | 159 void OAuth2MintTokenFlow::ReportFailure( |
| 154 const GoogleServiceAuthError& error) { | 160 const GoogleServiceAuthError& error) { |
| 155 if (delegate_) { | 161 if (delegate_) { |
| 156 delegate_->OnMintTokenFailure(error); | 162 delegate_->OnMintTokenFailure(error); |
| 157 } | 163 } |
| 164 |
| 165 Release(); // Balanced in Start(). |
| 158 } | 166 } |
| 159 | 167 |
| 160 GURL OAuth2MintTokenFlow::CreateApiCallUrl() { | 168 GURL OAuth2MintTokenFlow::CreateApiCallUrl() { |
| 161 return GURL(GaiaUrls::GetInstance()->oauth2_issue_token_url()); | 169 return GURL(GaiaUrls::GetInstance()->oauth2_issue_token_url()); |
| 162 } | 170 } |
| 163 | 171 |
| 164 std::string OAuth2MintTokenFlow::CreateApiCallBody() { | 172 std::string OAuth2MintTokenFlow::CreateApiCallBody() { |
| 165 const char* force_value = | 173 const char* force_value = |
| 166 (parameters_.mode == MODE_MINT_TOKEN_FORCE || | 174 (parameters_.mode == MODE_MINT_TOKEN_FORCE || |
| 167 parameters_.mode == MODE_RECORD_GRANT) | 175 parameters_.mode == MODE_RECORD_GRANT) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 194 } | 202 } |
| 195 | 203 |
| 196 std::string issue_advice; | 204 std::string issue_advice; |
| 197 if (!dict->GetString(kIssueAdviceKey, &issue_advice)) { | 205 if (!dict->GetString(kIssueAdviceKey, &issue_advice)) { |
| 198 ReportFailure(GoogleServiceAuthError::FromConnectionError(101)); | 206 ReportFailure(GoogleServiceAuthError::FromConnectionError(101)); |
| 199 return; | 207 return; |
| 200 } | 208 } |
| 201 if (issue_advice == kIssueAdviceValueConsent) { | 209 if (issue_advice == kIssueAdviceValueConsent) { |
| 202 IssueAdviceInfo issue_advice; | 210 IssueAdviceInfo issue_advice; |
| 203 if (ParseIssueAdviceResponse(dict, &issue_advice)) | 211 if (ParseIssueAdviceResponse(dict, &issue_advice)) |
| 204 ReportSuccess(issue_advice); | 212 ReportIssueAdviceSuccess(issue_advice); |
| 205 else | 213 else |
| 206 ReportFailure(GoogleServiceAuthError::FromConnectionError(101)); | 214 ReportFailure(GoogleServiceAuthError::FromConnectionError(101)); |
| 207 } else { | 215 } else { |
| 208 std::string access_token; | 216 std::string access_token; |
| 209 if (ParseMintTokenResponse(dict, &access_token)) | 217 if (ParseMintTokenResponse(dict, &access_token)) |
| 210 ReportSuccess(access_token); | 218 ReportSuccess(access_token); |
| 211 else | 219 else |
| 212 ReportFailure(GoogleServiceAuthError::FromConnectionError(101)); | 220 ReportFailure(GoogleServiceAuthError::FromConnectionError(101)); |
| 213 } | 221 } |
| 214 } | 222 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 | 272 |
| 265 Tokenize(detail, kDetailSeparators, &entry.details); | 273 Tokenize(detail, kDetailSeparators, &entry.details); |
| 266 issue_advice->push_back(entry); | 274 issue_advice->push_back(entry); |
| 267 } | 275 } |
| 268 | 276 |
| 269 if (!success) | 277 if (!success) |
| 270 issue_advice->clear(); | 278 issue_advice->clear(); |
| 271 | 279 |
| 272 return success; | 280 return success; |
| 273 } | 281 } |
| OLD | NEW |