| 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/browser/sync/glue/http_bridge.h" | 5 #include "chrome/browser/sync/glue/http_bridge.h" |
| 6 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/message_loop_proxy.h" | 8 #include "base/message_loop_proxy.h" |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "content/browser/browser_thread.h" | 10 #include "content/browser/browser_thread.h" |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 request_content_.assign(content, content_length); | 167 request_content_.assign(content, content_length); |
| 168 } | 168 } |
| 169 } | 169 } |
| 170 | 170 |
| 171 bool HttpBridge::MakeSynchronousPost(int* os_error_code, int* response_code) { | 171 bool HttpBridge::MakeSynchronousPost(int* os_error_code, int* response_code) { |
| 172 DCHECK_EQ(MessageLoop::current(), created_on_loop_); | 172 DCHECK_EQ(MessageLoop::current(), created_on_loop_); |
| 173 DCHECK(!request_completed_); | 173 DCHECK(!request_completed_); |
| 174 DCHECK(url_for_request_.is_valid()) << "Invalid URL for request"; | 174 DCHECK(url_for_request_.is_valid()) << "Invalid URL for request"; |
| 175 DCHECK(!content_type_.empty()) << "Payload not set"; | 175 DCHECK(!content_type_.empty()) << "Payload not set"; |
| 176 | 176 |
| 177 BrowserThread::PostTask( | 177 if (!BrowserThread::PostTask( |
| 178 BrowserThread::IO, FROM_HERE, | 178 BrowserThread::IO, FROM_HERE, |
| 179 NewRunnableMethod(this, &HttpBridge::CallMakeAsynchronousPost)); | 179 NewRunnableMethod(this, &HttpBridge::CallMakeAsynchronousPost))) { |
| 180 // This usually happens when we're in a unit test. |
| 181 LOG(WARNING) << "Could not post CallMakeAsynchronousPost task"; |
| 182 return false; |
| 183 } |
| 180 | 184 |
| 181 if (!http_post_completed_.Wait()) // Block until network request completes. | 185 if (!http_post_completed_.Wait()) // Block until network request completes. |
| 182 NOTREACHED(); // See OnURLFetchComplete. | 186 NOTREACHED(); // See OnURLFetchComplete. |
| 183 | 187 |
| 184 DCHECK(request_completed_); | 188 DCHECK(request_completed_); |
| 185 *os_error_code = os_error_code_; | 189 *os_error_code = os_error_code_; |
| 186 *response_code = http_response_code_; | 190 *response_code = http_response_code_; |
| 187 return request_succeeded_; | 191 return request_succeeded_; |
| 188 } | 192 } |
| 189 | 193 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 // URLFetcher, so it seems most natural / "polite" to let the stack unwind. | 246 // URLFetcher, so it seems most natural / "polite" to let the stack unwind. |
| 243 MessageLoop::current()->DeleteSoon(FROM_HERE, url_poster_); | 247 MessageLoop::current()->DeleteSoon(FROM_HERE, url_poster_); |
| 244 url_poster_ = NULL; | 248 url_poster_ = NULL; |
| 245 | 249 |
| 246 // Wake the blocked syncer thread in MakeSynchronousPost. | 250 // Wake the blocked syncer thread in MakeSynchronousPost. |
| 247 // WARNING: DONT DO ANYTHING AFTER THIS CALL! |this| may be deleted! | 251 // WARNING: DONT DO ANYTHING AFTER THIS CALL! |this| may be deleted! |
| 248 http_post_completed_.Signal(); | 252 http_post_completed_.Signal(); |
| 249 } | 253 } |
| 250 | 254 |
| 251 } // namespace browser_sync | 255 } // namespace browser_sync |
| OLD | NEW |