OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 | 183 |
184 // Clean up the transaction. | 184 // Clean up the transaction. |
185 virtual ~Transaction(); | 185 virtual ~Transaction(); |
186 | 186 |
187 // HttpTransaction methods: | 187 // HttpTransaction methods: |
188 virtual int Start(const HttpRequestInfo*, CompletionCallback*); | 188 virtual int Start(const HttpRequestInfo*, CompletionCallback*); |
189 virtual int RestartIgnoringLastError(CompletionCallback*); | 189 virtual int RestartIgnoringLastError(CompletionCallback*); |
190 virtual int RestartWithAuth(const std::wstring& username, | 190 virtual int RestartWithAuth(const std::wstring& username, |
191 const std::wstring& password, | 191 const std::wstring& password, |
192 CompletionCallback* callback); | 192 CompletionCallback* callback); |
193 virtual int Read(char* buf, int buf_len, CompletionCallback*); | 193 virtual int Read(IOBuffer* buf, int buf_len, CompletionCallback*); |
194 virtual const HttpResponseInfo* GetResponseInfo() const; | 194 virtual const HttpResponseInfo* GetResponseInfo() const; |
195 virtual LoadState GetLoadState() const; | 195 virtual LoadState GetLoadState() const; |
196 virtual uint64 GetUploadProgress(void) const; | 196 virtual uint64 GetUploadProgress(void) const; |
197 | 197 |
198 // The transaction has the following modes, which apply to how it may access | 198 // The transaction has the following modes, which apply to how it may access |
199 // its cache entry. | 199 // its cache entry. |
200 // | 200 // |
201 // o If the mode of the transaction is NONE, then it is in "pass through" | 201 // o If the mode of the transaction is NONE, then it is in "pass through" |
202 // mode and all methods just forward to the inner network transaction. | 202 // mode and all methods just forward to the inner network transaction. |
203 // | 203 // |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 auth_response_ = HttpResponseInfo(); | 404 auth_response_ = HttpResponseInfo(); |
405 | 405 |
406 int rv = RestartNetworkRequestWithAuth(username, password); | 406 int rv = RestartNetworkRequestWithAuth(username, password); |
407 | 407 |
408 if (rv == ERR_IO_PENDING) | 408 if (rv == ERR_IO_PENDING) |
409 callback_ = callback; | 409 callback_ = callback; |
410 | 410 |
411 return rv; | 411 return rv; |
412 } | 412 } |
413 | 413 |
414 int HttpCache::Transaction::Read(char* buf, int buf_len, | 414 int HttpCache::Transaction::Read(IOBuffer* buf, int buf_len, |
415 CompletionCallback* callback) { | 415 CompletionCallback* callback) { |
416 DCHECK(buf); | 416 DCHECK(buf); |
417 DCHECK(buf_len > 0); | 417 DCHECK(buf_len > 0); |
418 DCHECK(callback); | 418 DCHECK(callback); |
419 | 419 |
420 DCHECK(!callback_); | 420 DCHECK(!callback_); |
421 | 421 |
422 // If we have an intermediate auth response at this point, then it means the | 422 // If we have an intermediate auth response at this point, then it means the |
423 // user wishes to read the network response (the error page). If there is a | 423 // user wishes to read the network response (the error page). If there is a |
424 // previous response in the cache then we should leave it intact. | 424 // previous response in the cache then we should leave it intact. |
425 if (auth_response_.headers && mode_ != NONE) { | 425 if (auth_response_.headers && mode_ != NONE) { |
426 DCHECK(mode_ & WRITE); | 426 DCHECK(mode_ & WRITE); |
427 DoneWritingToEntry(mode_ == READ_WRITE); | 427 DoneWritingToEntry(mode_ == READ_WRITE); |
428 mode_ = NONE; | 428 mode_ = NONE; |
429 } | 429 } |
430 | 430 |
431 int rv; | 431 int rv; |
432 | 432 |
433 switch (mode_) { | 433 switch (mode_) { |
434 case NONE: | 434 case NONE: |
435 case WRITE: | 435 case WRITE: |
436 DCHECK(network_trans_.get()); | 436 DCHECK(network_trans_.get()); |
437 rv = network_trans_->Read(buf, buf_len, &network_read_callback_); | 437 rv = network_trans_->Read(buf, buf_len, &network_read_callback_); |
438 read_buf_ = buf; | 438 read_buf_ = buf->data(); |
439 if (rv >= 0) | 439 if (rv >= 0) |
440 OnNetworkReadCompleted(rv); | 440 OnNetworkReadCompleted(rv); |
441 break; | 441 break; |
442 case READ: | 442 case READ: |
443 DCHECK(entry_); | 443 DCHECK(entry_); |
444 cache_read_callback_->AddRef(); // Balanced in OnCacheReadCompleted | 444 cache_read_callback_->AddRef(); // Balanced in OnCacheReadCompleted. |
| 445 cache_read_callback_->UseBuffer(buf); |
445 rv = entry_->disk_entry->ReadData(kResponseContentIndex, read_offset_, | 446 rv = entry_->disk_entry->ReadData(kResponseContentIndex, read_offset_, |
446 buf, buf_len, cache_read_callback_); | 447 buf->data(), buf_len, |
447 read_buf_ = buf; | 448 cache_read_callback_); |
| 449 read_buf_ = buf->data(); |
448 if (rv >= 0) { | 450 if (rv >= 0) { |
449 OnCacheReadCompleted(rv); | 451 OnCacheReadCompleted(rv); |
450 } else if (rv != ERR_IO_PENDING) { | 452 } else if (rv != ERR_IO_PENDING) { |
451 cache_read_callback_->Release(); | 453 cache_read_callback_->Release(); |
| 454 cache_read_callback_->ReleaseBuffer(); |
452 } | 455 } |
453 break; | 456 break; |
454 default: | 457 default: |
455 NOTREACHED(); | 458 NOTREACHED(); |
456 rv = ERR_FAILED; | 459 rv = ERR_FAILED; |
457 } | 460 } |
458 | 461 |
459 if (rv == ERR_IO_PENDING) | 462 if (rv == ERR_IO_PENDING) |
460 callback_ = callback; | 463 callback_ = callback; |
461 return rv; | 464 return rv; |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
896 if (result > 0) { | 899 if (result > 0) { |
897 AppendResponseDataToEntry(read_buf_, result); | 900 AppendResponseDataToEntry(read_buf_, result); |
898 } else if (result == 0) { // end of file | 901 } else if (result == 0) { // end of file |
899 DoneWritingToEntry(true); | 902 DoneWritingToEntry(true); |
900 } | 903 } |
901 HandleResult(result); | 904 HandleResult(result); |
902 } | 905 } |
903 | 906 |
904 void HttpCache::Transaction::OnCacheReadCompleted(int result) { | 907 void HttpCache::Transaction::OnCacheReadCompleted(int result) { |
905 DCHECK(cache_); | 908 DCHECK(cache_); |
906 cache_read_callback_->Release(); // Balance the AddRef() from Start() | 909 cache_read_callback_->Release(); // Balance the AddRef() from Start(). |
| 910 cache_read_callback_->ReleaseBuffer(); |
907 | 911 |
908 if (result > 0) { | 912 if (result > 0) { |
909 read_offset_ += result; | 913 read_offset_ += result; |
910 } else if (result == 0) { // end of file | 914 } else if (result == 0) { // end of file |
911 cache_->DoneReadingFromEntry(entry_, this); | 915 cache_->DoneReadingFromEntry(entry_, this); |
912 entry_ = NULL; | 916 entry_ = NULL; |
913 } | 917 } |
914 HandleResult(result); | 918 HandleResult(result); |
915 } | 919 } |
916 | 920 |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1371 | 1375 |
1372 entry->pending_queue.erase(entry->pending_queue.begin()); | 1376 entry->pending_queue.erase(entry->pending_queue.begin()); |
1373 | 1377 |
1374 AddTransactionToEntry(entry, next); | 1378 AddTransactionToEntry(entry, next); |
1375 } | 1379 } |
1376 | 1380 |
1377 //----------------------------------------------------------------------------- | 1381 //----------------------------------------------------------------------------- |
1378 | 1382 |
1379 } // namespace net | 1383 } // namespace net |
1380 | 1384 |
OLD | NEW |