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

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

Issue 10918279: Provide mutable members of UrlRequestContext via pure-virtual interface (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add TODO Created 8 years, 2 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
OLDNEW
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"
11 #include "net/base/load_flags.h" 11 #include "net/base/load_flags.h"
12 #include "net/base/net_errors.h" 12 #include "net/base/net_errors.h"
13 #include "net/cookies/cookie_monster.h" 13 #include "net/cookies/cookie_monster.h"
14 #include "net/http/http_cache.h" 14 #include "net/http/http_cache.h"
15 #include "net/http/http_network_layer.h" 15 #include "net/http/http_network_layer.h"
16 #include "net/http/http_response_headers.h" 16 #include "net/http/http_response_headers.h"
17 #include "net/proxy/proxy_service.h" 17 #include "net/proxy/proxy_service.h"
18 #include "net/url_request/static_http_user_agent_settings.h"
18 #include "net/url_request/url_fetcher.h" 19 #include "net/url_request/url_fetcher.h"
19 #include "net/url_request/url_request_context.h" 20 #include "net/url_request/url_request_context.h"
20 #include "net/url_request/url_request_status.h" 21 #include "net/url_request/url_request_status.h"
21 22
22 namespace syncer { 23 namespace syncer {
23 24
24 HttpBridge::RequestContextGetter::RequestContextGetter( 25 HttpBridge::RequestContextGetter::RequestContextGetter(
25 net::URLRequestContextGetter* baseline_context_getter, 26 net::URLRequestContextGetter* baseline_context_getter,
26 const std::string& user_agent) 27 const std::string& user_agent)
27 : baseline_context_getter_(baseline_context_getter), 28 : baseline_context_getter_(baseline_context_getter),
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 void HttpBridgeFactory::Destroy(HttpPostProviderInterface* http) { 75 void HttpBridgeFactory::Destroy(HttpPostProviderInterface* http) {
75 static_cast<HttpBridge*>(http)->Release(); 76 static_cast<HttpBridge*>(http)->Release();
76 } 77 }
77 78
78 HttpBridge::RequestContext::RequestContext( 79 HttpBridge::RequestContext::RequestContext(
79 net::URLRequestContext* baseline_context, 80 net::URLRequestContext* baseline_context,
80 const scoped_refptr<base::SingleThreadTaskRunner>& 81 const scoped_refptr<base::SingleThreadTaskRunner>&
81 network_task_runner, 82 network_task_runner,
82 const std::string& user_agent) 83 const std::string& user_agent)
83 : baseline_context_(baseline_context), 84 : baseline_context_(baseline_context),
84 network_task_runner_(network_task_runner), 85 network_task_runner_(network_task_runner) {
85 user_agent_(user_agent) { 86 DCHECK(!user_agent.empty());
86 DCHECK(!user_agent_.empty());
87 87
88 // Create empty, in-memory cookie store. 88 // Create empty, in-memory cookie store.
89 set_cookie_store(new net::CookieMonster(NULL, NULL)); 89 set_cookie_store(new net::CookieMonster(NULL, NULL));
90 90
91 // We don't use a cache for bridged loads, but we do want to share proxy info. 91 // 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()); 92 set_host_resolver(baseline_context->host_resolver());
93 set_proxy_service(baseline_context->proxy_service()); 93 set_proxy_service(baseline_context->proxy_service());
94 set_ssl_config_service(baseline_context->ssl_config_service()); 94 set_ssl_config_service(baseline_context->ssl_config_service());
95 95
96 // We want to share the HTTP session data with the network layer factory, 96 // We want to share the HTTP session data with the network layer factory,
97 // which includes auth_cache for proxies. 97 // which includes auth_cache for proxies.
98 // Session is not refcounted so we need to be careful to not lose the parent 98 // Session is not refcounted so we need to be careful to not lose the parent
99 // context. 99 // context.
100 net::HttpNetworkSession* session = 100 net::HttpNetworkSession* session =
101 baseline_context->http_transaction_factory()->GetSession(); 101 baseline_context->http_transaction_factory()->GetSession();
102 DCHECK(session); 102 DCHECK(session);
103 set_http_transaction_factory(new net::HttpNetworkLayer(session)); 103 set_http_transaction_factory(new net::HttpNetworkLayer(session));
104 104
105 // TODO(timsteele): We don't currently listen for pref changes of these 105 // 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 106 // 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 107 // 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 108 // 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 109 // 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 110 // 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. 111 // figure out if we need to give the user explicit control over policies etc.
112 set_accept_language(baseline_context->accept_language()); 112 static_http_user_agent_settings_.reset(new net::StaticHttpUserAgentSettings(
113 set_accept_charset(baseline_context->accept_charset()); 113 baseline_context->GetAcceptLanguage(),
114 baseline_context->GetAcceptCharset(),
115 user_agent));
116 set_http_user_agent_settings(static_http_user_agent_settings_.get());
114 117
115 set_net_log(baseline_context->net_log()); 118 set_net_log(baseline_context->net_log());
116 } 119 }
117 120
118 HttpBridge::RequestContext::~RequestContext() { 121 HttpBridge::RequestContext::~RequestContext() {
119 DCHECK(network_task_runner_->BelongsToCurrentThread()); 122 DCHECK(network_task_runner_->BelongsToCurrentThread());
120 delete http_transaction_factory(); 123 delete http_transaction_factory();
121 } 124 }
122 125
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), 126 HttpBridge::URLFetchState::URLFetchState() : url_poster(NULL),
129 aborted(false), 127 aborted(false),
130 request_completed(false), 128 request_completed(false),
131 request_succeeded(false), 129 request_succeeded(false),
132 http_response_code(-1), 130 http_response_code(-1),
133 error_code(-1) {} 131 error_code(-1) {}
134 HttpBridge::URLFetchState::~URLFetchState() {} 132 HttpBridge::URLFetchState::~URLFetchState() {}
135 133
136 HttpBridge::HttpBridge(HttpBridge::RequestContextGetter* context_getter) 134 HttpBridge::HttpBridge(HttpBridge::RequestContextGetter* context_getter)
137 : context_getter_for_request_(context_getter), 135 : context_getter_for_request_(context_getter),
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 // URLFetcher, so it seems most natural / "polite" to let the stack unwind. 306 // URLFetcher, so it seems most natural / "polite" to let the stack unwind.
309 MessageLoop::current()->DeleteSoon(FROM_HERE, fetch_state_.url_poster); 307 MessageLoop::current()->DeleteSoon(FROM_HERE, fetch_state_.url_poster);
310 fetch_state_.url_poster = NULL; 308 fetch_state_.url_poster = NULL;
311 309
312 // Wake the blocked syncer thread in MakeSynchronousPost. 310 // Wake the blocked syncer thread in MakeSynchronousPost.
313 // WARNING: DONT DO ANYTHING AFTER THIS CALL! |this| may be deleted! 311 // WARNING: DONT DO ANYTHING AFTER THIS CALL! |this| may be deleted!
314 http_post_completed_.Signal(); 312 http_post_completed_.Signal();
315 } 313 }
316 314
317 } // namespace syncer 315 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698