| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef NET_HTTP_PARTIAL_DATA_H_ | 5 #ifndef NET_HTTP_PARTIAL_DATA_H_ |
| 6 #define NET_HTTP_PARTIAL_DATA_H_ | 6 #define NET_HTTP_PARTIAL_DATA_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "net/base/completion_callback.h" | 10 #include "net/base/completion_callback.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 | 71 |
| 72 // Extracts info from headers already stored in the cache. Returns false if | 72 // Extracts info from headers already stored in the cache. Returns false if |
| 73 // there is any problem with the headers. |truncated| should be true if we | 73 // there is any problem with the headers. |truncated| should be true if we |
| 74 // have an incomplete 200 entry. | 74 // have an incomplete 200 entry. |
| 75 bool UpdateFromStoredHeaders(const HttpResponseHeaders* headers, | 75 bool UpdateFromStoredHeaders(const HttpResponseHeaders* headers, |
| 76 disk_cache::Entry* entry, bool truncated); | 76 disk_cache::Entry* entry, bool truncated); |
| 77 | 77 |
| 78 // Sets the byte current range to start again at zero (for a truncated entry). | 78 // Sets the byte current range to start again at zero (for a truncated entry). |
| 79 void SetRangeToStartDownload(); | 79 void SetRangeToStartDownload(); |
| 80 | 80 |
| 81 // Switch state to assume that the remainder of the response will be furnished |
| 82 // via a network reqeust. Subsequent calls to |
| 83 // ShouldValidateCache()/PrepareCacheValidation() will act as if the remainder |
| 84 // of the response is not present in the cache and should be fetched over the |
| 85 // network with validation. |
| 86 // |
| 87 // Returns true on success and false on failure. Fails only if the entire |
| 88 // response has already been furnished and there is no need for any additional |
| 89 // network reqeusts. |
| 90 bool SkipCacheForRemainder(); |
| 91 |
| 81 // Returns true if the requested range is valid given the stored data. | 92 // Returns true if the requested range is valid given the stored data. |
| 82 bool IsRequestedRangeOK(); | 93 bool IsRequestedRangeOK(); |
| 83 | 94 |
| 84 // Returns true if the response headers match what we expect, false otherwise. | 95 // Returns true if the response headers match what we expect, false otherwise. |
| 85 bool ResponseHeadersOK(const HttpResponseHeaders* headers); | 96 bool ResponseHeadersOK(const HttpResponseHeaders* headers); |
| 86 | 97 |
| 87 // Fixes the response headers to include the right content length and range. | 98 // Fixes the response headers to include the right content length and range. |
| 88 // |success| is the result of the whole request so if it's false, we'll change | 99 // |success| is the result of the whole request so if it's false, we'll change |
| 89 // the result code to be 416. | 100 // the result code to be 416. |
| 90 void FixResponseHeaders(HttpResponseHeaders* headers, bool success); | 101 void FixResponseHeaders(HttpResponseHeaders* headers, bool success); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 113 // the internal state about the current range. | 124 // the internal state about the current range. |
| 114 void OnCacheReadCompleted(int result); | 125 void OnCacheReadCompleted(int result); |
| 115 | 126 |
| 116 // This method should be called after receiving data from the network, to | 127 // This method should be called after receiving data from the network, to |
| 117 // update the internal state about the current range. | 128 // update the internal state about the current range. |
| 118 void OnNetworkReadCompleted(int result); | 129 void OnNetworkReadCompleted(int result); |
| 119 | 130 |
| 120 bool initial_validation() const { return initial_validation_; } | 131 bool initial_validation() const { return initial_validation_; } |
| 121 | 132 |
| 122 private: | 133 private: |
| 123 // Returns the length to use when scanning the cache. | |
| 124 int GetNextRangeLen(); | |
| 125 | |
| 126 // Completion routine for our callback. | 134 // Completion routine for our callback. |
| 127 void GetAvailableRangeCompleted(int64* start, int result); | 135 void GetAvailableRangeCompleted(int64* start, int result); |
| 128 | 136 |
| 129 int64 current_range_start_; | 137 int64 current_range_start_; |
| 130 int64 current_range_end_; | 138 int64 current_range_end_; |
| 131 int64 cached_start_; | 139 int64 cached_start_; |
| 132 int64 resource_size_; | 140 int64 resource_size_; |
| 133 int cached_min_len_; | 141 int64 cached_min_len_; |
| 134 HttpByteRange byte_range_; // The range requested by the user. | 142 HttpByteRange byte_range_; // The range requested by the user. |
| 135 // The clean set of extra headers (no ranges). | 143 // The clean set of extra headers (no ranges). |
| 136 HttpRequestHeaders extra_headers_; | 144 HttpRequestHeaders extra_headers_; |
| 137 bool range_present_; // True if next range entry is already stored. | 145 bool range_present_; // True if next range entry is already stored. |
| 138 bool final_range_; | 146 bool final_range_; |
| 139 bool sparse_entry_; | 147 bool sparse_entry_; |
| 140 bool truncated_; // We have an incomplete 200 stored. | 148 bool truncated_; // We have an incomplete 200 stored. |
| 141 bool initial_validation_; // Only used for truncated entries. | 149 bool initial_validation_; // Only used for truncated entries. |
| 142 CompletionCallback callback_; | 150 CompletionCallback callback_; |
| 143 base::WeakPtrFactory<PartialData> weak_factory_; | 151 base::WeakPtrFactory<PartialData> weak_factory_; |
| 144 | 152 |
| 145 DISALLOW_COPY_AND_ASSIGN(PartialData); | 153 DISALLOW_COPY_AND_ASSIGN(PartialData); |
| 146 }; | 154 }; |
| 147 | 155 |
| 148 } // namespace net | 156 } // namespace net |
| 149 | 157 |
| 150 #endif // NET_HTTP_PARTIAL_DATA_H_ | 158 #endif // NET_HTTP_PARTIAL_DATA_H_ |
| OLD | NEW |