| 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/local_discovery/gcd_api_flow.h" | 5 #include "chrome/browser/local_discovery/gcd_api_flow.h" |
| 6 | 6 |
| 7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "chrome/browser/local_discovery/gcd_constants.h" | 11 #include "chrome/browser/local_discovery/gcd_constants.h" |
| 12 #include "chrome/common/cloud_print/cloud_print_constants.h" | 12 #include "chrome/common/cloud_print/cloud_print_constants.h" |
| 13 #include "components/cloud_devices/common/cloud_devices_urls.h" | 13 #include "components/cloud_devices/common/cloud_devices_urls.h" |
| 14 #include "google_apis/gaia/google_service_auth_error.h" | 14 #include "google_apis/gaia/google_service_auth_error.h" |
| 15 #include "net/base/load_flags.h" | 15 #include "net/base/load_flags.h" |
| 16 #include "net/base/url_util.h" | 16 #include "net/base/url_util.h" |
| 17 #include "net/http/http_status_code.h" | 17 #include "net/http/http_status_code.h" |
| 18 #include "net/url_request/url_request_status.h" | 18 #include "net/url_request/url_request_status.h" |
| 19 | 19 |
| 20 namespace local_discovery { | 20 namespace local_discovery { |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 const char kCloudPrintOAuthHeaderFormat[] = "Authorization: Bearer %s"; | 23 const char kCloudPrintOAuthHeaderFormat[] = "Authorization: Bearer %s"; |
| 24 } | 24 } |
| 25 | 25 |
| 26 GCDApiFlow::Request::Request() { | 26 GCDApiFlowInterface::Request::Request() { |
| 27 } | 27 } |
| 28 | 28 |
| 29 GCDApiFlow::Request::~Request() { | 29 GCDApiFlowInterface::Request::~Request() { |
| 30 } | 30 } |
| 31 | 31 |
| 32 net::URLFetcher::RequestType GCDApiFlow::Request::GetRequestType() { | 32 net::URLFetcher::RequestType GCDApiFlowInterface::Request::GetRequestType() { |
| 33 return net::URLFetcher::GET; | 33 return net::URLFetcher::GET; |
| 34 } | 34 } |
| 35 | 35 |
| 36 void GCDApiFlow::Request::GetUploadData(std::string* upload_type, | 36 void GCDApiFlowInterface::Request::GetUploadData(std::string* upload_type, |
| 37 std::string* upload_data) { | 37 std::string* upload_data) { |
| 38 *upload_type = std::string(); | 38 *upload_type = std::string(); |
| 39 *upload_data = std::string(); | 39 *upload_data = std::string(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 GCDApiFlowInterface::GCDApiFlowInterface() { |
| 43 } |
| 44 |
| 45 GCDApiFlowInterface::~GCDApiFlowInterface() { |
| 46 } |
| 47 |
| 42 GCDApiFlow::GCDApiFlow(net::URLRequestContextGetter* request_context, | 48 GCDApiFlow::GCDApiFlow(net::URLRequestContextGetter* request_context, |
| 43 OAuth2TokenService* token_service, | 49 OAuth2TokenService* token_service, |
| 44 const std::string& account_id, | 50 const std::string& account_id) |
| 45 scoped_ptr<Request> delegate) | |
| 46 : OAuth2TokenService::Consumer("cloud_print"), | 51 : OAuth2TokenService::Consumer("cloud_print"), |
| 47 request_context_(request_context), | 52 request_context_(request_context), |
| 48 token_service_(token_service), | 53 token_service_(token_service), |
| 49 account_id_(account_id), | 54 account_id_(account_id) { |
| 50 request_(delegate.Pass()) { | |
| 51 } | 55 } |
| 52 | 56 |
| 53 GCDApiFlow::~GCDApiFlow() { | 57 GCDApiFlow::~GCDApiFlow() { |
| 54 } | 58 } |
| 55 | 59 |
| 56 void GCDApiFlow::Start() { | 60 void GCDApiFlow::Start(scoped_ptr<Request> request) { |
| 61 request_ = request.Pass(); |
| 57 OAuth2TokenService::ScopeSet oauth_scopes; | 62 OAuth2TokenService::ScopeSet oauth_scopes; |
| 58 oauth_scopes.insert(request_->GetOAuthScope()); | 63 oauth_scopes.insert(request_->GetOAuthScope()); |
| 59 oauth_request_ = | 64 oauth_request_ = |
| 60 token_service_->StartRequest(account_id_, oauth_scopes, this); | 65 token_service_->StartRequest(account_id_, oauth_scopes, this); |
| 61 } | 66 } |
| 62 | 67 |
| 63 void GCDApiFlow::OnGetTokenSuccess(const OAuth2TokenService::Request* request, | 68 void GCDApiFlow::OnGetTokenSuccess(const OAuth2TokenService::Request* request, |
| 64 const std::string& access_token, | 69 const std::string& access_token, |
| 65 const base::Time& expiration_time) { | 70 const base::Time& expiration_time) { |
| 66 CreateRequest(request_->GetURL()); | 71 CreateRequest(request_->GetURL()); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 | 155 |
| 151 std::string CloudPrintApiFlowRequest::GetOAuthScope() { | 156 std::string CloudPrintApiFlowRequest::GetOAuthScope() { |
| 152 return cloud_devices::kCloudPrintAuthScope; | 157 return cloud_devices::kCloudPrintAuthScope; |
| 153 } | 158 } |
| 154 | 159 |
| 155 std::vector<std::string> CloudPrintApiFlowRequest::GetExtraRequestHeaders() { | 160 std::vector<std::string> CloudPrintApiFlowRequest::GetExtraRequestHeaders() { |
| 156 return std::vector<std::string>(1, cloud_print::kChromeCloudPrintProxyHeader); | 161 return std::vector<std::string>(1, cloud_print::kChromeCloudPrintProxyHeader); |
| 157 } | 162 } |
| 158 | 163 |
| 159 } // namespace local_discovery | 164 } // namespace local_discovery |
| OLD | NEW |