OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_transaction.h" | 5 #include "net/http/http_cache_transaction.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 | 8 |
9 #if defined(OS_POSIX) | 9 #if defined(OS_POSIX) |
10 #include <unistd.h> | 10 #include <unistd.h> |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 return ERR_UNEXPECTED; | 347 return ERR_UNEXPECTED; |
348 | 348 |
349 // We don't need to track this operation for anything. | 349 // We don't need to track this operation for anything. |
350 // It could be possible to check if there is something already written and | 350 // It could be possible to check if there is something already written and |
351 // avoid writing again (it should be the same, right?), but let's allow the | 351 // avoid writing again (it should be the same, right?), but let's allow the |
352 // caller to "update" the contents with something new. | 352 // caller to "update" the contents with something new. |
353 return entry_->disk_entry->WriteData(kMetadataIndex, 0, buf, buf_len, | 353 return entry_->disk_entry->WriteData(kMetadataIndex, 0, buf, buf_len, |
354 callback, true); | 354 callback, true); |
355 } | 355 } |
356 | 356 |
| 357 // Histogram data from the end of 2010 show the following distribution of |
| 358 // response headers: |
| 359 // |
| 360 // Content-Length............... 87% |
| 361 // Date......................... 98% |
| 362 // Last-Modified................ 49% |
| 363 // Etag......................... 19% |
| 364 // Accept-Ranges: bytes......... 25% |
| 365 // Accept-Ranges: none.......... 0.4% |
| 366 // Strong Validator............. 50% |
| 367 // Strong Validator + ranges.... 24% |
| 368 // Strong Validator + CL........ 49% |
| 369 // |
357 bool HttpCache::Transaction::AddTruncatedFlag() { | 370 bool HttpCache::Transaction::AddTruncatedFlag() { |
358 DCHECK(mode_ & WRITE); | 371 DCHECK(mode_ & WRITE); |
359 | 372 |
360 // Don't set the flag for sparse entries. | 373 // Don't set the flag for sparse entries. |
361 if (partial_.get() && !truncated_) | 374 if (partial_.get() && !truncated_) |
362 return true; | 375 return true; |
363 | 376 |
364 // Double check that there is something worth keeping. | 377 // Double check that there is something worth keeping. |
365 if (!entry_->disk_entry->GetDataSize(kResponseContentIndex)) | 378 if (!entry_->disk_entry->GetDataSize(kResponseContentIndex)) |
366 return false; | 379 return false; |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 // sending a range. We have to delete the old entry. | 694 // sending a range. We have to delete the old entry. |
682 DoneWritingToEntry(false); | 695 DoneWritingToEntry(false); |
683 } | 696 } |
684 | 697 |
685 if (new_response_->headers->response_code() == 416) { | 698 if (new_response_->headers->response_code() == 416) { |
686 DCHECK_EQ(NONE, mode_); | 699 DCHECK_EQ(NONE, mode_); |
687 response_ = *new_response_; | 700 response_ = *new_response_; |
688 return OK; | 701 return OK; |
689 } | 702 } |
690 | 703 |
691 HistogramHeaders(new_response->headers); | |
692 | |
693 // Are we expecting a response to a conditional query? | 704 // Are we expecting a response to a conditional query? |
694 if (mode_ == READ_WRITE || mode_ == UPDATE) { | 705 if (mode_ == READ_WRITE || mode_ == UPDATE) { |
695 if (new_response->headers->response_code() == 304 || | 706 if (new_response->headers->response_code() == 304 || |
696 server_responded_206_) { | 707 server_responded_206_) { |
697 next_state_ = STATE_UPDATE_CACHED_RESPONSE; | 708 next_state_ = STATE_UPDATE_CACHED_RESPONSE; |
698 return OK; | 709 return OK; |
699 } | 710 } |
700 mode_ = WRITE; | 711 mode_ = WRITE; |
701 } | 712 } |
702 | 713 |
(...skipping 1147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1850 int HttpCache::Transaction::DoPartialCacheReadCompleted(int result) { | 1861 int HttpCache::Transaction::DoPartialCacheReadCompleted(int result) { |
1851 partial_->OnCacheReadCompleted(result); | 1862 partial_->OnCacheReadCompleted(result); |
1852 | 1863 |
1853 if (result == 0 && mode_ == READ_WRITE) { | 1864 if (result == 0 && mode_ == READ_WRITE) { |
1854 // We need to move on to the next range. | 1865 // We need to move on to the next range. |
1855 next_state_ = STATE_START_PARTIAL_CACHE_VALIDATION; | 1866 next_state_ = STATE_START_PARTIAL_CACHE_VALIDATION; |
1856 } | 1867 } |
1857 return result; | 1868 return result; |
1858 } | 1869 } |
1859 | 1870 |
1860 // For a 200 response we'll add a histogram with one bit set per header: | |
1861 // 0x01 Content-Length | |
1862 // 0x02 Date | |
1863 // 0x04 Last-Modified | |
1864 // 0x08 Etag | |
1865 // 0x10 Accept-Ranges: bytes | |
1866 // 0x20 Accept-Ranges: none | |
1867 // | |
1868 // TODO(rvargas): remove after having some results. | |
1869 void HttpCache::Transaction::HistogramHeaders( | |
1870 const HttpResponseHeaders* headers) { | |
1871 if (headers->response_code() != 200) | |
1872 return; | |
1873 | |
1874 int64 content_length = headers->GetContentLength(); | |
1875 int value = 0; | |
1876 if (content_length > 0) | |
1877 value = 1; | |
1878 | |
1879 Time date; | |
1880 if (headers->GetDateValue(&date)) | |
1881 value += 2; | |
1882 if (headers->GetLastModifiedValue(&date)) | |
1883 value += 4; | |
1884 | |
1885 std::string etag; | |
1886 headers->EnumerateHeader(NULL, "etag", &etag); | |
1887 if (!etag.empty()) | |
1888 value += 8; | |
1889 | |
1890 std::string accept_ranges("Accept-Ranges"); | |
1891 if (headers->HasHeaderValue(accept_ranges, "bytes")) | |
1892 value += 0x10; | |
1893 if (headers->HasHeaderValue(accept_ranges, "none")) | |
1894 value += 0x20; | |
1895 | |
1896 // |value| goes from 0 to 63. Actually, the max value should be 47 (0x2f) | |
1897 // but we'll see. | |
1898 UMA_HISTOGRAM_ENUMERATION("HttpCache.ResponseHeaders", value, 65); | |
1899 } | |
1900 | |
1901 void HttpCache::Transaction::OnIOComplete(int result) { | 1871 void HttpCache::Transaction::OnIOComplete(int result) { |
1902 DoLoop(result); | 1872 DoLoop(result); |
1903 } | 1873 } |
1904 | 1874 |
1905 } // namespace net | 1875 } // namespace net |
OLD | NEW |