Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "net/http/http_cache.h" | 5 #include "net/http/http_cache.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 | 10 |
| 11 #if defined(OS_POSIX) | 11 #if defined(OS_POSIX) |
| 12 #include <unistd.h> | 12 #include <unistd.h> |
| 13 #endif | 13 #endif |
| 14 | 14 |
| 15 #include "base/bind.h" | 15 #include "base/bind.h" |
| 16 #include "base/bind_helpers.h" | 16 #include "base/bind_helpers.h" |
| 17 #include "base/callback.h" | 17 #include "base/callback.h" |
| 18 #include "base/file_util.h" | 18 #include "base/file_util.h" |
| 19 #include "base/format_macros.h" | 19 #include "base/format_macros.h" |
| 20 #include "base/location.h" | 20 #include "base/location.h" |
| 21 #include "base/memory/ref_counted.h" | 21 #include "base/memory/ref_counted.h" |
| 22 #include "base/memory/scoped_ptr.h" | |
|
wtc
2014/01/15 19:08:59
Remove this. This is already included by net/http/
ramant (doing other things)
2014/01/18 00:21:56
Done.
| |
| 22 #include "base/message_loop/message_loop.h" | 23 #include "base/message_loop/message_loop.h" |
| 23 #include "base/metrics/field_trial.h" | 24 #include "base/metrics/field_trial.h" |
| 24 #include "base/pickle.h" | 25 #include "base/pickle.h" |
| 25 #include "base/stl_util.h" | 26 #include "base/stl_util.h" |
| 26 #include "base/strings/string_number_conversions.h" | 27 #include "base/strings/string_number_conversions.h" |
| 27 #include "base/strings/string_util.h" | 28 #include "base/strings/string_util.h" |
| 28 #include "base/strings/stringprintf.h" | 29 #include "base/strings/stringprintf.h" |
| 29 #include "base/threading/worker_pool.h" | 30 #include "base/threading/worker_pool.h" |
| 30 #include "net/base/cache_type.h" | 31 #include "net/base/cache_type.h" |
| 31 #include "net/base/io_buffer.h" | 32 #include "net/base/io_buffer.h" |
| 32 #include "net/base/load_flags.h" | 33 #include "net/base/load_flags.h" |
| 33 #include "net/base/net_errors.h" | 34 #include "net/base/net_errors.h" |
| 34 #include "net/base/upload_data_stream.h" | 35 #include "net/base/upload_data_stream.h" |
| 35 #include "net/disk_cache/disk_cache.h" | 36 #include "net/disk_cache/disk_cache.h" |
| 37 #include "net/http/disk_cache_based_ssl_host_info.h" | |
| 36 #include "net/http/http_cache_transaction.h" | 38 #include "net/http/http_cache_transaction.h" |
| 37 #include "net/http/http_network_layer.h" | 39 #include "net/http/http_network_layer.h" |
| 38 #include "net/http/http_network_session.h" | 40 #include "net/http/http_network_session.h" |
| 39 #include "net/http/http_request_info.h" | 41 #include "net/http/http_request_info.h" |
| 40 #include "net/http/http_response_headers.h" | 42 #include "net/http/http_response_headers.h" |
| 41 #include "net/http/http_response_info.h" | 43 #include "net/http/http_response_info.h" |
| 42 #include "net/http/http_util.h" | 44 #include "net/http/http_util.h" |
| 45 #include "net/socket/ssl_host_info.h" | |
| 43 | 46 |
| 44 namespace { | 47 namespace { |
| 45 | 48 |
| 46 // Adaptor to delete a file on a worker thread. | 49 // Adaptor to delete a file on a worker thread. |
| 47 void DeletePath(base::FilePath path) { | 50 void DeletePath(base::FilePath path) { |
| 48 base::DeleteFile(path, false); | 51 base::DeleteFile(path, false); |
| 49 } | 52 } |
| 50 | 53 |
| 51 } // namespace | 54 } // namespace |
| 52 | 55 |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 260 } | 263 } |
| 261 | 264 |
| 262 void HttpCache::MetadataWriter::OnIOComplete(int result) { | 265 void HttpCache::MetadataWriter::OnIOComplete(int result) { |
| 263 if (!verified_) | 266 if (!verified_) |
| 264 return VerifyResponse(result); | 267 return VerifyResponse(result); |
| 265 SelfDestroy(); | 268 SelfDestroy(); |
| 266 } | 269 } |
| 267 | 270 |
| 268 //----------------------------------------------------------------------------- | 271 //----------------------------------------------------------------------------- |
| 269 | 272 |
| 273 class HttpCache::SSLHostInfoFactoryAdaptor : public SSLHostInfoFactory { | |
| 274 public: | |
| 275 SSLHostInfoFactoryAdaptor(CertVerifier* cert_verifier, HttpCache* http_cache) | |
| 276 : cert_verifier_(cert_verifier), | |
| 277 http_cache_(http_cache) { | |
| 278 } | |
| 279 | |
| 280 virtual SSLHostInfo* GetForHost(const std::string& hostname, | |
| 281 const SSLConfig& ssl_config) OVERRIDE { | |
| 282 return new DiskCacheBasedSSLHostInfo( | |
| 283 hostname, ssl_config, cert_verifier_, http_cache_); | |
| 284 } | |
| 285 | |
| 286 private: | |
| 287 CertVerifier* const cert_verifier_; | |
| 288 HttpCache* const http_cache_; | |
| 289 }; | |
| 290 | |
| 291 //----------------------------------------------------------------------------- | |
| 270 HttpCache::HttpCache(const net::HttpNetworkSession::Params& params, | 292 HttpCache::HttpCache(const net::HttpNetworkSession::Params& params, |
| 271 BackendFactory* backend_factory) | 293 BackendFactory* backend_factory) |
| 272 : net_log_(params.net_log), | 294 : net_log_(params.net_log), |
| 273 backend_factory_(backend_factory), | 295 backend_factory_(backend_factory), |
| 274 building_backend_(false), | 296 building_backend_(false), |
| 275 mode_(NORMAL), | 297 mode_(NORMAL) { |
| 276 network_layer_(new HttpNetworkLayer(new HttpNetworkSession(params))) { | 298 HttpNetworkSession* session = new HttpNetworkSession(params); |
| 299 ssl_host_info_factory_.reset(new SSLHostInfoFactoryAdaptor( | |
| 300 session->cert_verifier(), this)); | |
| 301 network_layer_.reset(new HttpNetworkLayer(session)); | |
|
wtc
2014/01/15 19:08:59
Please change this back to using the initializer l
ramant (doing other things)
2014/01/18 00:21:56
Done.
| |
| 277 } | 302 } |
| 278 | 303 |
| 279 | 304 |
| 280 HttpCache::HttpCache(HttpNetworkSession* session, | 305 HttpCache::HttpCache(HttpNetworkSession* session, |
| 281 BackendFactory* backend_factory) | 306 BackendFactory* backend_factory) |
| 282 : net_log_(session->net_log()), | 307 : net_log_(session->net_log()), |
| 283 backend_factory_(backend_factory), | 308 backend_factory_(backend_factory), |
| 284 building_backend_(false), | 309 building_backend_(false), |
| 285 mode_(NORMAL), | 310 mode_(NORMAL), |
| 311 ssl_host_info_factory_(new SSLHostInfoFactoryAdaptor( | |
| 312 session->cert_verifier(), this)), | |
| 286 network_layer_(new HttpNetworkLayer(session)) { | 313 network_layer_(new HttpNetworkLayer(session)) { |
| 287 } | 314 } |
| 288 | 315 |
| 289 HttpCache::HttpCache(HttpTransactionFactory* network_layer, | 316 HttpCache::HttpCache(HttpTransactionFactory* network_layer, |
| 290 NetLog* net_log, | 317 NetLog* net_log, |
| 291 BackendFactory* backend_factory) | 318 BackendFactory* backend_factory) |
| 292 : net_log_(net_log), | 319 : net_log_(net_log), |
| 293 backend_factory_(backend_factory), | 320 backend_factory_(backend_factory), |
| 294 building_backend_(false), | 321 building_backend_(false), |
| 295 mode_(NORMAL), | 322 mode_(NORMAL), |
| (...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1140 building_backend_ = false; | 1167 building_backend_ = false; |
| 1141 DeletePendingOp(pending_op); | 1168 DeletePendingOp(pending_op); |
| 1142 } | 1169 } |
| 1143 | 1170 |
| 1144 // The cache may be gone when we return from the callback. | 1171 // The cache may be gone when we return from the callback. |
| 1145 if (!item->DoCallback(result, disk_cache_.get())) | 1172 if (!item->DoCallback(result, disk_cache_.get())) |
| 1146 item->NotifyTransaction(result, NULL); | 1173 item->NotifyTransaction(result, NULL); |
| 1147 } | 1174 } |
| 1148 | 1175 |
| 1149 } // namespace net | 1176 } // namespace net |
| OLD | NEW |