OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_ELEMENT_H_ | 5 #ifndef NET_BASE_UPLOAD_ELEMENT_H_ |
6 #define NET_BASE_UPLOAD_ELEMENT_H_ | 6 #define NET_BASE_UPLOAD_ELEMENT_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 } | 52 } |
53 | 53 |
54 void SetToFilePath(const base::FilePath& path) { | 54 void SetToFilePath(const base::FilePath& path) { |
55 SetToFilePathRange(path, 0, kuint64max, base::Time()); | 55 SetToFilePathRange(path, 0, kuint64max, base::Time()); |
56 } | 56 } |
57 | 57 |
58 // If expected_modification_time is NULL, we do not check for the file | 58 // If expected_modification_time is NULL, we do not check for the file |
59 // change. Also note that the granularity for comparison is time_t, not | 59 // change. Also note that the granularity for comparison is time_t, not |
60 // the full precision. | 60 // the full precision. |
61 void SetToFilePathRange(const base::FilePath& path, | 61 void SetToFilePathRange(const base::FilePath& path, |
62 uint64 offset, uint64 length, | 62 uint64 offset, |
| 63 uint64 length, |
63 const base::Time& expected_modification_time) { | 64 const base::Time& expected_modification_time) { |
64 type_ = TYPE_FILE; | 65 type_ = TYPE_FILE; |
65 file_path_ = path; | 66 file_path_ = path; |
66 file_range_offset_ = offset; | 67 file_range_offset_ = offset; |
67 file_range_length_ = length; | 68 file_range_length_ = length; |
68 expected_file_modification_time_ = expected_modification_time; | 69 expected_file_modification_time_ = expected_modification_time; |
69 } | 70 } |
70 | 71 |
71 private: | 72 private: |
72 Type type_; | 73 Type type_; |
73 std::vector<char> buf_; | 74 std::vector<char> buf_; |
74 const char* bytes_start_; | 75 const char* bytes_start_; |
75 uint64 bytes_length_; | 76 uint64 bytes_length_; |
76 base::FilePath file_path_; | 77 base::FilePath file_path_; |
77 uint64 file_range_offset_; | 78 uint64 file_range_offset_; |
78 uint64 file_range_length_; | 79 uint64 file_range_length_; |
79 base::Time expected_file_modification_time_; | 80 base::Time expected_file_modification_time_; |
80 | 81 |
81 DISALLOW_COPY_AND_ASSIGN(UploadElement); | 82 DISALLOW_COPY_AND_ASSIGN(UploadElement); |
82 }; | 83 }; |
83 | 84 |
84 #if defined(UNIT_TEST) | 85 #if defined(UNIT_TEST) |
85 inline bool operator==(const UploadElement& a, | 86 inline bool operator==(const UploadElement& a, const UploadElement& b) { |
86 const UploadElement& b) { | |
87 if (a.type() != b.type()) | 87 if (a.type() != b.type()) |
88 return false; | 88 return false; |
89 if (a.type() == UploadElement::TYPE_BYTES) | 89 if (a.type() == UploadElement::TYPE_BYTES) |
90 return a.bytes_length() == b.bytes_length() && | 90 return a.bytes_length() == b.bytes_length() && |
91 memcmp(a.bytes(), b.bytes(), b.bytes_length()) == 0; | 91 memcmp(a.bytes(), b.bytes(), b.bytes_length()) == 0; |
92 if (a.type() == UploadElement::TYPE_FILE) { | 92 if (a.type() == UploadElement::TYPE_FILE) { |
93 return a.file_path() == b.file_path() && | 93 return a.file_path() == b.file_path() && |
94 a.file_range_offset() == b.file_range_offset() && | 94 a.file_range_offset() == b.file_range_offset() && |
95 a.file_range_length() == b.file_range_length() && | 95 a.file_range_length() == b.file_range_length() && |
96 a.expected_file_modification_time() == | 96 a.expected_file_modification_time() == |
97 b.expected_file_modification_time(); | 97 b.expected_file_modification_time(); |
98 } | 98 } |
99 return false; | 99 return false; |
100 } | 100 } |
101 | 101 |
102 inline bool operator!=(const UploadElement& a, | 102 inline bool operator!=(const UploadElement& a, const UploadElement& b) { |
103 const UploadElement& b) { | |
104 return !(a == b); | 103 return !(a == b); |
105 } | 104 } |
106 #endif // defined(UNIT_TEST) | 105 #endif // defined(UNIT_TEST) |
107 | 106 |
108 } // namespace net | 107 } // namespace net |
109 | 108 |
110 #endif // NET_BASE_UPLOAD_ELEMENT_H_ | 109 #endif // NET_BASE_UPLOAD_ELEMENT_H_ |
OLD | NEW |