| 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 "components/data_use_measurement/core/data_use_user_data.h" |
| 20 #include "google_apis/gaia/google_service_auth_error.h" | 20 #include "google_apis/gaia/google_service_auth_error.h" |
| 21 #include "net/base/load_flags.h" | 21 #include "net/base/load_flags.h" |
| 22 #include "net/base/url_util.h" | 22 #include "net/base/url_util.h" |
| 23 #include "net/http/http_status_code.h" | 23 #include "net/http/http_status_code.h" |
| 24 #include "net/url_request/url_request_status.h" | 24 #include "net/url_request/url_request_status.h" |
| 25 | 25 |
| 26 namespace cloud_print { | 26 namespace cloud_print { |
| 27 | 27 |
| 28 namespace { |
| 29 const char kCloudPrintOAuthHeaderFormat[] = "Authorization: Bearer %s"; |
| 30 } // namespace |
| 31 |
| 28 GCDApiFlowImpl::GCDApiFlowImpl(net::URLRequestContextGetter* request_context, | 32 GCDApiFlowImpl::GCDApiFlowImpl(net::URLRequestContextGetter* request_context, |
| 29 OAuth2TokenService* token_service, | 33 OAuth2TokenService* token_service, |
| 30 const std::string& account_id) | 34 const std::string& account_id) |
| 31 : OAuth2TokenService::Consumer("cloud_print"), | 35 : OAuth2TokenService::Consumer("cloud_print"), |
| 32 request_context_(request_context), | 36 request_context_(request_context), |
| 33 token_service_(token_service), | 37 token_service_(token_service), |
| 34 account_id_(account_id) { | 38 account_id_(account_id) { |
| 35 } | 39 } |
| 36 | 40 |
| 37 GCDApiFlowImpl::~GCDApiFlowImpl() { | 41 GCDApiFlowImpl::~GCDApiFlowImpl() { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 61 } | 65 } |
| 62 | 66 |
| 63 void GCDApiFlowImpl::OnGetTokenFailure( | 67 void GCDApiFlowImpl::OnGetTokenFailure( |
| 64 const OAuth2TokenService::Request* request, | 68 const OAuth2TokenService::Request* request, |
| 65 const GoogleServiceAuthError& error) { | 69 const GoogleServiceAuthError& error) { |
| 66 request_->OnGCDApiFlowError(ERROR_TOKEN); | 70 request_->OnGCDApiFlowError(ERROR_TOKEN); |
| 67 } | 71 } |
| 68 | 72 |
| 69 void GCDApiFlowImpl::CreateRequest(const GURL& url) { | 73 void GCDApiFlowImpl::CreateRequest(const GURL& url) { |
| 70 net::URLFetcher::RequestType request_type = request_->GetRequestType(); | 74 net::URLFetcher::RequestType request_type = request_->GetRequestType(); |
| 75 DCHECK_EQ(net::URLFetcher::GET, request_type); |
| 71 | 76 |
| 72 url_fetcher_ = net::URLFetcher::Create(url, request_type, this); | 77 url_fetcher_ = net::URLFetcher::Create(url, request_type, this); |
| 73 | 78 |
| 74 if (request_type != net::URLFetcher::GET) { | |
| 75 std::string upload_type; | |
| 76 std::string upload_data; | |
| 77 request_->GetUploadData(&upload_type, &upload_data); | |
| 78 url_fetcher_->SetUploadData(upload_type, upload_data); | |
| 79 } | |
| 80 | |
| 81 data_use_measurement::DataUseUserData::AttachToFetcher( | 79 data_use_measurement::DataUseUserData::AttachToFetcher( |
| 82 url_fetcher_.get(), data_use_measurement::DataUseUserData::CLOUD_PRINT); | 80 url_fetcher_.get(), data_use_measurement::DataUseUserData::CLOUD_PRINT); |
| 83 url_fetcher_->SetRequestContext(request_context_.get()); | 81 url_fetcher_->SetRequestContext(request_context_.get()); |
| 84 | 82 |
| 85 std::vector<std::string> extra_headers = request_->GetExtraRequestHeaders(); | 83 std::vector<std::string> extra_headers = request_->GetExtraRequestHeaders(); |
| 86 for (size_t i = 0; i < extra_headers.size(); ++i) | 84 for (size_t i = 0; i < extra_headers.size(); ++i) |
| 87 url_fetcher_->AddExtraRequestHeader(extra_headers[i]); | 85 url_fetcher_->AddExtraRequestHeader(extra_headers[i]); |
| 88 } | 86 } |
| 89 | 87 |
| 90 void GCDApiFlowImpl::OnURLFetchComplete(const net::URLFetcher* source) { | 88 void GCDApiFlowImpl::OnURLFetchComplete(const net::URLFetcher* source) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 111 | 109 |
| 112 if (!value || !value->GetAsDictionary(&dictionary_value)) { | 110 if (!value || !value->GetAsDictionary(&dictionary_value)) { |
| 113 request_->OnGCDApiFlowError(ERROR_MALFORMED_RESPONSE); | 111 request_->OnGCDApiFlowError(ERROR_MALFORMED_RESPONSE); |
| 114 return; | 112 return; |
| 115 } | 113 } |
| 116 | 114 |
| 117 request_->OnGCDApiFlowComplete(*dictionary_value); | 115 request_->OnGCDApiFlowComplete(*dictionary_value); |
| 118 } | 116 } |
| 119 | 117 |
| 120 } // namespace cloud_print | 118 } // namespace cloud_print |
| OLD | NEW |