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