Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/json/json_reader.h" | 5 #include "base/json/json_reader.h" |
| 6 #include "base/strings/stringprintf.h" | 6 #include "base/strings/stringprintf.h" |
| 7 #include "base/values.h" | 7 #include "base/values.h" |
| 8 #include "chrome/browser/local_discovery/cloud_print_base_api_flow.h" | 8 #include "chrome/browser/local_discovery/cloud_print_base_api_flow.h" |
| 9 #include "chrome/common/cloud_print/cloud_print_constants.h" | 9 #include "chrome/common/cloud_print/cloud_print_constants.h" |
| 10 #include "google_apis/gaia/google_service_auth_error.h" | 10 #include "google_apis/gaia/google_service_auth_error.h" |
| 11 #include "net/base/load_flags.h" | 11 #include "net/base/load_flags.h" |
| 12 #include "net/http/http_status_code.h" | 12 #include "net/http/http_status_code.h" |
| 13 #include "net/url_request/url_request_status.h" | 13 #include "net/url_request/url_request_status.h" |
| 14 | 14 |
| 15 namespace local_discovery { | 15 namespace local_discovery { |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 const char kCloudPrintOAuthHeaderFormat[] = "Authorization: Bearer %s"; | 18 const char kCloudPrintOAuthHeaderFormat[] = "Authorization: Bearer %s"; |
| 19 const char kCookieURLFormat[] = "%s%cxsrf=%s&user=%d"; | 19 const char kCookieURLFormat[] = "%s%cxsrf=%s&user=%d"; |
| 20 const char kCookieURLFormatNoXSRF[] = "%s%cuser=%d"; | 20 const char kCookieURLFormatNoXSRF[] = "%s%cuser=%d"; |
| 21 } | 21 } |
| 22 | 22 |
| 23 CloudPrintBaseApiFlow::CloudPrintBaseApiFlow( | 23 CloudPrintBaseApiFlow::CloudPrintBaseApiFlow( |
| 24 net::URLRequestContextGetter* request_context, | 24 net::URLRequestContextGetter* request_context, |
| 25 OAuth2TokenService* token_service, | 25 OAuth2TokenService* token_service, |
| 26 const GURL& automated_claim_url, | 26 const GURL& automated_claim_url, |
| 27 Delegate* delegate) | 27 Delegate* delegate) |
| 28 : request_context_(request_context), | 28 : request_context_(request_context), |
| 29 token_service_(token_service), | 29 token_service_(token_service), |
| 30 user_index_(kAccountIndexUseOAuth2), | |
| 30 url_(automated_claim_url), | 31 url_(automated_claim_url), |
| 31 delegate_(delegate) { | 32 delegate_(delegate) { |
| 32 } | 33 } |
| 33 | 34 |
| 34 CloudPrintBaseApiFlow::CloudPrintBaseApiFlow( | 35 CloudPrintBaseApiFlow::CloudPrintBaseApiFlow( |
| 35 net::URLRequestContextGetter* request_context, | 36 net::URLRequestContextGetter* request_context, |
| 36 int user_index, | 37 int user_index, |
| 37 const std::string& xsrf_token, | 38 const std::string& xsrf_token, |
| 38 const GURL& automated_claim_url, | 39 const GURL& automated_claim_url, |
| 39 Delegate* delegate) | 40 Delegate* delegate) |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 62 | 63 |
| 63 void CloudPrintBaseApiFlow::Start() { | 64 void CloudPrintBaseApiFlow::Start() { |
| 64 if (UseOAuth2()) { | 65 if (UseOAuth2()) { |
| 65 OAuth2TokenService::ScopeSet oauth_scopes; | 66 OAuth2TokenService::ScopeSet oauth_scopes; |
| 66 oauth_scopes.insert(cloud_print::kCloudPrintAuth); | 67 oauth_scopes.insert(cloud_print::kCloudPrintAuth); |
| 67 oauth_request_ = token_service_->StartRequest(oauth_scopes, this); | 68 oauth_request_ = token_service_->StartRequest(oauth_scopes, this); |
| 68 } else { | 69 } else { |
| 69 GURL cookie_url; | 70 GURL cookie_url; |
| 70 | 71 |
| 71 char separator_character = '?'; | 72 char separator_character = '?'; |
| 72 if (url_.spec().find_first_of('?') == std::string::npos) { | 73 if (url_.spec().find_first_of('?') != std::string::npos) { |
| 73 separator_character = '&' | 74 separator_character = '&'; |
| 74 } | 75 } |
| 75 | 76 |
| 76 if (xsrf_token_.empty()) { | 77 if (xsrf_token_.empty()) { |
| 77 cookie_url = GURL(base::StringPrintf(kCookieURLFormatNoXSRF, | 78 cookie_url = GURL(base::StringPrintf(kCookieURLFormatNoXSRF, |
| 78 url_.spec().c_str(), | 79 url_.spec().c_str(), |
| 80 separator_character, | |
|
Vitaly Buka (NO REVIEWS)
2013/09/04 21:46:25
Please use net::AppendQueryParameter(
Noam Samuel
2013/09/05 23:08:31
Done.
| |
| 79 user_index_)); | 81 user_index_)); |
| 80 } else { | 82 } else { |
| 81 cookie_url = GURL(base::StringPrintf(kCookieURLFormat, | 83 cookie_url = GURL(base::StringPrintf(kCookieURLFormat, |
| 82 url_.spec().c_str(), | 84 url_.spec().c_str(), |
| 85 separator_character, | |
| 83 xsrf_token_.c_str(), | 86 xsrf_token_.c_str(), |
| 84 user_index_)); | 87 user_index_)); |
| 85 } | 88 } |
| 86 | 89 |
| 87 CreateRequest(cookie_url); | 90 CreateRequest(cookie_url); |
| 88 | 91 |
| 89 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES); | 92 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES); |
| 90 | 93 |
| 91 url_fetcher_->Start(); | 94 url_fetcher_->Start(); |
| 92 } | 95 } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 149 | 152 |
| 150 if (!value.get() || !value->GetAsDictionary(&dictionary_value)) { | 153 if (!value.get() || !value->GetAsDictionary(&dictionary_value)) { |
| 151 delegate_->OnCloudPrintAPIFlowError(this, ERROR_MALFORMED_RESPONSE); | 154 delegate_->OnCloudPrintAPIFlowError(this, ERROR_MALFORMED_RESPONSE); |
| 152 return; | 155 return; |
| 153 } | 156 } |
| 154 | 157 |
| 155 delegate_->OnCloudPrintAPIFlowComplete(this, dictionary_value); | 158 delegate_->OnCloudPrintAPIFlowComplete(this, dictionary_value); |
| 156 } | 159 } |
| 157 | 160 |
| 158 } // namespace local_discovery | 161 } // namespace local_discovery |
| OLD | NEW |