| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/host_resolver.h" | 10 #include "net/base/host_resolver.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 void HttpBridgeFactory::Destroy(HttpPostProviderInterface* http) { | 74 void HttpBridgeFactory::Destroy(HttpPostProviderInterface* http) { |
| 75 static_cast<HttpBridge*>(http)->Release(); | 75 static_cast<HttpBridge*>(http)->Release(); |
| 76 } | 76 } |
| 77 | 77 |
| 78 HttpBridge::RequestContext::RequestContext( | 78 HttpBridge::RequestContext::RequestContext( |
| 79 net::URLRequestContext* baseline_context, | 79 net::URLRequestContext* baseline_context, |
| 80 const scoped_refptr<base::SingleThreadTaskRunner>& | 80 const scoped_refptr<base::SingleThreadTaskRunner>& |
| 81 network_task_runner, | 81 network_task_runner, |
| 82 const std::string& user_agent) | 82 const std::string& user_agent) |
| 83 : baseline_context_(baseline_context), | 83 : baseline_context_(baseline_context), |
| 84 network_task_runner_(network_task_runner), | 84 network_task_runner_(network_task_runner) { |
| 85 user_agent_(user_agent) { | 85 DCHECK(!user_agent.empty()); |
| 86 DCHECK(!user_agent_.empty()); | |
| 87 | 86 |
| 88 // Create empty, in-memory cookie store. | 87 // Create empty, in-memory cookie store. |
| 89 set_cookie_store(new net::CookieMonster(NULL, NULL)); | 88 set_cookie_store(new net::CookieMonster(NULL, NULL)); |
| 90 | 89 |
| 91 // We don't use a cache for bridged loads, but we do want to share proxy info. | 90 // We don't use a cache for bridged loads, but we do want to share proxy info. |
| 92 set_host_resolver(baseline_context->host_resolver()); | 91 set_host_resolver(baseline_context->host_resolver()); |
| 93 set_proxy_service(baseline_context->proxy_service()); | 92 set_proxy_service(baseline_context->proxy_service()); |
| 94 set_ssl_config_service(baseline_context->ssl_config_service()); | 93 set_ssl_config_service(baseline_context->ssl_config_service()); |
| 95 | 94 |
| 96 // We want to share the HTTP session data with the network layer factory, | 95 // We want to share the HTTP session data with the network layer factory, |
| 97 // which includes auth_cache for proxies. | 96 // which includes auth_cache for proxies. |
| 98 // Session is not refcounted so we need to be careful to not lose the parent | 97 // Session is not refcounted so we need to be careful to not lose the parent |
| 99 // context. | 98 // context. |
| 100 net::HttpNetworkSession* session = | 99 net::HttpNetworkSession* session = |
| 101 baseline_context->http_transaction_factory()->GetSession(); | 100 baseline_context->http_transaction_factory()->GetSession(); |
| 102 DCHECK(session); | 101 DCHECK(session); |
| 103 set_http_transaction_factory(new net::HttpNetworkLayer(session)); | 102 set_http_transaction_factory(new net::HttpNetworkLayer(session)); |
| 104 | 103 |
| 105 // TODO(timsteele): We don't currently listen for pref changes of these | 104 // TODO(timsteele): We don't currently listen for pref changes of these |
| 106 // fields or CookiePolicy; I'm not sure we want to strictly follow the | 105 // fields or CookiePolicy; I'm not sure we want to strictly follow the |
| 107 // default settings, since for example if the user chooses to block all | 106 // default settings, since for example if the user chooses to block all |
| 108 // cookies, sync will start failing. Also it seems like accept_lang/charset | 107 // cookies, sync will start failing. Also it seems like accept_lang/charset |
| 109 // should be tied to whatever the sync servers expect (if anything). These | 108 // should be tied to whatever the sync servers expect (if anything). These |
| 110 // fields should probably just be settable by sync backend; though we should | 109 // fields should probably just be settable by sync backend; though we should |
| 111 // figure out if we need to give the user explicit control over policies etc. | 110 // figure out if we need to give the user explicit control over policies etc. |
| 112 set_accept_language(baseline_context->accept_language()); | 111 const_http_user_agent_settings_.reset(new net::ConstHttpUserAgentSettings( |
| 113 set_accept_charset(baseline_context->accept_charset()); | 112 baseline_context->accept_language(), baseline_context->accept_charset(), |
| 113 user_agent)); |
| 114 set_http_user_agent_settings(const_http_user_agent_settings_.get()); |
| 114 | 115 |
| 115 set_net_log(baseline_context->net_log()); | 116 set_net_log(baseline_context->net_log()); |
| 116 } | 117 } |
| 117 | 118 |
| 118 HttpBridge::RequestContext::~RequestContext() { | 119 HttpBridge::RequestContext::~RequestContext() { |
| 119 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 120 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| 120 delete http_transaction_factory(); | 121 delete http_transaction_factory(); |
| 121 } | 122 } |
| 122 | 123 |
| 123 const std::string& HttpBridge::RequestContext::GetUserAgent( | |
| 124 const GURL& url) const { | |
| 125 return user_agent_; | |
| 126 } | |
| 127 | |
| 128 HttpBridge::URLFetchState::URLFetchState() : url_poster(NULL), | 124 HttpBridge::URLFetchState::URLFetchState() : url_poster(NULL), |
| 129 aborted(false), | 125 aborted(false), |
| 130 request_completed(false), | 126 request_completed(false), |
| 131 request_succeeded(false), | 127 request_succeeded(false), |
| 132 http_response_code(-1), | 128 http_response_code(-1), |
| 133 error_code(-1) {} | 129 error_code(-1) {} |
| 134 HttpBridge::URLFetchState::~URLFetchState() {} | 130 HttpBridge::URLFetchState::~URLFetchState() {} |
| 135 | 131 |
| 136 HttpBridge::HttpBridge(HttpBridge::RequestContextGetter* context_getter) | 132 HttpBridge::HttpBridge(HttpBridge::RequestContextGetter* context_getter) |
| 137 : context_getter_for_request_(context_getter), | 133 : context_getter_for_request_(context_getter), |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 // URLFetcher, so it seems most natural / "polite" to let the stack unwind. | 304 // URLFetcher, so it seems most natural / "polite" to let the stack unwind. |
| 309 MessageLoop::current()->DeleteSoon(FROM_HERE, fetch_state_.url_poster); | 305 MessageLoop::current()->DeleteSoon(FROM_HERE, fetch_state_.url_poster); |
| 310 fetch_state_.url_poster = NULL; | 306 fetch_state_.url_poster = NULL; |
| 311 | 307 |
| 312 // Wake the blocked syncer thread in MakeSynchronousPost. | 308 // Wake the blocked syncer thread in MakeSynchronousPost. |
| 313 // WARNING: DONT DO ANYTHING AFTER THIS CALL! |this| may be deleted! | 309 // WARNING: DONT DO ANYTHING AFTER THIS CALL! |this| may be deleted! |
| 314 http_post_completed_.Signal(); | 310 http_post_completed_.Signal(); |
| 315 } | 311 } |
| 316 | 312 |
| 317 } // namespace syncer | 313 } // namespace syncer |
| OLD | NEW |