Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: sync/internal_api/http_bridge.cc

Issue 195973002: Change DCHECK_IS_ON() to DCHECK_IS_ON (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Keep a comment Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/spdy/spdy_write_queue.cc ('k') | ui/gfx/font_list_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 "sync/internal_api/public/http_bridge.h" 5 #include "sync/internal_api/public/http_bridge.h"
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/message_loop/message_loop_proxy.h" 8 #include "base/message_loop/message_loop_proxy.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "net/base/load_flags.h" 10 #include "net/base/load_flags.h"
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 HttpBridge::~HttpBridge() { 191 HttpBridge::~HttpBridge() {
192 } 192 }
193 193
194 void HttpBridge::SetExtraRequestHeaders(const char * headers) { 194 void HttpBridge::SetExtraRequestHeaders(const char * headers) {
195 DCHECK(extra_headers_.empty()) 195 DCHECK(extra_headers_.empty())
196 << "HttpBridge::SetExtraRequestHeaders called twice."; 196 << "HttpBridge::SetExtraRequestHeaders called twice.";
197 extra_headers_.assign(headers); 197 extra_headers_.assign(headers);
198 } 198 }
199 199
200 void HttpBridge::SetURL(const char* url, int port) { 200 void HttpBridge::SetURL(const char* url, int port) {
201 #if DCHECK_IS_ON
201 DCHECK_EQ(base::MessageLoop::current(), created_on_loop_); 202 DCHECK_EQ(base::MessageLoop::current(), created_on_loop_);
202 if (DCHECK_IS_ON()) { 203 {
203 base::AutoLock lock(fetch_state_lock_); 204 base::AutoLock lock(fetch_state_lock_);
204 DCHECK(!fetch_state_.request_completed); 205 DCHECK(!fetch_state_.request_completed);
205 } 206 }
206 DCHECK(url_for_request_.is_empty()) 207 DCHECK(url_for_request_.is_empty())
207 << "HttpBridge::SetURL called more than once?!"; 208 << "HttpBridge::SetURL called more than once?!";
209 #endif
208 GURL temp(url); 210 GURL temp(url);
209 GURL::Replacements replacements; 211 GURL::Replacements replacements;
210 std::string port_str = base::IntToString(port); 212 std::string port_str = base::IntToString(port);
211 replacements.SetPort(port_str.c_str(), 213 replacements.SetPort(port_str.c_str(),
212 url_parse::Component(0, port_str.length())); 214 url_parse::Component(0, port_str.length()));
213 url_for_request_ = temp.ReplaceComponents(replacements); 215 url_for_request_ = temp.ReplaceComponents(replacements);
214 } 216 }
215 217
216 void HttpBridge::SetPostPayload(const char* content_type, 218 void HttpBridge::SetPostPayload(const char* content_type,
217 int content_length, 219 int content_length,
218 const char* content) { 220 const char* content) {
221 #if DCHECK_IS_ON
219 DCHECK_EQ(base::MessageLoop::current(), created_on_loop_); 222 DCHECK_EQ(base::MessageLoop::current(), created_on_loop_);
220 if (DCHECK_IS_ON()) { 223 {
221 base::AutoLock lock(fetch_state_lock_); 224 base::AutoLock lock(fetch_state_lock_);
222 DCHECK(!fetch_state_.request_completed); 225 DCHECK(!fetch_state_.request_completed);
223 } 226 }
224 DCHECK(content_type_.empty()) << "Bridge payload already set."; 227 DCHECK(content_type_.empty()) << "Bridge payload already set.";
225 DCHECK_GE(content_length, 0) << "Content length < 0"; 228 DCHECK_GE(content_length, 0) << "Content length < 0";
229 #endif
226 content_type_ = content_type; 230 content_type_ = content_type;
227 if (!content || (content_length == 0)) { 231 if (!content || (content_length == 0)) {
228 DCHECK_EQ(content_length, 0); 232 DCHECK_EQ(content_length, 0);
229 request_content_ = " "; // TODO(timsteele): URLFetcher requires non-empty 233 request_content_ = " "; // TODO(timsteele): URLFetcher requires non-empty
230 // content for POSTs whereas CURL does not, for now 234 // content for POSTs whereas CURL does not, for now
231 // we hack this to support the sync backend. 235 // we hack this to support the sync backend.
232 } else { 236 } else {
233 request_content_.assign(content, content_length); 237 request_content_.assign(content, content_length);
234 } 238 }
235 } 239 }
236 240
237 bool HttpBridge::MakeSynchronousPost(int* error_code, int* response_code) { 241 bool HttpBridge::MakeSynchronousPost(int* error_code, int* response_code) {
242 #if DCHECK_IS_ON
238 DCHECK_EQ(base::MessageLoop::current(), created_on_loop_); 243 DCHECK_EQ(base::MessageLoop::current(), created_on_loop_);
239 if (DCHECK_IS_ON()) { 244 {
240 base::AutoLock lock(fetch_state_lock_); 245 base::AutoLock lock(fetch_state_lock_);
241 DCHECK(!fetch_state_.request_completed); 246 DCHECK(!fetch_state_.request_completed);
242 } 247 }
243 DCHECK(url_for_request_.is_valid()) << "Invalid URL for request"; 248 DCHECK(url_for_request_.is_valid()) << "Invalid URL for request";
244 DCHECK(!content_type_.empty()) << "Payload not set"; 249 DCHECK(!content_type_.empty()) << "Payload not set";
250 #endif
245 251
246 if (!network_task_runner_->PostTask( 252 if (!network_task_runner_->PostTask(
247 FROM_HERE, 253 FROM_HERE,
248 base::Bind(&HttpBridge::CallMakeAsynchronousPost, this))) { 254 base::Bind(&HttpBridge::CallMakeAsynchronousPost, this))) {
249 // This usually happens when we're in a unit test. 255 // This usually happens when we're in a unit test.
250 LOG(WARNING) << "Could not post CallMakeAsynchronousPost task"; 256 LOG(WARNING) << "Could not post CallMakeAsynchronousPost task";
251 return false; 257 return false;
252 } 258 }
253 259
254 // Block until network request completes or is aborted. See 260 // Block until network request completes or is aborted. See
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 int64 sane_time_ms = 0; 394 int64 sane_time_ms = 0;
389 if (base::StringToInt64(sane_time_str, &sane_time_ms)) { 395 if (base::StringToInt64(sane_time_str, &sane_time_ms)) {
390 network_time_update_callback_.Run( 396 network_time_update_callback_.Run(
391 base::Time::FromJsTime(sane_time_ms), 397 base::Time::FromJsTime(sane_time_ms),
392 base::TimeDelta::FromMilliseconds(1), 398 base::TimeDelta::FromMilliseconds(1),
393 fetch_state_.end_time - fetch_state_.start_time); 399 fetch_state_.end_time - fetch_state_.start_time);
394 } 400 }
395 } 401 }
396 402
397 } // namespace syncer 403 } // namespace syncer
OLDNEW
« no previous file with comments | « net/spdy/spdy_write_queue.cc ('k') | ui/gfx/font_list_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698