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

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

Issue 594036: Support sending a sliced file in chromium.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 9 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/base/net_error_list.h ('k') | net/base/upload_data_stream.h » ('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) 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_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/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/file_path.h" 11 #include "base/file_path.h"
12 #include "base/ref_counted.h" 12 #include "base/ref_counted.h"
13 #include "base/time.h"
13 #include "testing/gtest/include/gtest/gtest_prod.h" 14 #include "testing/gtest/include/gtest/gtest_prod.h"
14 15
15 namespace net { 16 namespace net {
16 17
17 class UploadData : public base::RefCounted<UploadData> { 18 class UploadData : public base::RefCounted<UploadData> {
18 public: 19 public:
19 UploadData() : identifier_(0) {} 20 UploadData() : identifier_(0) {}
20 21
21 enum Type { 22 enum Type {
22 TYPE_BYTES, 23 TYPE_BYTES,
23 TYPE_FILE 24 TYPE_FILE
24 }; 25 };
25 26
26 class Element { 27 class Element {
27 public: 28 public:
28 Element() : type_(TYPE_BYTES), file_range_offset_(0), 29 Element() : type_(TYPE_BYTES), file_range_offset_(0),
29 file_range_length_(kuint64max), 30 file_range_length_(kuint64max),
30 override_content_length_(false) { 31 override_content_length_(false) {
31 } 32 }
32 33
33 Type type() const { return type_; } 34 Type type() const { return type_; }
34 const std::vector<char>& bytes() const { return bytes_; } 35 const std::vector<char>& bytes() const { return bytes_; }
35 const FilePath& file_path() const { return file_path_; } 36 const FilePath& file_path() const { return file_path_; }
36 uint64 file_range_offset() const { return file_range_offset_; } 37 uint64 file_range_offset() const { return file_range_offset_; }
37 uint64 file_range_length() const { return file_range_length_; } 38 uint64 file_range_length() const { return file_range_length_; }
39 // If NULL time is returned, we do not do the check.
40 const base::Time& expected_file_modification_time() const {
41 return expected_file_modification_time_;
42 }
38 43
39 void SetToBytes(const char* bytes, int bytes_len) { 44 void SetToBytes(const char* bytes, int bytes_len) {
40 type_ = TYPE_BYTES; 45 type_ = TYPE_BYTES;
41 bytes_.assign(bytes, bytes + bytes_len); 46 bytes_.assign(bytes, bytes + bytes_len);
42 } 47 }
43 48
44 void SetToFilePath(const FilePath& path) { 49 void SetToFilePath(const FilePath& path) {
45 SetToFilePathRange(path, 0, kuint64max); 50 SetToFilePathRange(path, 0, kuint64max, base::Time());
46 } 51 }
47 52
53 // If expected_modification_time is NULL, we do not check for the file
54 // change. Also note that the granularity for comparison is time_t, not
55 // the full precision.
48 void SetToFilePathRange(const FilePath& path, 56 void SetToFilePathRange(const FilePath& path,
49 uint64 offset, uint64 length) { 57 uint64 offset, uint64 length,
58 const base::Time& expected_modification_time) {
50 type_ = TYPE_FILE; 59 type_ = TYPE_FILE;
51 file_path_ = path; 60 file_path_ = path;
52 file_range_offset_ = offset; 61 file_range_offset_ = offset;
53 file_range_length_ = length; 62 file_range_length_ = length;
63 expected_file_modification_time_ = expected_modification_time;
54 } 64 }
55 65
56 // Returns the byte-length of the element. For files that do not exist, 0 66 // Returns the byte-length of the element. For files that do not exist, 0
57 // is returned. This is done for consistency with Mozilla. 67 // is returned. This is done for consistency with Mozilla.
58 uint64 GetContentLength() const; 68 uint64 GetContentLength() const;
59 69
60 private: 70 private:
61 // Allows tests to override the result of GetContentLength. 71 // Allows tests to override the result of GetContentLength.
62 void SetContentLength(uint64 content_length) { 72 void SetContentLength(uint64 content_length) {
63 override_content_length_ = true; 73 override_content_length_ = true;
64 content_length_ = content_length; 74 content_length_ = content_length;
65 } 75 }
66 76
67 Type type_; 77 Type type_;
68 std::vector<char> bytes_; 78 std::vector<char> bytes_;
69 FilePath file_path_; 79 FilePath file_path_;
70 uint64 file_range_offset_; 80 uint64 file_range_offset_;
71 uint64 file_range_length_; 81 uint64 file_range_length_;
82 base::Time expected_file_modification_time_;
72 bool override_content_length_; 83 bool override_content_length_;
73 uint64 content_length_; 84 uint64 content_length_;
74 85
75 FRIEND_TEST(UploadDataStreamTest, FileSmallerThanLength); 86 FRIEND_TEST(UploadDataStreamTest, FileSmallerThanLength);
76 FRIEND_TEST(HttpNetworkTransactionTest, UploadFileSmallerThanLength); 87 FRIEND_TEST(HttpNetworkTransactionTest, UploadFileSmallerThanLength);
77 }; 88 };
78 89
79 void AppendBytes(const char* bytes, int bytes_len) { 90 void AppendBytes(const char* bytes, int bytes_len) {
80 if (bytes_len > 0) { 91 if (bytes_len > 0) {
81 elements_.push_back(Element()); 92 elements_.push_back(Element());
82 elements_.back().SetToBytes(bytes, bytes_len); 93 elements_.back().SetToBytes(bytes, bytes_len);
83 } 94 }
84 } 95 }
85 96
86 void AppendFile(const FilePath& file_path) { 97 void AppendFile(const FilePath& file_path) {
87 elements_.push_back(Element()); 98 elements_.push_back(Element());
88 elements_.back().SetToFilePath(file_path); 99 elements_.back().SetToFilePath(file_path);
89 } 100 }
90 101
91 void AppendFileRange(const FilePath& file_path, 102 void AppendFileRange(const FilePath& file_path,
92 uint64 offset, uint64 length) { 103 uint64 offset, uint64 length,
104 const base::Time& expected_modification_time) {
93 elements_.push_back(Element()); 105 elements_.push_back(Element());
94 elements_.back().SetToFilePathRange(file_path, offset, length); 106 elements_.back().SetToFilePathRange(file_path, offset, length,
107 expected_modification_time);
95 } 108 }
96 109
97 // Returns the total size in bytes of the data to upload. 110 // Returns the total size in bytes of the data to upload.
98 uint64 GetContentLength() const; 111 uint64 GetContentLength() const;
99 112
100 const std::vector<Element>& elements() const { 113 const std::vector<Element>& elements() const {
101 return elements_; 114 return elements_;
102 } 115 }
103 116
104 void set_elements(const std::vector<Element>& elements) { 117 void set_elements(const std::vector<Element>& elements) {
(...skipping 15 matching lines...) Expand all
120 133
121 ~UploadData() {} 134 ~UploadData() {}
122 135
123 std::vector<Element> elements_; 136 std::vector<Element> elements_;
124 int64 identifier_; 137 int64 identifier_;
125 }; 138 };
126 139
127 } // namespace net 140 } // namespace net
128 141
129 #endif // NET_BASE_UPLOAD_DATA_H_ 142 #endif // NET_BASE_UPLOAD_DATA_H_
OLDNEW
« no previous file with comments | « net/base/net_error_list.h ('k') | net/base/upload_data_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698