| 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 #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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "net/base/completion_callback.h" | 10 #include "net/base/completion_callback.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 // Returns true if the current range is the last one needed to fulfill the | 68 // Returns true if the current range is the last one needed to fulfill the |
| 69 // user's request. | 69 // user's request. |
| 70 bool IsLastRange() const; | 70 bool IsLastRange() const; |
| 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). |
| 79 void SetRangeToStartDownload(); |
| 80 |
| 78 // Returns true if the requested range is valid given the stored data. | 81 // Returns true if the requested range is valid given the stored data. |
| 79 bool IsRequestedRangeOK(); | 82 bool IsRequestedRangeOK(); |
| 80 | 83 |
| 81 // Returns true if the response headers match what we expect, false otherwise. | 84 // Returns true if the response headers match what we expect, false otherwise. |
| 82 bool ResponseHeadersOK(const HttpResponseHeaders* headers); | 85 bool ResponseHeadersOK(const HttpResponseHeaders* headers); |
| 83 | 86 |
| 84 // Fixes the response headers to include the right content length and range. | 87 // Fixes the response headers to include the right content length and range. |
| 85 // |success| is the result of the whole request so if it's false, we'll change | 88 // |success| is the result of the whole request so if it's false, we'll change |
| 86 // the result code to be 416. | 89 // the result code to be 416. |
| 87 void FixResponseHeaders(HttpResponseHeaders* headers, bool success); | 90 void FixResponseHeaders(HttpResponseHeaders* headers, bool success); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 103 CompletionCallback* callback); | 106 CompletionCallback* callback); |
| 104 | 107 |
| 105 // This method should be called when CacheRead() finishes the read, to update | 108 // This method should be called when CacheRead() finishes the read, to update |
| 106 // the internal state about the current range. | 109 // the internal state about the current range. |
| 107 void OnCacheReadCompleted(int result); | 110 void OnCacheReadCompleted(int result); |
| 108 | 111 |
| 109 // This method should be called after receiving data from the network, to | 112 // This method should be called after receiving data from the network, to |
| 110 // update the internal state about the current range. | 113 // update the internal state about the current range. |
| 111 void OnNetworkReadCompleted(int result); | 114 void OnNetworkReadCompleted(int result); |
| 112 | 115 |
| 116 bool initial_validation() const { return initial_validation_; } |
| 117 |
| 113 private: | 118 private: |
| 114 class Core; | 119 class Core; |
| 115 // Returns the length to use when scanning the cache. | 120 // Returns the length to use when scanning the cache. |
| 116 int GetNextRangeLen(); | 121 int GetNextRangeLen(); |
| 117 | 122 |
| 118 // Completion routine for our callback. | 123 // Completion routine for our callback. |
| 119 void GetAvailableRangeCompleted(int result, int64 start); | 124 void GetAvailableRangeCompleted(int result, int64 start); |
| 120 | 125 |
| 121 int64 current_range_start_; | 126 int64 current_range_start_; |
| 122 int64 cached_start_; | 127 int64 cached_start_; |
| 123 int64 resource_size_; | 128 int64 resource_size_; |
| 124 int cached_min_len_; | 129 int cached_min_len_; |
| 125 HttpByteRange byte_range_; // The range requested by the user. | 130 HttpByteRange byte_range_; // The range requested by the user. |
| 126 // The clean set of extra headers (no ranges). | 131 // The clean set of extra headers (no ranges). |
| 127 HttpRequestHeaders extra_headers_; | 132 HttpRequestHeaders extra_headers_; |
| 128 bool range_present_; // True if next range entry is already stored. | 133 bool range_present_; // True if next range entry is already stored. |
| 129 bool final_range_; | 134 bool final_range_; |
| 130 bool sparse_entry_; | 135 bool sparse_entry_; |
| 131 bool truncated_; // We have an incomplete 200 stored. | 136 bool truncated_; // We have an incomplete 200 stored. |
| 137 bool initial_validation_; // Only used for truncated entries. |
| 132 Core* core_; | 138 Core* core_; |
| 133 CompletionCallback* callback_; | 139 CompletionCallback* callback_; |
| 134 | 140 |
| 135 DISALLOW_COPY_AND_ASSIGN(PartialData); | 141 DISALLOW_COPY_AND_ASSIGN(PartialData); |
| 136 }; | 142 }; |
| 137 | 143 |
| 138 } // namespace net | 144 } // namespace net |
| 139 | 145 |
| 140 #endif // NET_HTTP_PARTIAL_DATA_H_ | 146 #endif // NET_HTTP_PARTIAL_DATA_H_ |
| OLD | NEW |