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/oauth2_api_call_flow.h" | 5 #include "google_apis/gaia/oauth2_api_call_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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 if (tried_mint_access_token_) { | 83 if (tried_mint_access_token_) { |
84 state_ = ERROR_STATE; | 84 state_ = ERROR_STATE; |
85 ProcessApiCallFailure(source); | 85 ProcessApiCallFailure(source); |
86 } else { | 86 } else { |
87 BeginMintAccessToken(); | 87 BeginMintAccessToken(); |
88 } | 88 } |
89 | 89 |
90 return; | 90 return; |
91 } | 91 } |
92 | 92 |
93 if (source->GetResponseCode() != net::HTTP_OK) { | 93 if (source->GetResponseCode() != net::HTTP_OK && |
| 94 source->GetResponseCode() != net::HTTP_NO_CONTENT) { |
94 state_ = ERROR_STATE; | 95 state_ = ERROR_STATE; |
95 ProcessApiCallFailure(source); | 96 ProcessApiCallFailure(source); |
96 return; | 97 return; |
97 } | 98 } |
98 | 99 |
99 ProcessApiCallSuccess(source); | 100 ProcessApiCallSuccess(source); |
100 } | 101 } |
101 | 102 |
102 void OAuth2ApiCallFlow::BeginMintAccessToken() { | 103 void OAuth2ApiCallFlow::BeginMintAccessToken() { |
103 CHECK(state_ == INITIAL || state_ == API_CALL_DONE); | 104 CHECK(state_ == INITIAL || state_ == API_CALL_DONE); |
(...skipping 14 matching lines...) Expand all Loading... |
118 | 119 |
119 if (!error) { | 120 if (!error) { |
120 state_ = MINT_ACCESS_TOKEN_DONE; | 121 state_ = MINT_ACCESS_TOKEN_DONE; |
121 BeginApiCall(); | 122 BeginApiCall(); |
122 } else { | 123 } else { |
123 state_ = ERROR_STATE; | 124 state_ = ERROR_STATE; |
124 ProcessMintAccessTokenFailure(*error); | 125 ProcessMintAccessTokenFailure(*error); |
125 } | 126 } |
126 } | 127 } |
127 | 128 |
| 129 std::string OAuth2ApiCallFlow::CreateApiCallBodyContentType() { |
| 130 return "application/x-www-form-urlencoded"; |
| 131 } |
| 132 |
128 OAuth2AccessTokenFetcher* OAuth2ApiCallFlow::CreateAccessTokenFetcher() { | 133 OAuth2AccessTokenFetcher* OAuth2ApiCallFlow::CreateAccessTokenFetcher() { |
129 return new OAuth2AccessTokenFetcherImpl(this, context_, refresh_token_); | 134 return new OAuth2AccessTokenFetcherImpl(this, context_, refresh_token_); |
130 } | 135 } |
131 | 136 |
132 void OAuth2ApiCallFlow::OnURLFetchComplete(const net::URLFetcher* source) { | 137 void OAuth2ApiCallFlow::OnURLFetchComplete(const net::URLFetcher* source) { |
133 CHECK(source); | 138 CHECK(source); |
134 CHECK_EQ(API_CALL_STARTED, state_); | 139 CHECK_EQ(API_CALL_STARTED, state_); |
135 EndApiCall(source); | 140 EndApiCall(source); |
136 } | 141 } |
137 | 142 |
(...skipping 21 matching lines...) Expand all Loading... |
159 result->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 164 result->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
160 net::LOAD_DO_NOT_SAVE_COOKIES); | 165 net::LOAD_DO_NOT_SAVE_COOKIES); |
161 result->AddExtraRequestHeader(MakeAuthorizationHeader(access_token_)); | 166 result->AddExtraRequestHeader(MakeAuthorizationHeader(access_token_)); |
162 // Fetchers are sometimes cancelled because a network change was detected, | 167 // Fetchers are sometimes cancelled because a network change was detected, |
163 // especially at startup and after sign-in on ChromeOS. Retrying once should | 168 // especially at startup and after sign-in on ChromeOS. Retrying once should |
164 // be enough in those cases; let the fetcher retry up to 3 times just in case. | 169 // be enough in those cases; let the fetcher retry up to 3 times just in case. |
165 // http://crbug.com/163710 | 170 // http://crbug.com/163710 |
166 result->SetAutomaticallyRetryOnNetworkChanges(3); | 171 result->SetAutomaticallyRetryOnNetworkChanges(3); |
167 | 172 |
168 if (!empty_body) | 173 if (!empty_body) |
169 result->SetUploadData("application/x-www-form-urlencoded", body); | 174 result->SetUploadData(CreateApiCallBodyContentType(), body); |
170 | 175 |
171 return result; | 176 return result; |
172 } | 177 } |
OLD | NEW |