| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/gaia/service_gaia_authenticator.h" | 5 #include "chrome/service/gaia/service_gaia_authenticator.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop_proxy.h" | 8 #include "base/message_loop_proxy.h" |
| 9 #include "chrome/service/net/service_url_request_context.h" | 9 #include "chrome/service/net/service_url_request_context.h" |
| 10 #include "chrome/service/service_process.h" | 10 #include "chrome/service/service_process.h" |
| 11 #include "content/public/common/content_url_request_user_data.h" |
| 11 #include "content/public/common/url_fetcher.h" | 12 #include "content/public/common/url_fetcher.h" |
| 12 #include "googleurl/src/gurl.h" | 13 #include "googleurl/src/gurl.h" |
| 13 | 14 |
| 14 ServiceGaiaAuthenticator::ServiceGaiaAuthenticator( | 15 ServiceGaiaAuthenticator::ServiceGaiaAuthenticator( |
| 15 const std::string& user_agent, const std::string& service_id, | 16 const std::string& user_agent, const std::string& service_id, |
| 16 const std::string& gaia_url, | 17 const std::string& gaia_url, |
| 17 base::MessageLoopProxy* io_message_loop_proxy) | 18 base::MessageLoopProxy* io_message_loop_proxy) |
| 18 : gaia::GaiaAuthenticator(user_agent, service_id, gaia_url), | 19 : gaia::GaiaAuthenticator(user_agent, service_id, gaia_url), |
| 19 http_post_completed_(false, false), | 20 http_post_completed_(false, false), |
| 20 io_message_loop_proxy_(io_message_loop_proxy), | 21 io_message_loop_proxy_(io_message_loop_proxy), |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 return ret; | 62 return ret; |
| 62 } | 63 } |
| 63 | 64 |
| 64 void ServiceGaiaAuthenticator::DoPost(const GURL& post_url, | 65 void ServiceGaiaAuthenticator::DoPost(const GURL& post_url, |
| 65 const std::string& post_body) { | 66 const std::string& post_body) { |
| 66 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 67 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
| 67 content::URLFetcher* request = content::URLFetcher::Create( | 68 content::URLFetcher* request = content::URLFetcher::Create( |
| 68 post_url, content::URLFetcher::POST, this); | 69 post_url, content::URLFetcher::POST, this); |
| 69 request->SetRequestContext( | 70 request->SetRequestContext( |
| 70 g_service_process->GetServiceURLRequestContextGetter()); | 71 g_service_process->GetServiceURLRequestContextGetter()); |
| 72 // TODO(jochen): Do cookie audit. |
| 73 request->SetContentURLRequestUserData( |
| 74 new content::ContentURLRequestUserData()); |
| 71 request->SetUploadData("application/x-www-form-urlencoded", post_body); | 75 request->SetUploadData("application/x-www-form-urlencoded", post_body); |
| 72 request->Start(); | 76 request->Start(); |
| 73 } | 77 } |
| 74 | 78 |
| 75 // content::URLFetcherDelegate implementation | 79 // content::URLFetcherDelegate implementation |
| 76 void ServiceGaiaAuthenticator::OnURLFetchComplete( | 80 void ServiceGaiaAuthenticator::OnURLFetchComplete( |
| 77 const content::URLFetcher* source) { | 81 const content::URLFetcher* source) { |
| 78 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 82 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
| 79 http_response_code_ = source->GetResponseCode(); | 83 http_response_code_ = source->GetResponseCode(); |
| 80 source->GetResponseAsString(&response_data_); | 84 source->GetResponseAsString(&response_data_); |
| 81 delete source; | 85 delete source; |
| 82 // Add an extra reference because we want http_post_completed_ to remain | 86 // Add an extra reference because we want http_post_completed_ to remain |
| 83 // valid until after Signal() returns. | 87 // valid until after Signal() returns. |
| 84 scoped_refptr<ServiceGaiaAuthenticator> keep_alive(this); | 88 scoped_refptr<ServiceGaiaAuthenticator> keep_alive(this); |
| 85 // Wake the blocked thread in Post. | 89 // Wake the blocked thread in Post. |
| 86 http_post_completed_.Signal(); | 90 http_post_completed_.Signal(); |
| 87 // WARNING: DONT DO ANYTHING AFTER THIS CALL! |this| may be deleted! | 91 // WARNING: DONT DO ANYTHING AFTER THIS CALL! |this| may be deleted! |
| 88 } | 92 } |
| OLD | NEW |