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

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

Issue 16298002: Update sync/, sql/, and printing/ to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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 | « sync/engine/model_changing_syncer_command.cc ('k') | sync/internal_api/http_bridge_unittest.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.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 "net/base/load_flags.h" 10 #include "net/base/load_flags.h"
(...skipping 11 matching lines...) Expand all
22 22
23 namespace syncer { 23 namespace syncer {
24 24
25 HttpBridge::RequestContextGetter::RequestContextGetter( 25 HttpBridge::RequestContextGetter::RequestContextGetter(
26 net::URLRequestContextGetter* baseline_context_getter, 26 net::URLRequestContextGetter* baseline_context_getter,
27 const std::string& user_agent) 27 const std::string& user_agent)
28 : baseline_context_getter_(baseline_context_getter), 28 : baseline_context_getter_(baseline_context_getter),
29 network_task_runner_( 29 network_task_runner_(
30 baseline_context_getter_->GetNetworkTaskRunner()), 30 baseline_context_getter_->GetNetworkTaskRunner()),
31 user_agent_(user_agent) { 31 user_agent_(user_agent) {
32 DCHECK(baseline_context_getter_); 32 DCHECK(baseline_context_getter_.get());
33 DCHECK(network_task_runner_); 33 DCHECK(network_task_runner_.get());
34 DCHECK(!user_agent_.empty()); 34 DCHECK(!user_agent_.empty());
35 } 35 }
36 36
37 HttpBridge::RequestContextGetter::~RequestContextGetter() {} 37 HttpBridge::RequestContextGetter::~RequestContextGetter() {}
38 38
39 net::URLRequestContext* 39 net::URLRequestContext*
40 HttpBridge::RequestContextGetter::GetURLRequestContext() { 40 HttpBridge::RequestContextGetter::GetURLRequestContext() {
41 // Lazily create the context. 41 // Lazily create the context.
42 if (!context_) { 42 if (!context_) {
43 net::URLRequestContext* baseline_context = 43 net::URLRequestContext* baseline_context =
(...skipping 19 matching lines...) Expand all
63 : request_context_getter_( 63 : request_context_getter_(
64 new HttpBridge::RequestContextGetter( 64 new HttpBridge::RequestContextGetter(
65 baseline_context_getter, user_agent)), 65 baseline_context_getter, user_agent)),
66 network_time_update_callback_(network_time_update_callback) { 66 network_time_update_callback_(network_time_update_callback) {
67 } 67 }
68 68
69 HttpBridgeFactory::~HttpBridgeFactory() { 69 HttpBridgeFactory::~HttpBridgeFactory() {
70 } 70 }
71 71
72 HttpPostProviderInterface* HttpBridgeFactory::Create() { 72 HttpPostProviderInterface* HttpBridgeFactory::Create() {
73 HttpBridge* http = new HttpBridge(request_context_getter_, 73 HttpBridge* http = new HttpBridge(request_context_getter_.get(),
74 network_time_update_callback_); 74 network_time_update_callback_);
75 http->AddRef(); 75 http->AddRef();
76 return http; 76 return http;
77 } 77 }
78 78
79 void HttpBridgeFactory::Destroy(HttpPostProviderInterface* http) { 79 void HttpBridgeFactory::Destroy(HttpPostProviderInterface* http) {
80 static_cast<HttpBridge*>(http)->Release(); 80 static_cast<HttpBridge*>(http)->Release();
81 } 81 }
82 82
83 HttpBridge::RequestContext::RequestContext( 83 HttpBridge::RequestContext::RequestContext(
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 221
222 void HttpBridge::MakeAsynchronousPost() { 222 void HttpBridge::MakeAsynchronousPost() {
223 DCHECK(network_task_runner_->BelongsToCurrentThread()); 223 DCHECK(network_task_runner_->BelongsToCurrentThread());
224 base::AutoLock lock(fetch_state_lock_); 224 base::AutoLock lock(fetch_state_lock_);
225 DCHECK(!fetch_state_.request_completed); 225 DCHECK(!fetch_state_.request_completed);
226 if (fetch_state_.aborted) 226 if (fetch_state_.aborted)
227 return; 227 return;
228 228
229 fetch_state_.url_poster = net::URLFetcher::Create( 229 fetch_state_.url_poster = net::URLFetcher::Create(
230 url_for_request_, net::URLFetcher::POST, this); 230 url_for_request_, net::URLFetcher::POST, this);
231 fetch_state_.url_poster->SetRequestContext(context_getter_for_request_); 231 fetch_state_.url_poster->SetRequestContext(context_getter_for_request_.get());
232 fetch_state_.url_poster->SetUploadData(content_type_, request_content_); 232 fetch_state_.url_poster->SetUploadData(content_type_, request_content_);
233 fetch_state_.url_poster->SetExtraRequestHeaders(extra_headers_); 233 fetch_state_.url_poster->SetExtraRequestHeaders(extra_headers_);
234 fetch_state_.url_poster->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES); 234 fetch_state_.url_poster->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES);
235 fetch_state_.start_time = base::Time::Now(); 235 fetch_state_.start_time = base::Time::Now();
236 fetch_state_.url_poster->Start(); 236 fetch_state_.url_poster->Start();
237 } 237 }
238 238
239 int HttpBridge::GetResponseContentLength() const { 239 int HttpBridge::GetResponseContentLength() const {
240 DCHECK_EQ(base::MessageLoop::current(), created_on_loop_); 240 DCHECK_EQ(base::MessageLoop::current(), created_on_loop_);
241 base::AutoLock lock(fetch_state_lock_); 241 base::AutoLock lock(fetch_state_lock_);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 base::MessageLoop::current()->DeleteSoon(FROM_HERE, fetch_state_.url_poster); 316 base::MessageLoop::current()->DeleteSoon(FROM_HERE, fetch_state_.url_poster);
317 fetch_state_.url_poster = NULL; 317 fetch_state_.url_poster = NULL;
318 318
319 // Wake the blocked syncer thread in MakeSynchronousPost. 319 // Wake the blocked syncer thread in MakeSynchronousPost.
320 // WARNING: DONT DO ANYTHING AFTER THIS CALL! |this| may be deleted! 320 // WARNING: DONT DO ANYTHING AFTER THIS CALL! |this| may be deleted!
321 http_post_completed_.Signal(); 321 http_post_completed_.Signal();
322 } 322 }
323 323
324 net::URLRequestContextGetter* HttpBridge::GetRequestContextGetterForTest() 324 net::URLRequestContextGetter* HttpBridge::GetRequestContextGetterForTest()
325 const { 325 const {
326 return context_getter_for_request_; 326 return context_getter_for_request_.get();
327 } 327 }
328 328
329 void HttpBridge::UpdateNetworkTime() { 329 void HttpBridge::UpdateNetworkTime() {
330 std::string sane_time_str; 330 std::string sane_time_str;
331 if (!fetch_state_.request_succeeded || fetch_state_.start_time.is_null() || 331 if (!fetch_state_.request_succeeded || fetch_state_.start_time.is_null() ||
332 fetch_state_.end_time < fetch_state_.start_time || 332 fetch_state_.end_time < fetch_state_.start_time ||
333 !fetch_state_.response_headers->EnumerateHeader(NULL, "Sane-Time-Millis", 333 !fetch_state_.response_headers->EnumerateHeader(NULL, "Sane-Time-Millis",
334 &sane_time_str)) { 334 &sane_time_str)) {
335 return; 335 return;
336 } 336 }
337 337
338 int64 sane_time_ms = 0; 338 int64 sane_time_ms = 0;
339 if (base::StringToInt64(sane_time_str, &sane_time_ms)) { 339 if (base::StringToInt64(sane_time_str, &sane_time_ms)) {
340 network_time_update_callback_.Run( 340 network_time_update_callback_.Run(
341 base::Time::FromJsTime(sane_time_ms), 341 base::Time::FromJsTime(sane_time_ms),
342 base::TimeDelta::FromMilliseconds(1), 342 base::TimeDelta::FromMilliseconds(1),
343 fetch_state_.end_time - fetch_state_.start_time); 343 fetch_state_.end_time - fetch_state_.start_time);
344 } 344 }
345 } 345 }
346 346
347 } // namespace syncer 347 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/engine/model_changing_syncer_command.cc ('k') | sync/internal_api/http_bridge_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698