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

Side by Side Diff: net/base/upload_data.h

Issue 541022: Fix the case where the browser livelocks if we cannot open a file. (Closed)
Patch Set: Created 10 years, 11 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
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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_BASE_UPLOAD_DATA_H_ 5 #ifndef NET_BASE_UPLOAD_DATA_H_
6 #define NET_BASE_UPLOAD_DATA_H_ 6 #define NET_BASE_UPLOAD_DATA_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/file_path.h" 10 #include "base/file_path.h"
11 #include "base/ref_counted.h" 11 #include "base/ref_counted.h"
12 12
13 namespace net { 13 namespace net {
14 14
15 class UploadData : public base::RefCounted<UploadData> { 15 class UploadData : public base::RefCounted<UploadData> {
16 public: 16 public:
17 UploadData() : identifier_(0) {} 17 UploadData() : identifier_(0) {}
18 18
19 enum Type { 19 enum Type {
20 TYPE_BYTES, 20 TYPE_BYTES,
21 TYPE_FILE 21 TYPE_FILE
22 }; 22 };
23 23
24 class Element { 24 class Element {
25 public: 25 public:
26 Element() : type_(TYPE_BYTES), file_range_offset_(0), 26 Element() : type_(TYPE_BYTES), file_range_offset_(0),
27 file_range_length_(kuint64max) { 27 file_range_length_(kuint64max), expected_file_length_(-1) {
28 } 28 }
29 29
30 Type type() const { return type_; } 30 Type type() const { return type_; }
31 const std::vector<char>& bytes() const { return bytes_; } 31 const std::vector<char>& bytes() const { return bytes_; }
32 const FilePath& file_path() const { return file_path_; } 32 const FilePath& file_path() const { return file_path_; }
33 uint64 file_range_offset() const { return file_range_offset_; } 33 uint64 file_range_offset() const { return file_range_offset_; }
34 uint64 file_range_length() const { return file_range_length_; } 34 uint64 file_range_length() const { return file_range_length_; }
35 int64 expected_length() const { return expected_file_length_; }
wtc 2010/01/12 19:51:02 Nit: rename this method expected_file_size and the
agl 2010/01/25 14:14:09 Done.
35 36
36 void SetToBytes(const char* bytes, int bytes_len) { 37 void SetToBytes(const char* bytes, int bytes_len) {
37 type_ = TYPE_BYTES; 38 type_ = TYPE_BYTES;
38 bytes_.assign(bytes, bytes + bytes_len); 39 bytes_.assign(bytes, bytes + bytes_len);
39 } 40 }
40 41
41 void SetToFilePath(const FilePath& path) { 42 void SetToFilePath(const FilePath& path) {
42 SetToFilePathRange(path, 0, kuint64max); 43 SetToFilePathRange(path, 0, kuint64max);
43 } 44 }
44 45
45 void SetToFilePathRange(const FilePath& path, 46 void SetToFilePathRange(const FilePath& path,
46 uint64 offset, uint64 length) { 47 uint64 offset, uint64 length) {
47 type_ = TYPE_FILE; 48 type_ = TYPE_FILE;
48 file_path_ = path; 49 file_path_ = path;
49 file_range_offset_ = offset; 50 file_range_offset_ = offset;
50 file_range_length_ = length; 51 file_range_length_ = length;
51 } 52 }
52 53
53 // Returns the byte-length of the element. For files that do not exist, 0 54 // Returns the byte-length of the element. For files that do not exist, 0
54 // is returned. This is done for consistency with Mozilla. 55 // is returned. This is done for consistency with Mozilla.
55 uint64 GetContentLength() const; 56 uint64 GetContentLength() const;
56 57
57 private: 58 private:
58 Type type_; 59 Type type_;
59 std::vector<char> bytes_; 60 std::vector<char> bytes_;
60 FilePath file_path_; 61 FilePath file_path_;
61 uint64 file_range_offset_; 62 uint64 file_range_offset_;
62 uint64 file_range_length_; 63 uint64 file_range_length_;
64
65 // If this Element is a file, then this is the length that we expect it to
66 // have. This allows us to detect when a file has been truncated from under
67 // us. This is only valid after calling GetContentLength().
68 mutable int64 expected_file_length_;
wtc 2010/01/12 19:51:02 Does this member need to be mutable?
agl 2010/01/25 14:14:09 It's changed inside of GetContextLength, which is
63 }; 69 };
64 70
65 void AppendBytes(const char* bytes, int bytes_len) { 71 void AppendBytes(const char* bytes, int bytes_len) {
66 if (bytes_len > 0) { 72 if (bytes_len > 0) {
67 elements_.push_back(Element()); 73 elements_.push_back(Element());
68 elements_.back().SetToBytes(bytes, bytes_len); 74 elements_.back().SetToBytes(bytes, bytes_len);
69 } 75 }
70 } 76 }
71 77
72 void AppendFile(const FilePath& file_path) { 78 void AppendFile(const FilePath& file_path) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 112
107 ~UploadData() {} 113 ~UploadData() {}
108 114
109 std::vector<Element> elements_; 115 std::vector<Element> elements_;
110 int64 identifier_; 116 int64 identifier_;
111 }; 117 };
112 118
113 } // namespace net 119 } // namespace net
114 120
115 #endif // NET_BASE_UPLOAD_DATA_H_ 121 #endif // NET_BASE_UPLOAD_DATA_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698