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