Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(419)

Side by Side Diff: net/http/partial_data.h

Issue 197016: Http Cache: Add support for resuming downloading a... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/http/http_cache_unittest.cc ('k') | net/http/partial_data.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 14 matching lines...) Expand all
25 // these requests. This class is tightly integrated with HttpCache::Transaction 25 // these requests. This class is tightly integrated with HttpCache::Transaction
26 // and it is intended to allow a cleaner implementation of that class. 26 // and it is intended to allow a cleaner implementation of that class.
27 // 27 //
28 // In order to fulfill range requests, we may have to perform a sequence of 28 // In order to fulfill range requests, we may have to perform a sequence of
29 // reads from the cache, interleaved with reads from the network / writes to the 29 // reads from the cache, interleaved with reads from the network / writes to the
30 // cache. This class basically keeps track of the data required to perform each 30 // cache. This class basically keeps track of the data required to perform each
31 // of those individual network / cache requests. 31 // of those individual network / cache requests.
32 class PartialData { 32 class PartialData {
33 public: 33 public:
34 PartialData() 34 PartialData()
35 : range_present_(false), final_range_(false), sparse_entry_(true) {} 35 : range_present_(false), final_range_(false), sparse_entry_(true),
36 truncated_(false) {}
36 ~PartialData() {} 37 ~PartialData() {}
37 38
38 // Performs initialization of the object by parsing the request |headers| 39 // Performs initialization of the object by parsing the request |headers|
39 // and verifying that we can process the requested range. Returns true if 40 // and verifying that we can process the requested range. Returns true if
40 // we can process the requested range, and false otherwise. |new_headers| is 41 // we can process the requested range, and false otherwise. |new_headers| is
41 // a subset of the request extra headers, with byte-range related headers 42 // a subset of the request extra headers, with byte-range related headers
42 // removed so that we can easily add any byte-range that we need. 43 // removed so that we can easily add any byte-range that we need.
43 bool Init(const std::string& headers, const std::string& new_headers); 44 bool Init(const std::string& headers, const std::string& new_headers);
44 45
45 // Restores the byte-range header that was removed during Init(), by appending 46 // Restores the byte-range header that was removed during Init(), by appending
46 // the data to the provided |headers|. 47 // the data to the provided |headers|.
47 void RestoreHeaders(std::string* headers) const; 48 void RestoreHeaders(std::string* headers) const;
48 49
49 // Builds the required |headers| to perform the proper cache validation for 50 // Builds the required |headers| to perform the proper cache validation for
50 // the next range to be fetched. Returns 0 when there is no need to perform 51 // the next range to be fetched. Returns 0 when there is no need to perform
51 // more operations because we reached the end of the request (so 0 bytes 52 // more operations because we reached the end of the request (so 0 bytes
52 // should be actually returned to the user), a positive number to indicate 53 // should be actually returned to the user), a positive number to indicate
53 // that |headers| should be used to validate the cache, or an appropriate 54 // that |headers| should be used to validate the cache, or an appropriate
54 // error code. 55 // error code.
55 int PrepareCacheValidation(disk_cache::Entry* entry, std::string* headers); 56 int PrepareCacheValidation(disk_cache::Entry* entry, std::string* headers);
56 57
57 // Returns true if the current range is stored in the cache. 58 // Returns true if the current range is stored in the cache.
58 bool IsCurrentRangeCached() const; 59 bool IsCurrentRangeCached() const;
59 60
60 // Returns true if the current range is the last one needed to fulfill the 61 // Returns true if the current range is the last one needed to fulfill the
61 // user's request. 62 // user's request.
62 bool IsLastRange() const; 63 bool IsLastRange() const;
63 64
64 // Extracts info from headers already stored in the cache. Returns false if 65 // Extracts info from headers already stored in the cache. Returns false if
65 // there is any problem with the headers. 66 // there is any problem with the headers. |truncated| should be true if we
67 // have an incomplete 200 entry.
66 bool UpdateFromStoredHeaders(const HttpResponseHeaders* headers, 68 bool UpdateFromStoredHeaders(const HttpResponseHeaders* headers,
67 disk_cache::Entry* entry); 69 disk_cache::Entry* entry, bool truncated);
68 70
69 // Returns true if the requested range is valid given the stored data. 71 // Returns true if the requested range is valid given the stored data.
70 bool IsRequestedRangeOK(); 72 bool IsRequestedRangeOK();
71 73
72 // Returns true if the response headers match what we expect, false otherwise. 74 // Returns true if the response headers match what we expect, false otherwise.
73 bool ResponseHeadersOK(const HttpResponseHeaders* headers); 75 bool ResponseHeadersOK(const HttpResponseHeaders* headers);
74 76
75 // Fixes the response headers to include the right content length and range. 77 // Fixes the response headers to include the right content length and range.
76 void FixResponseHeaders(HttpResponseHeaders* headers); 78 void FixResponseHeaders(HttpResponseHeaders* headers);
77 79
(...skipping 26 matching lines...) Expand all
104 106
105 int64 current_range_start_; 107 int64 current_range_start_;
106 int64 cached_start_; 108 int64 cached_start_;
107 int64 resource_size_; 109 int64 resource_size_;
108 int cached_min_len_; 110 int cached_min_len_;
109 HttpByteRange byte_range_; // The range requested by the user. 111 HttpByteRange byte_range_; // The range requested by the user.
110 std::string extra_headers_; // The clean set of extra headers (no ranges). 112 std::string extra_headers_; // The clean set of extra headers (no ranges).
111 bool range_present_; // True if next range entry is already stored. 113 bool range_present_; // True if next range entry is already stored.
112 bool final_range_; 114 bool final_range_;
113 bool sparse_entry_; 115 bool sparse_entry_;
116 bool truncated_; // We have an incomplete 200 stored.
114 117
115 DISALLOW_COPY_AND_ASSIGN(PartialData); 118 DISALLOW_COPY_AND_ASSIGN(PartialData);
116 }; 119 };
117 120
118 } // namespace net 121 } // namespace net
119 122
120 #endif // NET_HTTP_PARTIAL_DATA_H_ 123 #endif // NET_HTTP_PARTIAL_DATA_H_
OLDNEW
« no previous file with comments | « net/http/http_cache_unittest.cc ('k') | net/http/partial_data.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698