| 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" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 CHECK(source); | 72 CHECK(source); |
| 73 CHECK_EQ(API_CALL_STARTED, state_); | 73 CHECK_EQ(API_CALL_STARTED, state_); |
| 74 EndApiCall(source); | 74 EndApiCall(source); |
| 75 } | 75 } |
| 76 | 76 |
| 77 std::unique_ptr<URLFetcher> OAuth2ApiCallFlow::CreateURLFetcher( | 77 std::unique_ptr<URLFetcher> OAuth2ApiCallFlow::CreateURLFetcher( |
| 78 net::URLRequestContextGetter* context, | 78 net::URLRequestContextGetter* context, |
| 79 const std::string& access_token) { | 79 const std::string& access_token) { |
| 80 std::string body = CreateApiCallBody(); | 80 std::string body = CreateApiCallBody(); |
| 81 net::URLFetcher::RequestType request_type = GetRequestTypeForBody(body); | 81 net::URLFetcher::RequestType request_type = GetRequestTypeForBody(body); |
| 82 std::unique_ptr<URLFetcher> result = | 82 net::NetworkTrafficAnnotationTag traffic_annotation = |
| 83 net::URLFetcher::Create(0, CreateApiCallUrl(), request_type, this); | 83 CompleteNetworkTrafficAnnotation("oauth2_api_call_flow", |
| 84 GetNetworkTrafficAnnotationTag(), R"( |
| 85 policy { |
| 86 cookies_allowed: false |
| 87 })"); |
| 88 std::unique_ptr<URLFetcher> result = net::URLFetcher::Create( |
| 89 0, CreateApiCallUrl(), request_type, this, traffic_annotation); |
| 84 | 90 |
| 85 gaia::MarkURLFetcherAsGaia(result.get()); | 91 gaia::MarkURLFetcherAsGaia(result.get()); |
| 86 result->SetRequestContext(context); | 92 result->SetRequestContext(context); |
| 87 result->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 93 result->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
| 88 net::LOAD_DO_NOT_SAVE_COOKIES); | 94 net::LOAD_DO_NOT_SAVE_COOKIES); |
| 89 result->AddExtraRequestHeader(MakeAuthorizationHeader(access_token)); | 95 result->AddExtraRequestHeader(MakeAuthorizationHeader(access_token)); |
| 90 // Fetchers are sometimes cancelled because a network change was detected, | 96 // Fetchers are sometimes cancelled because a network change was detected, |
| 91 // especially at startup and after sign-in on ChromeOS. Retrying once should | 97 // especially at startup and after sign-in on ChromeOS. Retrying once should |
| 92 // be enough in those cases; let the fetcher retry up to 3 times just in case. | 98 // be enough in those cases; let the fetcher retry up to 3 times just in case. |
| 93 // http://crbug.com/163710 | 99 // http://crbug.com/163710 |
| 94 result->SetAutomaticallyRetryOnNetworkChanges(3); | 100 result->SetAutomaticallyRetryOnNetworkChanges(3); |
| 95 | 101 |
| 96 // Even if the the body is empty, we still set the Content-Type because an | 102 // Even if the the body is empty, we still set the Content-Type because an |
| 97 // empty string may be a meaningful value. For example, a Protocol Buffer | 103 // empty string may be a meaningful value. For example, a Protocol Buffer |
| 98 // message with only default values will be serialized as an empty string. | 104 // message with only default values will be serialized as an empty string. |
| 99 if (request_type != net::URLFetcher::GET) | 105 if (request_type != net::URLFetcher::GET) |
| 100 result->SetUploadData(CreateApiCallBodyContentType(), body); | 106 result->SetUploadData(CreateApiCallBodyContentType(), body); |
| 101 | 107 |
| 102 return result; | 108 return result; |
| 103 } | 109 } |
| OLD | NEW |