forked from sanyaade-mobiledev/chromium.src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathurl_request_context_builder.h
131 lines (103 loc) · 3.81 KB
/
url_request_context_builder.h
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Copyright (c) 2012 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.
// This class is useful for building a simple URLRequestContext. Most creators
// of new URLRequestContexts should use this helper class to construct it. Call
// any configuration params, and when done, invoke Build() to construct the
// URLRequestContext. This URLRequestContext will own all its own storage.
//
// URLRequestContextBuilder and its associated params classes are initially
// populated with "sane" default values. Read through the comments to figure out
// what these are.
#ifndef NET_URL_REQUEST_URL_REQUEST_CONTEXT_BUILDER_H_
#define NET_URL_REQUEST_URL_REQUEST_CONTEXT_BUILDER_H_
#include <string>
#include "base/basictypes.h"
#include "base/file_path.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "build/build_config.h"
#include "net/base/net_export.h"
namespace net {
class HostMappingRules;
class ProxyConfigService;
class URLRequestContext;
class NET_EXPORT URLRequestContextBuilder {
public:
struct NET_EXPORT HostResolverParams {
HostResolverParams();
~HostResolverParams();
// The limit on the number of parallel host resolutions.
size_t parallelism;
// When the host resolution is taking too long, we'll retry this many times,
// in a backing off manner.
size_t retry_attempts;
};
struct NET_EXPORT HttpCacheParams {
enum Type {
IN_MEMORY,
DISK,
};
HttpCacheParams();
~HttpCacheParams();
// The type of HTTP cache. Default is IN_MEMORY.
Type type;
// The max size of the cache in bytes. Default is algorithmically determined
// based off available disk space.
int max_size;
// The cache path (when type is DISK).
FilePath path;
};
struct NET_EXPORT HttpNetworkSessionParams {
HttpNetworkSessionParams();
~HttpNetworkSessionParams();
// These fields mirror those in net::HttpNetworkSession::Params;
bool ignore_certificate_errors;
HostMappingRules* host_mapping_rules;
bool http_pipelining_enabled;
uint16 testing_fixed_http_port;
uint16 testing_fixed_https_port;
std::string trusted_spdy_proxy;
};
URLRequestContextBuilder();
~URLRequestContextBuilder();
#if defined(OS_LINUX)
void set_proxy_config_service(ProxyConfigService* proxy_config_service);
#endif // defined(OS_LINUX)
// Call this function to specify a hard-coded User-Agent for all requests that
// don't have a User-Agent already set.
void set_user_agent(const std::string& user_agent) {
user_agent_ = user_agent;
}
// Allows for overriding the default HostResolver params.
void set_host_resolver_params(
const HostResolverParams& host_resolver_params) {
host_resolver_params_ = host_resolver_params;
}
// By default it's disabled.
void set_ftp_enabled(bool enable) {
ftp_enabled_ = enable;
}
// By default HttpCache is enabled with a default constructed HttpCacheParams.
void EnableHttpCache(const HttpCacheParams& params);
void DisableHttpCache();
// Override default net::HttpNetworkSession::Params settings.
void set_http_network_session_params(
const HttpNetworkSessionParams& http_network_session_params) {
http_network_session_params_ = http_network_session_params;
}
URLRequestContext* Build();
private:
std::string user_agent_;
bool ftp_enabled_;
HostResolverParams host_resolver_params_;
bool http_cache_enabled_;
HttpCacheParams http_cache_params_;
HttpNetworkSessionParams http_network_session_params_;
#if defined(OS_LINUX)
scoped_ptr<ProxyConfigService> proxy_config_service_;
#endif // defined(OS_LINUX)
DISALLOW_COPY_AND_ASSIGN(URLRequestContextBuilder);
};
} // namespace net
#endif // NET_URL_REQUEST_URL_REQUEST_CONTEXT_BUILDER_H_