| OLD | NEW |
| 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 <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/file_path.h" |
| 11 #include "base/ref_counted.h" | 12 #include "base/ref_counted.h" |
| 12 | 13 |
| 13 namespace net { | 14 namespace net { |
| 14 | 15 |
| 15 class UploadData : public base::RefCounted<UploadData> { | 16 class UploadData : public base::RefCounted<UploadData> { |
| 16 public: | 17 public: |
| 17 UploadData() : identifier_(0) {} | 18 UploadData() : identifier_(0) {} |
| 18 | 19 |
| 19 enum Type { | 20 enum Type { |
| 20 TYPE_BYTES, | 21 TYPE_BYTES, |
| 21 TYPE_FILE | 22 TYPE_FILE |
| 22 }; | 23 }; |
| 23 | 24 |
| 24 class Element { | 25 class Element { |
| 25 public: | 26 public: |
| 26 Element() : type_(TYPE_BYTES), file_range_offset_(0), | 27 Element() : type_(TYPE_BYTES), file_range_offset_(0), |
| 27 file_range_length_(kuint64max) { | 28 file_range_length_(kuint64max) { |
| 28 } | 29 } |
| 29 | 30 |
| 30 Type type() const { return type_; } | 31 Type type() const { return type_; } |
| 31 const std::vector<char>& bytes() const { return bytes_; } | 32 const std::vector<char>& bytes() const { return bytes_; } |
| 32 const std::wstring& file_path() const { return file_path_; } | 33 const FilePath& file_path() const { return file_path_; } |
| 33 uint64 file_range_offset() const { return file_range_offset_; } | 34 uint64 file_range_offset() const { return file_range_offset_; } |
| 34 uint64 file_range_length() const { return file_range_length_; } | 35 uint64 file_range_length() const { return file_range_length_; } |
| 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 std::wstring& 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 std::wstring& 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 std::wstring 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_; |
| 63 }; | 64 }; |
| 64 | 65 |
| 65 void AppendBytes(const char* bytes, int bytes_len) { | 66 void AppendBytes(const char* bytes, int bytes_len) { |
| 66 if (bytes_len > 0) { | 67 if (bytes_len > 0) { |
| 67 elements_.push_back(Element()); | 68 elements_.push_back(Element()); |
| 68 elements_.back().SetToBytes(bytes, bytes_len); | 69 elements_.back().SetToBytes(bytes, bytes_len); |
| 69 } | 70 } |
| 70 } | 71 } |
| 71 | 72 |
| 72 void AppendFile(const std::wstring& file_path) { | 73 void AppendFile(const FilePath& file_path) { |
| 73 elements_.push_back(Element()); | 74 elements_.push_back(Element()); |
| 74 elements_.back().SetToFilePath(file_path); | 75 elements_.back().SetToFilePath(file_path); |
| 75 } | 76 } |
| 76 | 77 |
| 77 void AppendFileRange(const std::wstring& file_path, | 78 void AppendFileRange(const FilePath& file_path, |
| 78 uint64 offset, uint64 length) { | 79 uint64 offset, uint64 length) { |
| 79 elements_.push_back(Element()); | 80 elements_.push_back(Element()); |
| 80 elements_.back().SetToFilePathRange(file_path, offset, length); | 81 elements_.back().SetToFilePathRange(file_path, offset, length); |
| 81 } | 82 } |
| 82 | 83 |
| 83 // Returns the total size in bytes of the data to upload. | 84 // Returns the total size in bytes of the data to upload. |
| 84 uint64 GetContentLength() const; | 85 uint64 GetContentLength() const; |
| 85 | 86 |
| 86 const std::vector<Element>& elements() const { | 87 const std::vector<Element>& elements() const { |
| 87 return elements_; | 88 return elements_; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 102 int64 identifier() const { return identifier_; } | 103 int64 identifier() const { return identifier_; } |
| 103 | 104 |
| 104 private: | 105 private: |
| 105 std::vector<Element> elements_; | 106 std::vector<Element> elements_; |
| 106 int64 identifier_; | 107 int64 identifier_; |
| 107 }; | 108 }; |
| 108 | 109 |
| 109 } // namespace net | 110 } // namespace net |
| 110 | 111 |
| 111 #endif // NET_BASE_UPLOAD_DATA_H_ | 112 #endif // NET_BASE_UPLOAD_DATA_H_ |
| OLD | NEW |