OLD | NEW |
| (Empty) |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/policy/cloud/system_policy_request_context.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "base/single_thread_task_runner.h" | |
9 #include "net/cookies/cookie_monster.h" | |
10 #include "net/http/http_network_layer.h" | |
11 #include "net/url_request/url_request_context.h" | |
12 | |
13 namespace policy { | |
14 | |
15 SystemPolicyRequestContext::SystemPolicyRequestContext( | |
16 scoped_refptr<net::URLRequestContextGetter> system_context_getter, | |
17 const std::string& user_agent) | |
18 : system_context_getter_(system_context_getter), | |
19 http_user_agent_settings_("*", user_agent) { | |
20 DCHECK(system_context_getter); | |
21 } | |
22 | |
23 SystemPolicyRequestContext::~SystemPolicyRequestContext() { | |
24 } | |
25 | |
26 net::URLRequestContext* | |
27 SystemPolicyRequestContext::GetURLRequestContext() { | |
28 DCHECK(GetNetworkTaskRunner()->RunsTasksOnCurrentThread()); | |
29 if (!context_.get()) { | |
30 // Create our URLRequestContext(). | |
31 context_.reset(new net::URLRequestContext()); | |
32 | |
33 net::URLRequestContext* system_context = | |
34 system_context_getter_->GetURLRequestContext(); | |
35 // Share resolver, proxy service and ssl bits with the system context. | |
36 // This is important so we don't make redundant requests (e.g. when | |
37 // resolving proxy auto configuration). | |
38 // TODO(atwilson): Consider using CopyFrom() here to copy all services - | |
39 // http://crbug.com/322422. | |
40 context_->set_net_log(system_context->net_log()); | |
41 context_->set_host_resolver(system_context->host_resolver()); | |
42 context_->set_proxy_service(system_context->proxy_service()); | |
43 context_->set_ssl_config_service( | |
44 system_context->ssl_config_service()); | |
45 | |
46 // Set our custom UserAgent. | |
47 context_->set_http_user_agent_settings(&http_user_agent_settings_); | |
48 | |
49 // Share the http session. | |
50 http_transaction_factory_.reset(new net::HttpNetworkLayer( | |
51 system_context->http_transaction_factory()->GetSession())); | |
52 context_->set_http_transaction_factory(http_transaction_factory_.get()); | |
53 | |
54 // No cookies, please. We also don't track channel IDs (no | |
55 // ServerBoundCertService). | |
56 context_->set_cookie_store(new net::CookieMonster(NULL, NULL)); | |
57 } | |
58 | |
59 return context_.get(); | |
60 } | |
61 | |
62 scoped_refptr<base::SingleThreadTaskRunner> | |
63 SystemPolicyRequestContext::GetNetworkTaskRunner() const { | |
64 return system_context_getter_->GetNetworkTaskRunner(); | |
65 } | |
66 | |
67 } // namespace policy | |
OLD | NEW |