| 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/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 11 #include "google_apis/gaia/gaia_auth_util.h" |
| 11 #include "google_apis/gaia/gaia_urls.h" | 12 #include "google_apis/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 net::URLFetcher; | 19 using net::URLFetcher; |
| 19 using net::URLFetcherDelegate; | 20 using net::URLFetcherDelegate; |
| 20 using net::URLRequestContextGetter; | 21 using net::URLRequestContextGetter; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 } | 75 } |
| 75 | 76 |
| 76 std::unique_ptr<URLFetcher> OAuth2ApiCallFlow::CreateURLFetcher( | 77 std::unique_ptr<URLFetcher> OAuth2ApiCallFlow::CreateURLFetcher( |
| 77 net::URLRequestContextGetter* context, | 78 net::URLRequestContextGetter* context, |
| 78 const std::string& access_token) { | 79 const std::string& access_token) { |
| 79 std::string body = CreateApiCallBody(); | 80 std::string body = CreateApiCallBody(); |
| 80 net::URLFetcher::RequestType request_type = GetRequestTypeForBody(body); | 81 net::URLFetcher::RequestType request_type = GetRequestTypeForBody(body); |
| 81 std::unique_ptr<URLFetcher> result = | 82 std::unique_ptr<URLFetcher> result = |
| 82 net::URLFetcher::Create(0, CreateApiCallUrl(), request_type, this); | 83 net::URLFetcher::Create(0, CreateApiCallUrl(), request_type, this); |
| 83 | 84 |
| 85 gaia::MarkURLFetcherAsGaia(result.get()); |
| 84 result->SetRequestContext(context); | 86 result->SetRequestContext(context); |
| 85 result->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 87 result->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
| 86 net::LOAD_DO_NOT_SAVE_COOKIES); | 88 net::LOAD_DO_NOT_SAVE_COOKIES); |
| 87 result->AddExtraRequestHeader(MakeAuthorizationHeader(access_token)); | 89 result->AddExtraRequestHeader(MakeAuthorizationHeader(access_token)); |
| 88 // Fetchers are sometimes cancelled because a network change was detected, | 90 // Fetchers are sometimes cancelled because a network change was detected, |
| 89 // especially at startup and after sign-in on ChromeOS. Retrying once should | 91 // especially at startup and after sign-in on ChromeOS. Retrying once should |
| 90 // be enough in those cases; let the fetcher retry up to 3 times just in case. | 92 // be enough in those cases; let the fetcher retry up to 3 times just in case. |
| 91 // http://crbug.com/163710 | 93 // http://crbug.com/163710 |
| 92 result->SetAutomaticallyRetryOnNetworkChanges(3); | 94 result->SetAutomaticallyRetryOnNetworkChanges(3); |
| 93 | 95 |
| 94 // Even if the the body is empty, we still set the Content-Type because an | 96 // Even if the the body is empty, we still set the Content-Type because an |
| 95 // empty string may be a meaningful value. For example, a Protocol Buffer | 97 // empty string may be a meaningful value. For example, a Protocol Buffer |
| 96 // message with only default values will be serialized as an empty string. | 98 // message with only default values will be serialized as an empty string. |
| 97 if (request_type != net::URLFetcher::GET) | 99 if (request_type != net::URLFetcher::GET) |
| 98 result->SetUploadData(CreateApiCallBodyContentType(), body); | 100 result->SetUploadData(CreateApiCallBodyContentType(), body); |
| 99 | 101 |
| 100 return result; | 102 return result; |
| 101 } | 103 } |
| OLD | NEW |