summaryrefslogtreecommitdiffstats
path: root/chromium/components/policy/core/common/cloud/user_policy_request_context.cc
blob: 09e20f16cea07594937d1fa7214afa56912227b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/policy/core/common/cloud/user_policy_request_context.h"

#include "base/logging.h"
#include "base/single_thread_task_runner.h"
#include "net/cookies/cookie_monster.h"
#include "net/http/http_network_layer.h"
#include "net/url_request/url_request_context.h"

namespace policy {

UserPolicyRequestContext::UserPolicyRequestContext(
    scoped_refptr<net::URLRequestContextGetter> user_context_getter,
    scoped_refptr<net::URLRequestContextGetter> system_context_getter,
    const std::string& user_agent)
    : user_context_getter_(user_context_getter),
      system_context_getter_(system_context_getter),
      http_user_agent_settings_("*", user_agent) {
  DCHECK(user_context_getter_);
}

UserPolicyRequestContext::~UserPolicyRequestContext() {
}

net::URLRequestContext*
UserPolicyRequestContext::GetURLRequestContext() {
  DCHECK(GetNetworkTaskRunner()->RunsTasksOnCurrentThread());
  if (!context_.get()) {
    // Create our URLRequestContext().
    context_.reset(new net::URLRequestContext());
    net::URLRequestContext* user_context =
        user_context_getter_->GetURLRequestContext();

    // Reuse pretty much everything from the user context, except we
    // use the system context's proxy and resolver (see below).
    context_->CopyFrom(user_context);

    // Use the system context's proxy and resolver to ensure that we can still
    // fetch policy updates even if a bad proxy config is pushed via user
    // policy.
    // TODO(atwilson): Re-enable the following lines in a followup CL per
    // reviewer request.
    // net::URLRequestContext* system_context =
    //        system_context_getter_->GetURLRequestContext();
    // context_->set_host_resolver(system_context->host_resolver());
    // context_->set_proxy_service(system_context->proxy_service());

    // Set our custom UserAgent.
    context_->set_http_user_agent_settings(&http_user_agent_settings_);
  }
  return context_.get();
}

scoped_refptr<base::SingleThreadTaskRunner>
UserPolicyRequestContext::GetNetworkTaskRunner() const {
  return user_context_getter_->GetNetworkTaskRunner();
}

}  // namespace policy