| 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_transaction.h" | 5 #include "net/http/http_cache_transaction.h" |
| 6 | 6 |
| 7 #include "build/build_config.h" // For OS_POSIX | 7 #include "build/build_config.h" // For OS_POSIX |
| 8 | 8 |
| 9 #if defined(OS_POSIX) | 9 #if defined(OS_POSIX) |
| 10 #include <unistd.h> | 10 #include <unistd.h> |
| 11 #endif | 11 #endif |
| 12 | 12 |
| 13 #include <algorithm> | 13 #include <algorithm> |
| 14 #include <string> | 14 #include <string> |
| 15 | 15 |
| 16 #include "base/bind.h" | 16 #include "base/bind.h" |
| 17 #include "base/callback_helpers.h" | 17 #include "base/callback_helpers.h" |
| 18 #include "base/compiler_specific.h" | 18 #include "base/compiler_specific.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/macros.h" |
| 21 #include "base/metrics/histogram_macros.h" | 22 #include "base/metrics/histogram_macros.h" |
| 22 #include "base/metrics/sparse_histogram.h" | 23 #include "base/metrics/sparse_histogram.h" |
| 23 #include "base/single_thread_task_runner.h" | 24 #include "base/single_thread_task_runner.h" |
| 24 #include "base/strings/string_number_conversions.h" // For HexEncode. | 25 #include "base/strings/string_number_conversions.h" // For HexEncode. |
| 25 #include "base/strings/string_piece.h" | 26 #include "base/strings/string_piece.h" |
| 26 #include "base/strings/string_util.h" // For LowerCaseEqualsASCII. | 27 #include "base/strings/string_util.h" // For LowerCaseEqualsASCII. |
| 27 #include "base/strings/stringprintf.h" | 28 #include "base/strings/stringprintf.h" |
| 28 #include "base/thread_task_runner_handle.h" | 29 #include "base/thread_task_runner_handle.h" |
| 29 #include "base/time/clock.h" | 30 #include "base/time/clock.h" |
| 30 #include "base/values.h" | 31 #include "base/values.h" |
| (...skipping 1844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1875 | 1876 |
| 1876 if (result != write_len_) { | 1877 if (result != write_len_) { |
| 1877 DLOG(ERROR) << "failed to write response data to cache"; | 1878 DLOG(ERROR) << "failed to write response data to cache"; |
| 1878 DoneWritingToEntry(false); | 1879 DoneWritingToEntry(false); |
| 1879 | 1880 |
| 1880 // We want to ignore errors writing to disk and just keep reading from | 1881 // We want to ignore errors writing to disk and just keep reading from |
| 1881 // the network. | 1882 // the network. |
| 1882 result = write_len_; | 1883 result = write_len_; |
| 1883 } else if (!done_reading_ && entry_ && (!partial_ || truncated_)) { | 1884 } else if (!done_reading_ && entry_ && (!partial_ || truncated_)) { |
| 1884 int current_size = entry_->disk_entry->GetDataSize(kResponseContentIndex); | 1885 int current_size = entry_->disk_entry->GetDataSize(kResponseContentIndex); |
| 1885 int64 body_size = response_.headers->GetContentLength(); | 1886 int64_t body_size = response_.headers->GetContentLength(); |
| 1886 if (body_size >= 0 && body_size <= current_size) | 1887 if (body_size >= 0 && body_size <= current_size) |
| 1887 done_reading_ = true; | 1888 done_reading_ = true; |
| 1888 } | 1889 } |
| 1889 | 1890 |
| 1890 if (partial_) { | 1891 if (partial_) { |
| 1891 // This may be the last request. | 1892 // This may be the last request. |
| 1892 if (result != 0 || truncated_ || | 1893 if (result != 0 || truncated_ || |
| 1893 !(partial_->IsLastRange() || mode_ == WRITE)) { | 1894 !(partial_->IsLastRange() || mode_ == WRITE)) { |
| 1894 return DoPartialNetworkReadCompleted(result); | 1895 return DoPartialNetworkReadCompleted(result); |
| 1895 } | 1896 } |
| (...skipping 998 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2894 transaction_pattern_ == PATTERN_ENTRY_CANT_CONDITIONALIZE)) || | 2895 transaction_pattern_ == PATTERN_ENTRY_CANT_CONDITIONALIZE)) || |
| 2895 (!did_send_request && transaction_pattern_ == PATTERN_ENTRY_USED)); | 2896 (!did_send_request && transaction_pattern_ == PATTERN_ENTRY_USED)); |
| 2896 | 2897 |
| 2897 if (!did_send_request) { | 2898 if (!did_send_request) { |
| 2898 DCHECK(transaction_pattern_ == PATTERN_ENTRY_USED); | 2899 DCHECK(transaction_pattern_ == PATTERN_ENTRY_USED); |
| 2899 UMA_HISTOGRAM_TIMES("HttpCache.AccessToDone.Used", total_time); | 2900 UMA_HISTOGRAM_TIMES("HttpCache.AccessToDone.Used", total_time); |
| 2900 return; | 2901 return; |
| 2901 } | 2902 } |
| 2902 | 2903 |
| 2903 TimeDelta before_send_time = send_request_since_ - first_cache_access_since_; | 2904 TimeDelta before_send_time = send_request_since_ - first_cache_access_since_; |
| 2904 int64 before_send_percent = (total_time.ToInternalValue() == 0) ? | 2905 int64_t before_send_percent = (total_time.ToInternalValue() == 0) |
| 2905 0 : before_send_time * 100 / total_time; | 2906 ? 0 |
| 2907 : before_send_time * 100 / total_time; |
| 2906 DCHECK_GE(before_send_percent, 0); | 2908 DCHECK_GE(before_send_percent, 0); |
| 2907 DCHECK_LE(before_send_percent, 100); | 2909 DCHECK_LE(before_send_percent, 100); |
| 2908 base::HistogramBase::Sample before_send_sample = | 2910 base::HistogramBase::Sample before_send_sample = |
| 2909 static_cast<base::HistogramBase::Sample>(before_send_percent); | 2911 static_cast<base::HistogramBase::Sample>(before_send_percent); |
| 2910 | 2912 |
| 2911 UMA_HISTOGRAM_TIMES("HttpCache.AccessToDone.SentRequest", total_time); | 2913 UMA_HISTOGRAM_TIMES("HttpCache.AccessToDone.SentRequest", total_time); |
| 2912 UMA_HISTOGRAM_TIMES("HttpCache.BeforeSend", before_send_time); | 2914 UMA_HISTOGRAM_TIMES("HttpCache.BeforeSend", before_send_time); |
| 2913 UMA_HISTOGRAM_PERCENTAGE("HttpCache.PercentBeforeSend", before_send_sample); | 2915 UMA_HISTOGRAM_PERCENTAGE("HttpCache.PercentBeforeSend", before_send_sample); |
| 2914 | 2916 |
| 2915 // TODO(gavinp): Remove or minimize these histograms, particularly the ones | 2917 // TODO(gavinp): Remove or minimize these histograms, particularly the ones |
| (...skipping 27 matching lines...) Expand all Loading... |
| 2943 default: | 2945 default: |
| 2944 NOTREACHED(); | 2946 NOTREACHED(); |
| 2945 } | 2947 } |
| 2946 } | 2948 } |
| 2947 | 2949 |
| 2948 void HttpCache::Transaction::OnIOComplete(int result) { | 2950 void HttpCache::Transaction::OnIOComplete(int result) { |
| 2949 DoLoop(result); | 2951 DoLoop(result); |
| 2950 } | 2952 } |
| 2951 | 2953 |
| 2952 } // namespace net | 2954 } // namespace net |
| OLD | NEW |