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/message_loop_proxy.h" | 8 #include "base/message_loop_proxy.h" |
8 #include "chrome/service/net/service_url_request_context.h" | 9 #include "chrome/service/net/service_url_request_context.h" |
9 #include "chrome/service/service_process.h" | 10 #include "chrome/service/service_process.h" |
10 #include "content/public/common/url_fetcher.h" | 11 #include "content/public/common/url_fetcher.h" |
11 #include "googleurl/src/gurl.h" | 12 #include "googleurl/src/gurl.h" |
12 | 13 |
13 ServiceGaiaAuthenticator::ServiceGaiaAuthenticator( | 14 ServiceGaiaAuthenticator::ServiceGaiaAuthenticator( |
14 const std::string& user_agent, const std::string& service_id, | 15 const std::string& user_agent, const std::string& service_id, |
15 const std::string& gaia_url, | 16 const std::string& gaia_url, |
16 base::MessageLoopProxy* io_message_loop_proxy) | 17 base::MessageLoopProxy* io_message_loop_proxy) |
17 : gaia::GaiaAuthenticator(user_agent, service_id, gaia_url), | 18 : gaia::GaiaAuthenticator(user_agent, service_id, gaia_url), |
18 http_post_completed_(false, false), | 19 http_post_completed_(false, false), |
19 io_message_loop_proxy_(io_message_loop_proxy), | 20 io_message_loop_proxy_(io_message_loop_proxy), |
20 http_response_code_(0) { | 21 http_response_code_(0) { |
21 } | 22 } |
22 | 23 |
23 ServiceGaiaAuthenticator::~ServiceGaiaAuthenticator() { | 24 ServiceGaiaAuthenticator::~ServiceGaiaAuthenticator() { |
24 } | 25 } |
25 | 26 |
26 bool ServiceGaiaAuthenticator::Post(const GURL& url, | 27 bool ServiceGaiaAuthenticator::Post(const GURL& url, |
27 const std::string& post_body, | 28 const std::string& post_body, |
28 unsigned long* response_code, | 29 unsigned long* response_code, |
29 std::string* response_body) { | 30 std::string* response_body) { |
30 DCHECK(url.SchemeIsSecure()); | 31 DCHECK(url.SchemeIsSecure()); |
31 DCHECK(io_message_loop_proxy_); | 32 DCHECK(io_message_loop_proxy_); |
32 io_message_loop_proxy_->PostTask( | 33 io_message_loop_proxy_->PostTask( |
33 FROM_HERE, | 34 FROM_HERE, |
34 NewRunnableMethod(this, &ServiceGaiaAuthenticator::DoPost, url, | 35 base::Bind(&ServiceGaiaAuthenticator::DoPost, this, url, post_body)); |
35 post_body)); | |
36 // TODO(sanjeevr): Waiting here until the network request completes is not | 36 // TODO(sanjeevr): Waiting here until the network request completes is not |
37 // desirable. We need to change Post to be asynchronous. | 37 // desirable. We need to change Post to be asynchronous. |
38 // Block until network request completes. See OnURLFetchComplete. | 38 // Block until network request completes. See OnURLFetchComplete. |
39 http_post_completed_.Wait(); | 39 http_post_completed_.Wait(); |
40 | 40 |
41 *response_code = static_cast<int>(http_response_code_); | 41 *response_code = static_cast<int>(http_response_code_); |
42 *response_body = response_data_; | 42 *response_body = response_data_; |
43 return true; | 43 return true; |
44 } | 44 } |
45 | 45 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 http_response_code_ = source->GetResponseCode(); | 79 http_response_code_ = source->GetResponseCode(); |
80 source->GetResponseAsString(&response_data_); | 80 source->GetResponseAsString(&response_data_); |
81 delete source; | 81 delete source; |
82 // 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 |
83 // valid until after Signal() returns. | 83 // valid until after Signal() returns. |
84 scoped_refptr<ServiceGaiaAuthenticator> keep_alive(this); | 84 scoped_refptr<ServiceGaiaAuthenticator> keep_alive(this); |
85 // Wake the blocked thread in Post. | 85 // Wake the blocked thread in Post. |
86 http_post_completed_.Signal(); | 86 http_post_completed_.Signal(); |
87 // WARNING: DONT DO ANYTHING AFTER THIS CALL! |this| may be deleted! | 87 // WARNING: DONT DO ANYTHING AFTER THIS CALL! |this| may be deleted! |
88 } | 88 } |
OLD | NEW |