| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/browser/printing/cloud_print/gcd_api_flow_impl.h" | 5 #include "chrome/browser/printing/cloud_print/gcd_api_flow_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/json/json_reader.h" | 12 #include "base/json/json_reader.h" |
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "chrome/browser/printing/cloud_print/gcd_constants.h" | 16 #include "chrome/browser/printing/cloud_print/gcd_constants.h" |
| 17 #include "chrome/common/cloud_print/cloud_print_constants.h" | 17 #include "chrome/common/cloud_print/cloud_print_constants.h" |
| 18 #include "components/cloud_devices/common/cloud_devices_urls.h" | 18 #include "components/cloud_devices/common/cloud_devices_urls.h" |
| 19 #include "components/data_use_measurement/core/data_use_user_data.h" |
| 19 #include "google_apis/gaia/google_service_auth_error.h" | 20 #include "google_apis/gaia/google_service_auth_error.h" |
| 20 #include "net/base/load_flags.h" | 21 #include "net/base/load_flags.h" |
| 21 #include "net/base/url_util.h" | 22 #include "net/base/url_util.h" |
| 22 #include "net/http/http_status_code.h" | 23 #include "net/http/http_status_code.h" |
| 23 #include "net/url_request/url_request_status.h" | 24 #include "net/url_request/url_request_status.h" |
| 24 | 25 |
| 25 namespace cloud_print { | 26 namespace cloud_print { |
| 26 | 27 |
| 27 GCDApiFlowImpl::GCDApiFlowImpl(net::URLRequestContextGetter* request_context, | 28 GCDApiFlowImpl::GCDApiFlowImpl(net::URLRequestContextGetter* request_context, |
| 28 OAuth2TokenService* token_service, | 29 OAuth2TokenService* token_service, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 | 71 |
| 71 url_fetcher_ = net::URLFetcher::Create(url, request_type, this); | 72 url_fetcher_ = net::URLFetcher::Create(url, request_type, this); |
| 72 | 73 |
| 73 if (request_type != net::URLFetcher::GET) { | 74 if (request_type != net::URLFetcher::GET) { |
| 74 std::string upload_type; | 75 std::string upload_type; |
| 75 std::string upload_data; | 76 std::string upload_data; |
| 76 request_->GetUploadData(&upload_type, &upload_data); | 77 request_->GetUploadData(&upload_type, &upload_data); |
| 77 url_fetcher_->SetUploadData(upload_type, upload_data); | 78 url_fetcher_->SetUploadData(upload_type, upload_data); |
| 78 } | 79 } |
| 79 | 80 |
| 81 data_use_measurement::DataUseUserData::AttachToFetcher( |
| 82 url_fetcher_.get(), data_use_measurement::DataUseUserData::CLOUD_PRINT); |
| 80 url_fetcher_->SetRequestContext(request_context_.get()); | 83 url_fetcher_->SetRequestContext(request_context_.get()); |
| 81 | 84 |
| 82 std::vector<std::string> extra_headers = request_->GetExtraRequestHeaders(); | 85 std::vector<std::string> extra_headers = request_->GetExtraRequestHeaders(); |
| 83 for (size_t i = 0; i < extra_headers.size(); ++i) | 86 for (size_t i = 0; i < extra_headers.size(); ++i) |
| 84 url_fetcher_->AddExtraRequestHeader(extra_headers[i]); | 87 url_fetcher_->AddExtraRequestHeader(extra_headers[i]); |
| 85 } | 88 } |
| 86 | 89 |
| 87 void GCDApiFlowImpl::OnURLFetchComplete(const net::URLFetcher* source) { | 90 void GCDApiFlowImpl::OnURLFetchComplete(const net::URLFetcher* source) { |
| 88 // TODO(noamsml): Error logging. | 91 // TODO(noamsml): Error logging. |
| 89 | 92 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 108 | 111 |
| 109 if (!value || !value->GetAsDictionary(&dictionary_value)) { | 112 if (!value || !value->GetAsDictionary(&dictionary_value)) { |
| 110 request_->OnGCDApiFlowError(ERROR_MALFORMED_RESPONSE); | 113 request_->OnGCDApiFlowError(ERROR_MALFORMED_RESPONSE); |
| 111 return; | 114 return; |
| 112 } | 115 } |
| 113 | 116 |
| 114 request_->OnGCDApiFlowComplete(*dictionary_value); | 117 request_->OnGCDApiFlowComplete(*dictionary_value); |
| 115 } | 118 } |
| 116 | 119 |
| 117 } // namespace cloud_print | 120 } // namespace cloud_print |
| OLD | NEW |