Update broken references to image assets
[chromium-blink-merge.git] / chrome / service / net / service_url_request_context_getter.cc
blob0f11bfaf97367895c132ded7103dd27cd1c8f906
1 // Copyright 2014 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.
5 #include "chrome/service/net/service_url_request_context_getter.h"
7 #if defined(OS_POSIX) && !defined(OS_MACOSX)
8 #include <sys/utsname.h>
9 #endif
11 #include "base/compiler_specific.h"
12 #include "base/single_thread_task_runner.h"
13 #include "base/strings/stringprintf.h"
14 #include "base/sys_info.h"
15 #include "chrome/service/service_process.h"
16 #include "components/version_info/version_info.h"
17 #include "net/proxy/proxy_config_service.h"
18 #include "net/proxy/proxy_service.h"
19 #include "net/url_request/url_request_context_builder.h"
21 namespace {
22 // Copied from webkit/glue/user_agent.cc. We don't want to pull in a dependency
23 // on webkit/glue which also pulls in the renderer. Also our user-agent is
24 // totally different from the user-agent used by the browser, just the
25 // OS-specific parts are common.
26 std::string BuildOSCpuInfo() {
27 std::string os_cpu;
29 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS)
30 int32 os_major_version = 0;
31 int32 os_minor_version = 0;
32 int32 os_bugfix_version = 0;
33 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version,
34 &os_minor_version,
35 &os_bugfix_version);
36 #endif
37 #if defined(OS_POSIX) && !defined(OS_MACOSX)
38 // Should work on any Posix system.
39 struct utsname unixinfo;
40 uname(&unixinfo);
42 std::string cputype;
43 // special case for biarch systems
44 if (strcmp(unixinfo.machine, "x86_64") == 0 &&
45 sizeof(void*) == sizeof(int32)) { // NOLINT
46 cputype.assign("i686 (x86_64)");
47 } else {
48 cputype.assign(unixinfo.machine);
50 #endif
52 base::StringAppendF(
53 &os_cpu,
54 #if defined(OS_WIN)
55 "Windows NT %d.%d",
56 os_major_version,
57 os_minor_version
58 #elif defined(OS_MACOSX)
59 "Intel Mac OS X %d_%d_%d",
60 os_major_version,
61 os_minor_version,
62 os_bugfix_version
63 #elif defined(OS_CHROMEOS)
64 "CrOS %s %d.%d.%d",
65 cputype.c_str(), // e.g. i686
66 os_major_version,
67 os_minor_version,
68 os_bugfix_version
69 #else
70 "%s %s",
71 unixinfo.sysname, // e.g. Linux
72 cputype.c_str() // e.g. i686
73 #endif
74 ); // NOLINT
76 return os_cpu;
79 // Returns the default user agent.
80 std::string MakeUserAgentForServiceProcess() {
81 std::string user_agent;
82 std::string extra_version_info;
83 if (!version_info::IsOfficialBuild())
84 extra_version_info = "-devel";
85 base::StringAppendF(&user_agent,
86 "Chrome Service %s(%s)%s %s ",
87 version_info::GetVersionNumber().c_str(),
88 version_info::GetLastChange().c_str(),
89 extra_version_info.c_str(),
90 BuildOSCpuInfo().c_str());
91 return user_agent;
94 } // namespace
96 ServiceURLRequestContextGetter::ServiceURLRequestContextGetter()
97 : user_agent_(MakeUserAgentForServiceProcess()),
98 network_task_runner_(g_service_process->io_task_runner()) {
99 DCHECK(g_service_process);
100 proxy_config_service_.reset(net::ProxyService::CreateSystemProxyConfigService(
101 g_service_process->io_task_runner(),
102 g_service_process->file_task_runner()));
105 net::URLRequestContext*
106 ServiceURLRequestContextGetter::GetURLRequestContext() {
107 if (!url_request_context_.get()) {
108 net::URLRequestContextBuilder builder;
109 builder.set_user_agent(user_agent_);
110 builder.set_accept_language("en-us,fr");
111 builder.set_proxy_config_service(proxy_config_service_.release());
112 builder.set_throttling_enabled(true);
113 url_request_context_.reset(builder.Build());
115 return url_request_context_.get();
118 scoped_refptr<base::SingleThreadTaskRunner>
119 ServiceURLRequestContextGetter::GetNetworkTaskRunner() const {
120 return network_task_runner_;
123 ServiceURLRequestContextGetter::~ServiceURLRequestContextGetter() {}