OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 truncated_(false), | 185 truncated_(false), |
186 read_offset_(0), | 186 read_offset_(0), |
187 effective_load_flags_(0), | 187 effective_load_flags_(0), |
188 final_upload_progress_(0), | 188 final_upload_progress_(0), |
189 ALLOW_THIS_IN_INITIALIZER_LIST( | 189 ALLOW_THIS_IN_INITIALIZER_LIST( |
190 network_info_callback_(this, &Transaction::OnNetworkInfoAvailable)), | 190 network_info_callback_(this, &Transaction::OnNetworkInfoAvailable)), |
191 ALLOW_THIS_IN_INITIALIZER_LIST( | 191 ALLOW_THIS_IN_INITIALIZER_LIST( |
192 network_read_callback_(this, &Transaction::OnNetworkReadCompleted)), | 192 network_read_callback_(this, &Transaction::OnNetworkReadCompleted)), |
193 ALLOW_THIS_IN_INITIALIZER_LIST( | 193 ALLOW_THIS_IN_INITIALIZER_LIST( |
194 cache_read_callback_(new CancelableCompletionCallback<Transaction>( | 194 cache_read_callback_(new CancelableCompletionCallback<Transaction>( |
195 this, &Transaction::OnCacheReadCompleted))) { | 195 this, &Transaction::OnCacheReadCompleted))), |
| 196 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 197 cache_write_callback_(new CancelableCompletionCallback<Transaction>( |
| 198 this, &Transaction::OnCacheWriteCompleted))) { |
196 } | 199 } |
197 | 200 |
198 // Clean up the transaction. | 201 // Clean up the transaction. |
199 virtual ~Transaction(); | 202 virtual ~Transaction(); |
200 | 203 |
201 // HttpTransaction methods: | 204 // HttpTransaction methods: |
202 virtual int Start(const HttpRequestInfo*, CompletionCallback*, LoadLog*); | 205 virtual int Start(const HttpRequestInfo*, CompletionCallback*, LoadLog*); |
203 virtual int RestartIgnoringLastError(CompletionCallback*); | 206 virtual int RestartIgnoringLastError(CompletionCallback*); |
204 virtual int RestartWithCertificate(X509Certificate* client_cert, | 207 virtual int RestartWithCertificate(X509Certificate* client_cert, |
205 CompletionCallback* callback); | 208 CompletionCallback* callback); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 int ReadFromNetwork(IOBuffer* data, int data_len); | 329 int ReadFromNetwork(IOBuffer* data, int data_len); |
327 | 330 |
328 // Reads data from the cache entry. | 331 // Reads data from the cache entry. |
329 int ReadFromEntry(IOBuffer* data, int data_len); | 332 int ReadFromEntry(IOBuffer* data, int data_len); |
330 | 333 |
331 // Called to populate response_ from the cache entry. | 334 // Called to populate response_ from the cache entry. |
332 int ReadResponseInfoFromEntry(); | 335 int ReadResponseInfoFromEntry(); |
333 | 336 |
334 // Called to write data to the cache entry. If the write fails, then the | 337 // Called to write data to the cache entry. If the write fails, then the |
335 // cache entry is destroyed. Future calls to this function will just do | 338 // cache entry is destroyed. Future calls to this function will just do |
336 // nothing without side-effect. | 339 // nothing without side-effect. Returns a network error code. |
337 void WriteToEntry(int index, int offset, IOBuffer* data, int data_len); | 340 int WriteToEntry(int index, int offset, IOBuffer* data, int data_len, |
| 341 CompletionCallback* callback); |
338 | 342 |
339 // Called to write response_ to the cache entry. |truncated| indicates if the | 343 // Called to write response_ to the cache entry. |truncated| indicates if the |
340 // entry should be marked as incomplete. | 344 // entry should be marked as incomplete. |
341 void WriteResponseInfoToEntry(bool truncated); | 345 void WriteResponseInfoToEntry(bool truncated); |
342 | 346 |
343 // Called to append response data to the cache entry. | 347 // Called to append response data to the cache entry. Returns a network error |
344 void AppendResponseDataToEntry(IOBuffer* data, int data_len); | 348 // code. |
| 349 int AppendResponseDataToEntry(IOBuffer* data, int data_len, |
| 350 CompletionCallback* callback); |
345 | 351 |
346 // Called to truncate response content in the entry. | 352 // Called to truncate response content in the entry. |
347 void TruncateResponseData(); | 353 void TruncateResponseData(); |
348 | 354 |
349 // Called when we are done writing to the cache entry. | 355 // Called when we are done writing to the cache entry. |
350 void DoneWritingToEntry(bool success); | 356 void DoneWritingToEntry(bool success); |
351 | 357 |
352 // Deletes the current partial cache entry (sparse), and optionally removes | 358 // Deletes the current partial cache entry (sparse), and optionally removes |
353 // the control object (partial_). | 359 // the control object (partial_). |
354 void DoomPartialEntry(bool delete_object); | 360 void DoomPartialEntry(bool delete_object); |
355 | 361 |
356 // Performs the needed work after receiving data from the network. | 362 // Performs the needed work after receiving data from the network. |
357 int DoNetworkReadCompleted(int result); | 363 int DoNetworkReadCompleted(int result); |
358 | 364 |
359 // Performs the needed work after receiving data from the network, when | 365 // Performs the needed work after receiving data from the network, when |
360 // working with range requests. | 366 // working with range requests. |
361 int DoPartialNetworkReadCompleted(int result); | 367 int DoPartialNetworkReadCompleted(int result); |
362 | 368 |
363 // Performs the needed work after receiving data from the cache. | 369 // Performs the needed work after receiving data from the cache. |
364 int DoCacheReadCompleted(int result); | 370 int DoCacheReadCompleted(int result); |
365 | 371 |
366 // Performs the needed work after receiving data from the cache, when | 372 // Performs the needed work after receiving data from the cache, when |
367 // working with range requests. | 373 // working with range requests. |
368 int DoPartialCacheReadCompleted(int result); | 374 int DoPartialCacheReadCompleted(int result); |
369 | 375 |
| 376 // Performs the needed work after writing data to the cache. |
| 377 int DoCacheWriteCompleted(int result); |
| 378 |
370 // Called to signal completion of the network transaction's Start method: | 379 // Called to signal completion of the network transaction's Start method: |
371 void OnNetworkInfoAvailable(int result); | 380 void OnNetworkInfoAvailable(int result); |
372 | 381 |
373 // Called to signal completion of the network transaction's Read method: | 382 // Called to signal completion of the network transaction's Read method: |
374 void OnNetworkReadCompleted(int result); | 383 void OnNetworkReadCompleted(int result); |
375 | 384 |
376 // Called to signal completion of the cache's ReadData method: | 385 // Called to signal completion of the cache's ReadData method: |
377 void OnCacheReadCompleted(int result); | 386 void OnCacheReadCompleted(int result); |
378 | 387 |
| 388 // Called to signal completion of the cache's WriteData method: |
| 389 void OnCacheWriteCompleted(int result); |
| 390 |
379 scoped_refptr<LoadLog> load_log_; | 391 scoped_refptr<LoadLog> load_log_; |
380 const HttpRequestInfo* request_; | 392 const HttpRequestInfo* request_; |
381 scoped_ptr<HttpRequestInfo> custom_request_; | 393 scoped_ptr<HttpRequestInfo> custom_request_; |
382 // If extra_headers specified a "if-modified-since" or "if-none-match", | 394 // If extra_headers specified a "if-modified-since" or "if-none-match", |
383 // |external_validation_| contains the value of that header. | 395 // |external_validation_| contains the value of that header. |
384 ValidationHeader external_validation_; | 396 ValidationHeader external_validation_; |
385 HttpCache* cache_; | 397 HttpCache* cache_; |
386 HttpCache::ActiveEntry* entry_; | 398 HttpCache::ActiveEntry* entry_; |
387 scoped_ptr<HttpTransaction> network_trans_; | 399 scoped_ptr<HttpTransaction> network_trans_; |
388 CompletionCallback* callback_; // Consumer's callback. | 400 CompletionCallback* callback_; // Consumer's callback. |
389 HttpResponseInfo response_; | 401 HttpResponseInfo response_; |
390 HttpResponseInfo auth_response_; | 402 HttpResponseInfo auth_response_; |
391 std::string cache_key_; | 403 std::string cache_key_; |
392 Mode mode_; | 404 Mode mode_; |
393 bool reading_; // We are already reading. | 405 bool reading_; // We are already reading. |
394 bool invalid_range_; // We may bypass the cache for this request. | 406 bool invalid_range_; // We may bypass the cache for this request. |
395 bool enable_range_support_; | 407 bool enable_range_support_; |
396 bool truncated_; // We don't have all the response data. | 408 bool truncated_; // We don't have all the response data. |
397 scoped_refptr<IOBuffer> read_buf_; | 409 scoped_refptr<IOBuffer> read_buf_; |
398 int read_buf_len_; | 410 int read_buf_len_; |
399 int read_offset_; | 411 int read_offset_; |
400 int effective_load_flags_; | 412 int effective_load_flags_; |
401 scoped_ptr<PartialData> partial_; // We are dealing with range requests. | 413 scoped_ptr<PartialData> partial_; // We are dealing with range requests. |
402 uint64 final_upload_progress_; | 414 uint64 final_upload_progress_; |
403 CompletionCallbackImpl<Transaction> network_info_callback_; | 415 CompletionCallbackImpl<Transaction> network_info_callback_; |
404 CompletionCallbackImpl<Transaction> network_read_callback_; | 416 CompletionCallbackImpl<Transaction> network_read_callback_; |
405 scoped_refptr<CancelableCompletionCallback<Transaction> > | 417 scoped_refptr<CancelableCompletionCallback<Transaction> > |
406 cache_read_callback_; | 418 cache_read_callback_; |
| 419 scoped_refptr<CancelableCompletionCallback<Transaction> > |
| 420 cache_write_callback_; |
407 }; | 421 }; |
408 | 422 |
409 HttpCache::Transaction::~Transaction() { | 423 HttpCache::Transaction::~Transaction() { |
410 if (!revoked()) { | 424 if (!revoked()) { |
411 if (entry_) { | 425 if (entry_) { |
412 bool cancel_request = reading_ && enable_range_support_; | 426 bool cancel_request = reading_ && enable_range_support_; |
413 if (cancel_request && !partial_.get()) | 427 if (cancel_request && !partial_.get()) |
414 cancel_request &= (response_.headers->response_code() == 200); | 428 cancel_request &= (response_.headers->response_code() == 200); |
415 | 429 |
416 cache_->DoneWithEntry(entry_, this, cancel_request); | 430 cache_->DoneWithEntry(entry_, this, cancel_request); |
417 } else { | 431 } else { |
418 cache_->RemovePendingTransaction(this); | 432 cache_->RemovePendingTransaction(this); |
419 } | 433 } |
420 } | 434 } |
421 | 435 |
422 // If there is an outstanding callback, mark it as cancelled so running it | 436 // If there is an outstanding callback, mark it as cancelled so running it |
423 // does nothing. | 437 // does nothing. |
424 cache_read_callback_->Cancel(); | 438 cache_read_callback_->Cancel(); |
| 439 cache_write_callback_->Cancel(); |
425 | 440 |
426 // We could still have a cache read in progress, so we just null the cache_ | 441 // We could still have a cache read or write in progress, so we just null the |
427 // pointer to signal that we are dead. See OnCacheReadCompleted. | 442 // cache_ pointer to signal that we are dead. See DoCacheReadCompleted. |
428 cache_ = NULL; | 443 cache_ = NULL; |
429 } | 444 } |
430 | 445 |
431 int HttpCache::Transaction::Start(const HttpRequestInfo* request, | 446 int HttpCache::Transaction::Start(const HttpRequestInfo* request, |
432 CompletionCallback* callback, | 447 CompletionCallback* callback, |
433 LoadLog* load_log) { | 448 LoadLog* load_log) { |
434 DCHECK(request); | 449 DCHECK(request); |
435 DCHECK(callback); | 450 DCHECK(callback); |
436 | 451 |
437 // ensure that we only have one asynchronous call at a time. | 452 // ensure that we only have one asynchronous call at a time. |
(...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1265 read_buf_ = data; | 1280 read_buf_ = data; |
1266 read_buf_len_ = data_len; | 1281 read_buf_len_ = data_len; |
1267 if (rv >= 0) | 1282 if (rv >= 0) |
1268 rv = DoNetworkReadCompleted(rv); | 1283 rv = DoNetworkReadCompleted(rv); |
1269 return rv; | 1284 return rv; |
1270 } | 1285 } |
1271 | 1286 |
1272 int HttpCache::Transaction::ReadFromEntry(IOBuffer* data, int data_len) { | 1287 int HttpCache::Transaction::ReadFromEntry(IOBuffer* data, int data_len) { |
1273 DCHECK(entry_); | 1288 DCHECK(entry_); |
1274 int rv; | 1289 int rv; |
1275 cache_read_callback_->AddRef(); // Balanced in DoCacheReadCompleted. | 1290 cache_read_callback_->AddRef(); // Balanced in OnCacheReadCompleted. |
1276 if (partial_.get()) { | 1291 if (partial_.get()) { |
1277 rv = partial_->CacheRead(entry_->disk_entry, data, data_len, | 1292 rv = partial_->CacheRead(entry_->disk_entry, data, data_len, |
1278 cache_read_callback_); | 1293 cache_read_callback_); |
1279 } else { | 1294 } else { |
1280 rv = entry_->disk_entry->ReadData(kResponseContentIndex, read_offset_, | 1295 rv = entry_->disk_entry->ReadData(kResponseContentIndex, read_offset_, |
1281 data, data_len, cache_read_callback_); | 1296 data, data_len, cache_read_callback_); |
1282 } | 1297 } |
1283 read_buf_ = data; | 1298 read_buf_ = data; |
1284 read_buf_len_ = data_len; | 1299 read_buf_len_ = data_len; |
1285 if (rv >= 0) { | 1300 if (rv != ERR_IO_PENDING) |
| 1301 cache_read_callback_->Release(); |
| 1302 |
| 1303 if (rv >= 0) |
1286 rv = DoCacheReadCompleted(rv); | 1304 rv = DoCacheReadCompleted(rv); |
1287 } else if (rv != ERR_IO_PENDING) { | 1305 |
1288 cache_read_callback_->Release(); | |
1289 } | |
1290 return rv; | 1306 return rv; |
1291 } | 1307 } |
1292 | 1308 |
1293 int HttpCache::Transaction::ReadResponseInfoFromEntry() { | 1309 int HttpCache::Transaction::ReadResponseInfoFromEntry() { |
1294 DCHECK(entry_); | 1310 DCHECK(entry_); |
1295 | 1311 |
1296 LoadLog::BeginEvent(load_log_, LoadLog::TYPE_HTTP_CACHE_READ_INFO); | 1312 LoadLog::BeginEvent(load_log_, LoadLog::TYPE_HTTP_CACHE_READ_INFO); |
1297 bool read_ok = | 1313 bool read_ok = |
1298 HttpCache::ReadResponseInfo(entry_->disk_entry, &response_, &truncated_); | 1314 HttpCache::ReadResponseInfo(entry_->disk_entry, &response_, &truncated_); |
1299 LoadLog::EndEvent(load_log_, LoadLog::TYPE_HTTP_CACHE_READ_INFO); | 1315 LoadLog::EndEvent(load_log_, LoadLog::TYPE_HTTP_CACHE_READ_INFO); |
1300 | 1316 |
1301 return read_ok ? OK : ERR_CACHE_READ_FAILURE; | 1317 return read_ok ? OK : ERR_CACHE_READ_FAILURE; |
1302 } | 1318 } |
1303 | 1319 |
1304 void HttpCache::Transaction::WriteToEntry(int index, int offset, | 1320 int HttpCache::Transaction::WriteToEntry(int index, int offset, |
1305 IOBuffer* data, int data_len) { | 1321 IOBuffer* data, int data_len, |
| 1322 CompletionCallback* callback) { |
1306 if (!entry_) | 1323 if (!entry_) |
1307 return; | 1324 return data_len; |
1308 | 1325 |
1309 int rv = 0; | 1326 int rv = 0; |
1310 if (!partial_.get() || !data_len) { | 1327 if (!partial_.get() || !data_len) { |
1311 rv = entry_->disk_entry->WriteData(index, offset, data, data_len, NULL, | 1328 rv = entry_->disk_entry->WriteData(index, offset, data, data_len, callback, |
1312 true); | 1329 true); |
1313 } else { | 1330 } else { |
1314 rv = partial_->CacheWrite(entry_->disk_entry, data, data_len, NULL); | 1331 rv = partial_->CacheWrite(entry_->disk_entry, data, data_len, callback); |
1315 } | 1332 } |
1316 if (rv != data_len) { | 1333 |
| 1334 if (rv >= 0 && rv != data_len) { |
1317 DLOG(ERROR) << "failed to write response data to cache"; | 1335 DLOG(ERROR) << "failed to write response data to cache"; |
1318 DoneWritingToEntry(false); | 1336 DoneWritingToEntry(false); |
1319 } | 1337 } |
| 1338 return rv; |
1320 } | 1339 } |
1321 | 1340 |
1322 void HttpCache::Transaction::WriteResponseInfoToEntry(bool truncated) { | 1341 void HttpCache::Transaction::WriteResponseInfoToEntry(bool truncated) { |
1323 if (!entry_) | 1342 if (!entry_) |
1324 return; | 1343 return; |
1325 | 1344 |
1326 // Do not cache no-store content (unless we are record mode). Do not cache | 1345 // Do not cache no-store content (unless we are record mode). Do not cache |
1327 // content with cert errors either. This is to prevent not reporting net | 1346 // content with cert errors either. This is to prevent not reporting net |
1328 // errors when loading a resource from the cache. When we load a page over | 1347 // errors when loading a resource from the cache. When we load a page over |
1329 // HTTPS with a cert error we show an SSL blocking page. If the user clicks | 1348 // HTTPS with a cert error we show an SSL blocking page. If the user clicks |
(...skipping 17 matching lines...) Expand all Loading... |
1347 DCHECK_EQ(200, response_.headers->response_code()); | 1366 DCHECK_EQ(200, response_.headers->response_code()); |
1348 } | 1367 } |
1349 | 1368 |
1350 if (!HttpCache::WriteResponseInfo(entry_->disk_entry, &response_, | 1369 if (!HttpCache::WriteResponseInfo(entry_->disk_entry, &response_, |
1351 skip_transient_headers, truncated)) { | 1370 skip_transient_headers, truncated)) { |
1352 DLOG(ERROR) << "failed to write response info to cache"; | 1371 DLOG(ERROR) << "failed to write response info to cache"; |
1353 DoneWritingToEntry(false); | 1372 DoneWritingToEntry(false); |
1354 } | 1373 } |
1355 } | 1374 } |
1356 | 1375 |
1357 void HttpCache::Transaction::AppendResponseDataToEntry(IOBuffer* data, | 1376 int HttpCache::Transaction::AppendResponseDataToEntry( |
1358 int data_len) { | 1377 IOBuffer* data, int data_len, CompletionCallback* callback) { |
1359 if (!entry_ || !data_len) | 1378 if (!entry_ || !data_len) |
1360 return; | 1379 return data_len; |
1361 | 1380 |
1362 int current_size = entry_->disk_entry->GetDataSize(kResponseContentIndex); | 1381 int current_size = entry_->disk_entry->GetDataSize(kResponseContentIndex); |
1363 WriteToEntry(kResponseContentIndex, current_size, data, data_len); | 1382 return WriteToEntry(kResponseContentIndex, current_size, data, data_len, |
| 1383 callback); |
1364 } | 1384 } |
1365 | 1385 |
1366 void HttpCache::Transaction::TruncateResponseData() { | 1386 void HttpCache::Transaction::TruncateResponseData() { |
1367 if (!entry_) | 1387 if (!entry_) |
1368 return; | 1388 return; |
1369 | 1389 |
1370 // Truncate the stream. | 1390 // Truncate the stream. |
1371 WriteToEntry(kResponseContentIndex, 0, NULL, 0); | 1391 int rv = WriteToEntry(kResponseContentIndex, 0, NULL, 0, NULL); |
| 1392 DCHECK(rv != ERR_IO_PENDING); |
1372 } | 1393 } |
1373 | 1394 |
1374 void HttpCache::Transaction::DoneWritingToEntry(bool success) { | 1395 void HttpCache::Transaction::DoneWritingToEntry(bool success) { |
1375 if (!entry_) | 1396 if (!entry_) |
1376 return; | 1397 return; |
1377 | 1398 |
1378 if (cache_->mode() == RECORD) | 1399 if (cache_->mode() == RECORD) |
1379 DLOG(INFO) << "Recorded: " << request_->method << request_->url | 1400 DLOG(INFO) << "Recorded: " << request_->method << request_->url |
1380 << " status: " << response_.headers->response_code(); | 1401 << " status: " << response_.headers->response_code(); |
1381 | 1402 |
1382 cache_->DoneWritingToEntry(entry_, success); | 1403 cache_->DoneWritingToEntry(entry_, success); |
1383 entry_ = NULL; | 1404 entry_ = NULL; |
1384 mode_ = NONE; // switch to 'pass through' mode | 1405 mode_ = NONE; // switch to 'pass through' mode |
1385 } | 1406 } |
1386 | 1407 |
1387 void HttpCache::Transaction::DoomPartialEntry(bool delete_object) { | 1408 void HttpCache::Transaction::DoomPartialEntry(bool delete_object) { |
1388 cache_->DoneWithEntry(entry_, this, false); | 1409 cache_->DoneWithEntry(entry_, this, false); |
1389 cache_->DoomEntry(cache_key_); | 1410 cache_->DoomEntry(cache_key_); |
1390 entry_ = NULL; | 1411 entry_ = NULL; |
1391 if (delete_object) | 1412 if (delete_object) |
1392 partial_.reset(NULL); | 1413 partial_.reset(NULL); |
1393 } | 1414 } |
1394 | 1415 |
1395 int HttpCache::Transaction::DoNetworkReadCompleted(int result) { | 1416 int HttpCache::Transaction::DoNetworkReadCompleted(int result) { |
1396 DCHECK(mode_ & WRITE || mode_ == NONE); | 1417 DCHECK(mode_ & WRITE || mode_ == NONE); |
1397 | 1418 |
1398 if (revoked()) | 1419 if (revoked()) |
1399 return HandleResult(ERR_UNEXPECTED); | 1420 return HandleResult(ERR_UNEXPECTED); |
1400 | 1421 |
1401 AppendResponseDataToEntry(read_buf_, result); | 1422 cache_write_callback_->AddRef(); // Balanced in DoCacheWriteCompleted. |
1402 | 1423 |
1403 if (partial_.get()) | 1424 result = AppendResponseDataToEntry(read_buf_, result, cache_write_callback_); |
1404 return DoPartialNetworkReadCompleted(result); | 1425 if (result == ERR_IO_PENDING) |
| 1426 return result; |
1405 | 1427 |
1406 if (result == 0) // End of file. | 1428 return DoCacheWriteCompleted(result); |
1407 DoneWritingToEntry(true); | |
1408 | |
1409 return HandleResult(result); | |
1410 } | 1429 } |
1411 | 1430 |
1412 int HttpCache::Transaction::DoPartialNetworkReadCompleted(int result) { | 1431 int HttpCache::Transaction::DoPartialNetworkReadCompleted(int result) { |
1413 partial_->OnNetworkReadCompleted(result); | 1432 partial_->OnNetworkReadCompleted(result); |
1414 | 1433 |
1415 if (result == 0) { // End of file. | 1434 if (result == 0) { // End of file. |
1416 if (mode_ == READ_WRITE) { | 1435 if (mode_ == READ_WRITE) { |
1417 // We need to move on to the next range. | 1436 // We need to move on to the next range. |
1418 network_trans_.reset(); | 1437 network_trans_.reset(); |
1419 result = ContinuePartialCacheValidation(); | 1438 result = ContinuePartialCacheValidation(); |
1420 if (result != OK) | 1439 if (result != OK) |
1421 // Any error was already handled. | 1440 // Any error was already handled. |
1422 return result; | 1441 return result; |
1423 } | 1442 } |
1424 DoneWritingToEntry(true); | 1443 DoneWritingToEntry(true); |
1425 } | 1444 } |
1426 return HandleResult(result); | 1445 return HandleResult(result); |
1427 } | 1446 } |
1428 | 1447 |
1429 int HttpCache::Transaction::DoCacheReadCompleted(int result) { | 1448 int HttpCache::Transaction::DoCacheReadCompleted(int result) { |
1430 DCHECK(cache_); | 1449 DCHECK(cache_); |
1431 cache_read_callback_->Release(); // Balance the AddRef() from Start(). | |
1432 | 1450 |
1433 if (revoked()) | 1451 if (revoked()) |
1434 return HandleResult(ERR_UNEXPECTED); | 1452 return HandleResult(ERR_UNEXPECTED); |
1435 | 1453 |
1436 if (partial_.get()) | 1454 if (partial_.get()) |
1437 return DoPartialCacheReadCompleted(result); | 1455 return DoPartialCacheReadCompleted(result); |
1438 | 1456 |
1439 if (result > 0) { | 1457 if (result > 0) { |
1440 read_offset_ += result; | 1458 read_offset_ += result; |
1441 } else if (result == 0) { // End of file. | 1459 } else if (result == 0) { // End of file. |
(...skipping 14 matching lines...) Expand all Loading... |
1456 // Any error was already handled. | 1474 // Any error was already handled. |
1457 return result; | 1475 return result; |
1458 cache_->ConvertWriterToReader(entry_); | 1476 cache_->ConvertWriterToReader(entry_); |
1459 } | 1477 } |
1460 cache_->DoneReadingFromEntry(entry_, this); | 1478 cache_->DoneReadingFromEntry(entry_, this); |
1461 entry_ = NULL; | 1479 entry_ = NULL; |
1462 } | 1480 } |
1463 return HandleResult(result); | 1481 return HandleResult(result); |
1464 } | 1482 } |
1465 | 1483 |
| 1484 int HttpCache::Transaction::DoCacheWriteCompleted(int result) { |
| 1485 DCHECK(cache_); |
| 1486 // Balance the AddRef from DoNetworkReadCompleted. |
| 1487 cache_write_callback_->Release(); |
| 1488 if (revoked()) |
| 1489 return HandleResult(ERR_UNEXPECTED); |
| 1490 |
| 1491 if (result < 0) |
| 1492 return HandleResult(result); |
| 1493 |
| 1494 if (partial_.get()) |
| 1495 return DoPartialNetworkReadCompleted(result); |
| 1496 |
| 1497 if (result == 0) // End of file. |
| 1498 DoneWritingToEntry(true); |
| 1499 |
| 1500 return HandleResult(result); |
| 1501 } |
| 1502 |
1466 void HttpCache::Transaction::OnNetworkInfoAvailable(int result) { | 1503 void HttpCache::Transaction::OnNetworkInfoAvailable(int result) { |
1467 DCHECK(result != ERR_IO_PENDING); | 1504 DCHECK(result != ERR_IO_PENDING); |
1468 | 1505 |
1469 if (revoked()) { | 1506 if (revoked()) { |
1470 HandleResult(ERR_UNEXPECTED); | 1507 HandleResult(ERR_UNEXPECTED); |
1471 return; | 1508 return; |
1472 } | 1509 } |
1473 | 1510 |
1474 if (result == OK) { | 1511 if (result == OK) { |
1475 const HttpResponseInfo* new_response = network_trans_->GetResponseInfo(); | 1512 const HttpResponseInfo* new_response = network_trans_->GetResponseInfo(); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1570 response_.cert_request_info = response->cert_request_info; | 1607 response_.cert_request_info = response->cert_request_info; |
1571 } | 1608 } |
1572 HandleResult(result); | 1609 HandleResult(result); |
1573 } | 1610 } |
1574 | 1611 |
1575 void HttpCache::Transaction::OnNetworkReadCompleted(int result) { | 1612 void HttpCache::Transaction::OnNetworkReadCompleted(int result) { |
1576 DoNetworkReadCompleted(result); | 1613 DoNetworkReadCompleted(result); |
1577 } | 1614 } |
1578 | 1615 |
1579 void HttpCache::Transaction::OnCacheReadCompleted(int result) { | 1616 void HttpCache::Transaction::OnCacheReadCompleted(int result) { |
| 1617 cache_read_callback_->Release(); // Balance the AddRef from ReadFromEntry. |
1580 DoCacheReadCompleted(result); | 1618 DoCacheReadCompleted(result); |
1581 } | 1619 } |
1582 | 1620 |
| 1621 void HttpCache::Transaction::OnCacheWriteCompleted(int result) { |
| 1622 DoCacheWriteCompleted(result); |
| 1623 } |
| 1624 |
1583 //----------------------------------------------------------------------------- | 1625 //----------------------------------------------------------------------------- |
1584 | 1626 |
1585 HttpCache::HttpCache(HostResolver* host_resolver, | 1627 HttpCache::HttpCache(HostResolver* host_resolver, |
1586 ProxyService* proxy_service, | 1628 ProxyService* proxy_service, |
1587 SSLConfigService* ssl_config_service, | 1629 SSLConfigService* ssl_config_service, |
1588 const std::wstring& cache_dir, | 1630 const std::wstring& cache_dir, |
1589 int cache_size) | 1631 int cache_size) |
1590 : disk_cache_dir_(cache_dir), | 1632 : disk_cache_dir_(cache_dir), |
1591 mode_(NORMAL), | 1633 mode_(NORMAL), |
1592 type_(DISK_CACHE), | 1634 type_(DISK_CACHE), |
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2127 static_cast<net::HttpNetworkLayer*>(network_layer_.get()); | 2169 static_cast<net::HttpNetworkLayer*>(network_layer_.get()); |
2128 HttpNetworkSession* session = network->GetSession(); | 2170 HttpNetworkSession* session = network->GetSession(); |
2129 if (session) { | 2171 if (session) { |
2130 session->tcp_socket_pool()->CloseIdleSockets(); | 2172 session->tcp_socket_pool()->CloseIdleSockets(); |
2131 } | 2173 } |
2132 } | 2174 } |
2133 | 2175 |
2134 //----------------------------------------------------------------------------- | 2176 //----------------------------------------------------------------------------- |
2135 | 2177 |
2136 } // namespace net | 2178 } // namespace net |
OLD | NEW |