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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 const std::string& body) { | 67 const std::string& body) { |
68 return body.empty() ? URLFetcher::GET : URLFetcher::POST; | 68 return body.empty() ? URLFetcher::GET : URLFetcher::POST; |
69 } | 69 } |
70 | 70 |
71 void OAuth2ApiCallFlow::OnURLFetchComplete(const net::URLFetcher* source) { | 71 void OAuth2ApiCallFlow::OnURLFetchComplete(const net::URLFetcher* source) { |
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 scoped_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 scoped_ptr<URLFetcher> result = | 82 std::unique_ptr<URLFetcher> result = |
83 net::URLFetcher::Create(0, CreateApiCallUrl(), request_type, this); | 83 net::URLFetcher::Create(0, CreateApiCallUrl(), request_type, this); |
84 | 84 |
85 result->SetRequestContext(context); | 85 result->SetRequestContext(context); |
86 result->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 86 result->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
87 net::LOAD_DO_NOT_SAVE_COOKIES); | 87 net::LOAD_DO_NOT_SAVE_COOKIES); |
88 result->AddExtraRequestHeader(MakeAuthorizationHeader(access_token)); | 88 result->AddExtraRequestHeader(MakeAuthorizationHeader(access_token)); |
89 // Fetchers are sometimes cancelled because a network change was detected, | 89 // Fetchers are sometimes cancelled because a network change was detected, |
90 // especially at startup and after sign-in on ChromeOS. Retrying once should | 90 // especially at startup and after sign-in on ChromeOS. Retrying once should |
91 // be enough in those cases; let the fetcher retry up to 3 times just in case. | 91 // be enough in those cases; let the fetcher retry up to 3 times just in case. |
92 // http://crbug.com/163710 | 92 // http://crbug.com/163710 |
93 result->SetAutomaticallyRetryOnNetworkChanges(3); | 93 result->SetAutomaticallyRetryOnNetworkChanges(3); |
94 | 94 |
95 // Even if the the body is empty, we still set the Content-Type because an | 95 // Even if the the body is empty, we still set the Content-Type because an |
96 // empty string may be a meaningful value. For example, a Protocol Buffer | 96 // empty string may be a meaningful value. For example, a Protocol Buffer |
97 // message with only default values will be serialized as an empty string. | 97 // message with only default values will be serialized as an empty string. |
98 if (request_type != net::URLFetcher::GET) | 98 if (request_type != net::URLFetcher::GET) |
99 result->SetUploadData(CreateApiCallBodyContentType(), body); | 99 result->SetUploadData(CreateApiCallBodyContentType(), body); |
100 | 100 |
101 return result; | 101 return result; |
102 } | 102 } |
OLD | NEW |