| 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/service/cloud_print/cloud_print_url_fetcher.h" | 5 #include "chrome/service/cloud_print/cloud_print_url_fetcher.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/common/cloud_print/cloud_print_constants.h" | 12 #include "chrome/common/cloud_print/cloud_print_constants.h" |
| 13 #include "chrome/common/cloud_print/cloud_print_helpers.h" | 13 #include "chrome/common/cloud_print/cloud_print_helpers.h" |
| 14 #include "chrome/service/cloud_print/cloud_print_service_helpers.h" | 14 #include "chrome/service/cloud_print/cloud_print_service_helpers.h" |
| 15 #include "chrome/service/cloud_print/cloud_print_token_store.h" | 15 #include "chrome/service/cloud_print/cloud_print_token_store.h" |
| 16 #include "chrome/service/net/service_url_request_context_getter.h" | 16 #include "chrome/service/net/service_url_request_context_getter.h" |
| 17 #include "chrome/service/service_process.h" | 17 #include "chrome/service/service_process.h" |
| 18 #include "components/data_use_measurement/core/data_use_user_data.h" |
| 18 #include "net/base/load_flags.h" | 19 #include "net/base/load_flags.h" |
| 19 #include "net/http/http_status_code.h" | 20 #include "net/http/http_status_code.h" |
| 20 #include "net/url_request/url_fetcher.h" | 21 #include "net/url_request/url_fetcher.h" |
| 21 #include "net/url_request/url_request_status.h" | 22 #include "net/url_request/url_request_status.h" |
| 22 #include "url/gurl.h" | 23 #include "url/gurl.h" |
| 23 | 24 |
| 24 namespace cloud_print { | 25 namespace cloud_print { |
| 25 | 26 |
| 26 namespace { | 27 namespace { |
| 27 | 28 |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 const std::string& post_data_mime_type, | 253 const std::string& post_data_mime_type, |
| 253 const std::string& post_data, | 254 const std::string& post_data, |
| 254 const std::string& additional_headers) { | 255 const std::string& additional_headers) { |
| 255 DCHECK(delegate); | 256 DCHECK(delegate); |
| 256 type_ = type; | 257 type_ = type; |
| 257 UMA_HISTOGRAM_ENUMERATION("CloudPrint.UrlFetcherRequestType", type, | 258 UMA_HISTOGRAM_ENUMERATION("CloudPrint.UrlFetcherRequestType", type, |
| 258 REQUEST_MAX); | 259 REQUEST_MAX); |
| 259 // Persist the additional headers in case we need to retry the request. | 260 // Persist the additional headers in case we need to retry the request. |
| 260 additional_headers_ = additional_headers; | 261 additional_headers_ = additional_headers; |
| 261 request_ = net::URLFetcher::Create(0, url, request_type, this); | 262 request_ = net::URLFetcher::Create(0, url, request_type, this); |
| 263 data_use_measurement::DataUseUserData::AttachToFetcher( |
| 264 request_.get(), data_use_measurement::DataUseUserData::CLOUD_PRINT); |
| 262 request_->SetRequestContext(GetRequestContextGetter()); | 265 request_->SetRequestContext(GetRequestContextGetter()); |
| 263 // Since we implement our own retry logic, disable the retry in URLFetcher. | 266 // Since we implement our own retry logic, disable the retry in URLFetcher. |
| 264 request_->SetAutomaticallyRetryOn5xx(false); | 267 request_->SetAutomaticallyRetryOn5xx(false); |
| 265 request_->SetMaxRetriesOn5xx(max_retries); | 268 request_->SetMaxRetriesOn5xx(max_retries); |
| 266 delegate_ = delegate; | 269 delegate_ = delegate; |
| 267 SetupRequestHeaders(); | 270 SetupRequestHeaders(); |
| 268 request_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 271 request_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
| 269 net::LOAD_DO_NOT_SAVE_COOKIES); | 272 net::LOAD_DO_NOT_SAVE_COOKIES); |
| 270 if (request_type == net::URLFetcher::POST) { | 273 if (request_type == net::URLFetcher::POST) { |
| 271 request_->SetUploadData(post_data_mime_type, post_data); | 274 request_->SetUploadData(post_data_mime_type, post_data); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 293 ServiceURLRequestContextGetter* getter = | 296 ServiceURLRequestContextGetter* getter = |
| 294 g_service_process->GetServiceURLRequestContextGetter(); | 297 g_service_process->GetServiceURLRequestContextGetter(); |
| 295 // Now set up the user agent for cloudprint. | 298 // Now set up the user agent for cloudprint. |
| 296 std::string user_agent = getter->user_agent(); | 299 std::string user_agent = getter->user_agent(); |
| 297 base::StringAppendF(&user_agent, " %s", kCloudPrintUserAgent); | 300 base::StringAppendF(&user_agent, " %s", kCloudPrintUserAgent); |
| 298 getter->set_user_agent(user_agent); | 301 getter->set_user_agent(user_agent); |
| 299 return getter; | 302 return getter; |
| 300 } | 303 } |
| 301 | 304 |
| 302 } // namespace cloud_print | 305 } // namespace cloud_print |
| OLD | NEW |