Chromium Code Reviews| 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_api_call_flow.h" | 5 #include "chrome/common/net/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" |
| 11 #include "base/stringprintf.h" | |
| 11 #include "chrome/common/net/gaia/gaia_urls.h" | 12 #include "chrome/common/net/gaia/gaia_urls.h" |
| 12 #include "net/base/escape.h" | 13 #include "net/base/escape.h" |
| 13 #include "net/base/load_flags.h" | 14 #include "net/base/load_flags.h" |
| 14 #include "net/http/http_status_code.h" | 15 #include "net/http/http_status_code.h" |
| 15 #include "net/url_request/url_request_context_getter.h" | 16 #include "net/url_request/url_request_context_getter.h" |
| 16 #include "net/url_request/url_request_status.h" | 17 #include "net/url_request/url_request_status.h" |
| 17 | 18 |
| 18 using content::URLFetcher; | 19 using content::URLFetcher; |
| 19 using content::URLFetcherDelegate; | 20 using content::URLFetcherDelegate; |
| 20 using net::ResponseCookies; | 21 using net::ResponseCookies; |
| 21 using net::URLRequestContextGetter; | 22 using net::URLRequestContextGetter; |
| 22 using net::URLRequestStatus; | 23 using net::URLRequestStatus; |
| 23 | 24 |
| 25 namespace { | |
| 26 static const char kAuthorizationHeaderFormat[] = | |
| 27 "Authorization: Bearer %s"; | |
| 28 | |
| 29 static std::string MakeAuthorizationHeader(const std::string& auth_token) { | |
|
jstritar
2012/04/16 19:30:36
nit: rm extra space
Munjal (Google)
2012/04/16 19:32:14
Done.
| |
| 30 return StringPrintf(kAuthorizationHeaderFormat, auth_token.c_str()); | |
| 31 } | |
| 32 } | |
|
jstritar
2012/04/16 19:30:36
nit: // namespace
Munjal (Google)
2012/04/16 19:32:14
Done.
| |
| 33 | |
| 24 OAuth2ApiCallFlow::OAuth2ApiCallFlow( | 34 OAuth2ApiCallFlow::OAuth2ApiCallFlow( |
| 25 net::URLRequestContextGetter* context, | 35 net::URLRequestContextGetter* context, |
| 26 const std::string& refresh_token, | 36 const std::string& refresh_token, |
| 27 const std::string& access_token, | 37 const std::string& access_token, |
| 28 const std::vector<std::string>& scopes) | 38 const std::vector<std::string>& scopes) |
| 29 : context_(context), | 39 : context_(context), |
| 30 refresh_token_(refresh_token), | 40 refresh_token_(refresh_token), |
| 31 access_token_(access_token), | 41 access_token_(access_token), |
| 32 scopes_(scopes), | 42 scopes_(scopes), |
| 33 state_(INITIAL), | 43 state_(INITIAL), |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 bool empty_body = body.empty(); | 149 bool empty_body = body.empty(); |
| 140 URLFetcher* result = URLFetcher::Create( | 150 URLFetcher* result = URLFetcher::Create( |
| 141 0, | 151 0, |
| 142 CreateApiCallUrl(), | 152 CreateApiCallUrl(), |
| 143 empty_body ? URLFetcher::GET : URLFetcher::POST, | 153 empty_body ? URLFetcher::GET : URLFetcher::POST, |
| 144 this); | 154 this); |
| 145 | 155 |
| 146 result->SetRequestContext(context_); | 156 result->SetRequestContext(context_); |
| 147 result->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 157 result->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
| 148 net::LOAD_DO_NOT_SAVE_COOKIES); | 158 net::LOAD_DO_NOT_SAVE_COOKIES); |
| 159 result->AddExtraRequestHeader(MakeAuthorizationHeader(access_token_)); | |
| 149 | 160 |
| 150 if (!empty_body) | 161 if (!empty_body) |
| 151 result->SetUploadData("application/x-www-form-urlencoded", body); | 162 result->SetUploadData("application/x-www-form-urlencoded", body); |
| 152 | 163 |
| 153 return result; | 164 return result; |
| 154 } | 165 } |
| OLD | NEW |