OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef COMPONENTS_CRONET_URL_REQUEST_CONTEXT_CONFIG_H_ | 5 #ifndef COMPONENTS_CRONET_URL_REQUEST_CONTEXT_CONFIG_H_ |
6 #define COMPONENTS_CRONET_URL_REQUEST_CONTEXT_CONFIG_H_ | 6 #define COMPONENTS_CRONET_URL_REQUEST_CONTEXT_CONFIG_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
| 10 #include "base/json/json_value_converter.h" |
10 #include "base/macros.h" | 11 #include "base/macros.h" |
11 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
12 #include "base/time/time.h" | 13 #include "base/time/time.h" |
13 #include "net/base/hash_value.h" | |
14 | 14 |
15 namespace net { | 15 namespace net { |
16 class CertVerifier; | 16 class CertVerifier; |
17 class URLRequestContextBuilder; | 17 class URLRequestContextBuilder; |
18 } // namespace net | 18 } // namespace net |
19 | 19 |
20 namespace cronet { | 20 namespace cronet { |
21 | 21 |
22 // Common configuration parameters used by Cronet to configure | 22 // Common configuration parameters used by Cronet to configure |
23 // URLRequestContext. | 23 // URLRequestContext. Can be parsed from JSON string passed through JNI. |
24 struct URLRequestContextConfig { | 24 struct URLRequestContextConfig { |
25 // Type of HTTP cache. | |
26 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.net | |
27 enum HttpCacheType { | |
28 // No HTTP cache. | |
29 DISABLED, | |
30 // HTTP cache persisted to disk. | |
31 DISK, | |
32 // HTTP cache kept in memory. | |
33 MEMORY, | |
34 }; | |
35 | |
36 // App-provided hint that server supports QUIC. | 25 // App-provided hint that server supports QUIC. |
37 struct QuicHint { | 26 struct QuicHint { |
38 QuicHint(const std::string& host, int port, int alternate_port); | 27 QuicHint(); |
39 ~QuicHint(); | 28 ~QuicHint(); |
40 | 29 |
| 30 // Register |converter| for use in converter.Convert(). |
| 31 static void RegisterJSONConverter( |
| 32 base::JSONValueConverter<QuicHint>* converter); |
| 33 |
41 // Host name of the server that supports QUIC. | 34 // Host name of the server that supports QUIC. |
42 const std::string host; | 35 std::string host; |
43 // Port of the server that supports QUIC. | 36 // Port of the server that supports QUIC. |
44 const int port; | 37 int port; |
45 // Alternate protocol port. | 38 // Alternate protocol port. |
46 const int alternate_port; | 39 int alternate_port; |
47 | 40 |
48 private: | 41 private: |
49 DISALLOW_COPY_AND_ASSIGN(QuicHint); | 42 DISALLOW_COPY_AND_ASSIGN(QuicHint); |
50 }; | 43 }; |
51 | 44 |
52 // Public-Key-Pinning configuration structure. | 45 // Public-Key-Pinning configuration structure. |
53 struct Pkp { | 46 struct Pkp { |
54 Pkp(const std::string& host, | 47 Pkp(); |
55 bool include_subdomains, | |
56 const base::Time& expiration_date); | |
57 ~Pkp(); | 48 ~Pkp(); |
58 | 49 |
| 50 // Register |converter| for use in converter.Convert(). |
| 51 static void RegisterJSONConverter(base::JSONValueConverter<Pkp>* converter); |
| 52 |
59 // Host name. | 53 // Host name. |
60 const std::string host; | 54 std::string host; |
61 // Pin hashes (currently SHA256 only). | 55 // Pin hashes (currently SHA256 only). |
62 net::HashValueVector pin_hashes; | 56 ScopedVector<std::string> pin_hashes; |
63 // Indicates whether the pinning should apply to the pinned host subdomains. | 57 // Indicates whether the pinning should apply to the pinned host subdomains. |
64 const bool include_subdomains; | 58 bool include_subdomains; |
65 // Expiration date for the pins. | 59 // Expiration date for the pins. |
66 const base::Time expiration_date; | 60 base::Time expiration_date; |
67 | 61 |
68 private: | 62 private: |
69 DISALLOW_COPY_AND_ASSIGN(Pkp); | 63 DISALLOW_COPY_AND_ASSIGN(Pkp); |
70 }; | 64 }; |
71 | 65 |
72 URLRequestContextConfig( | 66 URLRequestContextConfig(); |
73 // Enable QUIC. | |
74 bool enable_quic, | |
75 // Enable SPDY. | |
76 bool enable_spdy, | |
77 // Enable SDCH. | |
78 bool enable_sdch, | |
79 // Type of http cache. | |
80 HttpCacheType http_cache, | |
81 // Max size of http cache in bytes. | |
82 int http_cache_max_size, | |
83 // Disable caching for HTTP responses. Other information may be stored in | |
84 // the cache. | |
85 bool load_disable_cache, | |
86 // Storage path for http cache and cookie storage. | |
87 const std::string& storage_path, | |
88 // User-Agent request header field. | |
89 const std::string& user_agent, | |
90 // JSON encoded experimental options. | |
91 const std::string& experimental_options, | |
92 // Data reduction proxy key. | |
93 const std::string& data_reduction_proxy_key, | |
94 // Data reduction proxy. | |
95 const std::string& data_reduction_primary_proxy, | |
96 // Fallback data reduction proxy. | |
97 const std::string& data_reduction_fallback_proxy, | |
98 // Data reduction proxy secure proxy check URL. | |
99 const std::string& data_reduction_secure_proxy_check_url, | |
100 // MockCertVerifier to use for testing purposes. | |
101 scoped_ptr<net::CertVerifier> mock_cert_verifier); | |
102 ~URLRequestContextConfig(); | 67 ~URLRequestContextConfig(); |
103 | 68 |
| 69 // Load config values from JSON format. |
| 70 bool LoadFromJSON(const std::string& config_string); |
| 71 |
104 // Configure |context_builder| based on |this|. | 72 // Configure |context_builder| based on |this|. |
105 void ConfigureURLRequestContextBuilder( | 73 void ConfigureURLRequestContextBuilder( |
106 net::URLRequestContextBuilder* context_builder); | 74 net::URLRequestContextBuilder* context_builder); |
107 | 75 |
| 76 // Register |converter| for use in converter.Convert(). |
| 77 static void RegisterJSONConverter( |
| 78 base::JSONValueConverter<URLRequestContextConfig>* converter); |
| 79 |
108 // Enable QUIC. | 80 // Enable QUIC. |
109 const bool enable_quic; | 81 bool enable_quic; |
110 // Enable SPDY. | 82 // Enable SPDY. |
111 const bool enable_spdy; | 83 bool enable_spdy; |
112 // Enable SDCH. | 84 // Enable SDCH. |
113 const bool enable_sdch; | 85 bool enable_sdch; |
114 // Type of http cache. | 86 // Type of http cache: "HTTP_CACHE_DISABLED", "HTTP_CACHE_DISK" or |
115 const HttpCacheType http_cache; | 87 // "HTTP_CACHE_IN_MEMORY". |
| 88 std::string http_cache; |
116 // Max size of http cache in bytes. | 89 // Max size of http cache in bytes. |
117 const int http_cache_max_size; | 90 int http_cache_max_size; |
118 // Disable caching for HTTP responses. Other information may be stored in | 91 // Disable caching for HTTP responses. Other information may be stored in |
119 // the cache. | 92 // the cache. |
120 const bool load_disable_cache; | 93 bool load_disable_cache; |
121 // Storage path for http cache and cookie storage. | 94 // Storage path for http cache and cookie storage. |
122 const std::string storage_path; | 95 std::string storage_path; |
123 // User-Agent request header field. | 96 // User-Agent request header field. |
124 const std::string user_agent; | 97 std::string user_agent; |
| 98 // App-provided list of servers that support QUIC. |
| 99 ScopedVector<QuicHint> quic_hints; |
125 // Experimental options encoded as a string in a JSON format containing | 100 // Experimental options encoded as a string in a JSON format containing |
126 // experiments and their corresponding configuration options. The format | 101 // experiments and their corresponding configuration options. The format |
127 // is a JSON object with the name of the experiment as the key, and the | 102 // is a JSON object with the name of the experiment as the key, and the |
128 // configuration options as the value. An example: | 103 // configuration options as the value. An example: |
129 // {"experiment1": {"option1": "option_value1", "option2": "option_value2", | 104 // {"experiment1": {"option1": "option_value1", "option2": "option_value2", |
130 // ...}, "experiment2: {"option3", "option_value3", ...}, ...} | 105 // ...}, "experiment2: {"option3", "option_value3", ...}, ...} |
131 const std::string experimental_options; | 106 std::string experimental_options; |
132 // Enable Data Reduction Proxy with authentication key. | 107 // Enable Data Reduction Proxy with authentication key. |
133 const std::string data_reduction_proxy_key; | 108 std::string data_reduction_proxy_key; |
134 const std::string data_reduction_primary_proxy; | 109 std::string data_reduction_primary_proxy; |
135 const std::string data_reduction_fallback_proxy; | 110 std::string data_reduction_fallback_proxy; |
136 const std::string data_reduction_secure_proxy_check_url; | 111 std::string data_reduction_secure_proxy_check_url; |
| 112 // The list of public key pins. |
| 113 ScopedVector<Pkp> pkp_list; |
137 | 114 |
138 // Certificate verifier for testing. | 115 // Certificate verifier for testing. |
139 scoped_ptr<net::CertVerifier> mock_cert_verifier; | 116 scoped_ptr<net::CertVerifier> mock_cert_verifier; |
140 | 117 |
141 // App-provided list of servers that support QUIC. | |
142 ScopedVector<QuicHint> quic_hints; | |
143 | |
144 // The list of public key pins. | |
145 ScopedVector<Pkp> pkp_list; | |
146 | |
147 private: | 118 private: |
148 DISALLOW_COPY_AND_ASSIGN(URLRequestContextConfig); | 119 DISALLOW_COPY_AND_ASSIGN(URLRequestContextConfig); |
149 }; | 120 }; |
150 | 121 |
151 } // namespace cronet | 122 } // namespace cronet |
152 | 123 |
153 #endif // COMPONENTS_CRONET_URL_REQUEST_CONTEXT_CONFIG_H_ | 124 #endif // COMPONENTS_CRONET_URL_REQUEST_CONTEXT_CONFIG_H_ |
OLD | NEW |