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

Side by Side Diff: util/net/http_body.h

Issue 1416493006: Change file op |ssize_t|s to FileOperationResult (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: fixes Created 5 years, 1 month 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
« no previous file with comments | « util/file/string_file_test.cc ('k') | util/net/http_body.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 2014 The Crashpad Authors. All rights reserved. 1 // Copyright 2014 The Crashpad Authors. All rights reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
(...skipping 24 matching lines...) Expand all
35 //! \brief Copies up to \a max_len bytes into the user-supplied buffer. 35 //! \brief Copies up to \a max_len bytes into the user-supplied buffer.
36 //! 36 //!
37 //! \param[out] buffer A user-supplied buffer into which this method will copy 37 //! \param[out] buffer A user-supplied buffer into which this method will copy
38 //! bytes from the stream. 38 //! bytes from the stream.
39 //! \param[in] max_len The length (or size) of \a buffer. At most this many 39 //! \param[in] max_len The length (or size) of \a buffer. At most this many
40 //! bytes will be copied. 40 //! bytes will be copied.
41 //! 41 //!
42 //! \return On success, a positive number indicating the number of bytes 42 //! \return On success, a positive number indicating the number of bytes
43 //! actually copied to \a buffer. On failure, a negative number. When 43 //! actually copied to \a buffer. On failure, a negative number. When
44 //! the stream has no more data, returns `0`. 44 //! the stream has no more data, returns `0`.
45 virtual ssize_t GetBytesBuffer(uint8_t* buffer, size_t max_len) = 0; 45 virtual FileOperationResult GetBytesBuffer(uint8_t* buffer,
46 size_t max_len) = 0;
46 47
47 protected: 48 protected:
48 HTTPBodyStream() {} 49 HTTPBodyStream() {}
49 }; 50 };
50 51
51 //! \brief An implementation of HTTPBodyStream that turns a fixed string into 52 //! \brief An implementation of HTTPBodyStream that turns a fixed string into
52 //! a stream. 53 //! a stream.
53 class StringHTTPBodyStream : public HTTPBodyStream { 54 class StringHTTPBodyStream : public HTTPBodyStream {
54 public: 55 public:
55 //! \brief Creates a stream with the specified string. 56 //! \brief Creates a stream with the specified string.
56 //! 57 //!
57 //! \param[in] string The string to turn into a stream. 58 //! \param[in] string The string to turn into a stream.
58 explicit StringHTTPBodyStream(const std::string& string); 59 explicit StringHTTPBodyStream(const std::string& string);
59 60
60 ~StringHTTPBodyStream() override; 61 ~StringHTTPBodyStream() override;
61 62
62 // HTTPBodyStream: 63 // HTTPBodyStream:
63 ssize_t GetBytesBuffer(uint8_t* buffer, size_t max_len) override; 64 FileOperationResult GetBytesBuffer(uint8_t* buffer, size_t max_len) override;
64 65
65 private: 66 private:
66 std::string string_; 67 std::string string_;
67 size_t bytes_read_; 68 size_t bytes_read_;
68 69
69 DISALLOW_COPY_AND_ASSIGN(StringHTTPBodyStream); 70 DISALLOW_COPY_AND_ASSIGN(StringHTTPBodyStream);
70 }; 71 };
71 72
72 //! \brief An implementation of HTTPBodyStream that reads from the specified 73 //! \brief An implementation of HTTPBodyStream that reads from the specified
73 //! file and provides its contents for an HTTP body. 74 //! file and provides its contents for an HTTP body.
74 class FileHTTPBodyStream : public HTTPBodyStream { 75 class FileHTTPBodyStream : public HTTPBodyStream {
75 public: 76 public:
76 //! \brief Creates a stream for reading the file at the specified \a path. 77 //! \brief Creates a stream for reading the file at the specified \a path.
77 //! 78 //!
78 //! \param[in] path The file from which this HTTPBodyStream will read. 79 //! \param[in] path The file from which this HTTPBodyStream will read.
79 explicit FileHTTPBodyStream(const base::FilePath& path); 80 explicit FileHTTPBodyStream(const base::FilePath& path);
80 81
81 ~FileHTTPBodyStream() override; 82 ~FileHTTPBodyStream() override;
82 83
83 // HTTPBodyStream: 84 // HTTPBodyStream:
84 ssize_t GetBytesBuffer(uint8_t* buffer, size_t max_len) override; 85 FileOperationResult GetBytesBuffer(uint8_t* buffer, size_t max_len) override;
85 86
86 private: 87 private:
87 enum FileState { 88 enum FileState {
88 kUnopenedFile, 89 kUnopenedFile,
89 kFileOpenError, 90 kFileOpenError,
90 kClosedAtEOF, 91 kClosedAtEOF,
91 kReading, 92 kReading,
92 }; 93 };
93 94
94 base::FilePath path_; 95 base::FilePath path_;
(...skipping 13 matching lines...) Expand all
108 //! 109 //!
109 //! \param[in] parts A vector of HTTPBodyStream objects, of which this object 110 //! \param[in] parts A vector of HTTPBodyStream objects, of which this object
110 //! takes ownership, that will be represented as a single unified stream. 111 //! takes ownership, that will be represented as a single unified stream.
111 //! Callers should not mutate the stream objects after passing them to 112 //! Callers should not mutate the stream objects after passing them to
112 //! an instance of this class. 113 //! an instance of this class.
113 explicit CompositeHTTPBodyStream(const PartsList& parts); 114 explicit CompositeHTTPBodyStream(const PartsList& parts);
114 115
115 ~CompositeHTTPBodyStream() override; 116 ~CompositeHTTPBodyStream() override;
116 117
117 // HTTPBodyStream: 118 // HTTPBodyStream:
118 ssize_t GetBytesBuffer(uint8_t* buffer, size_t max_len) override; 119 FileOperationResult GetBytesBuffer(uint8_t* buffer, size_t max_len) override;
119 120
120 private: 121 private:
121 PartsList parts_; 122 PartsList parts_;
122 PartsList::iterator current_part_; 123 PartsList::iterator current_part_;
123 124
124 DISALLOW_COPY_AND_ASSIGN(CompositeHTTPBodyStream); 125 DISALLOW_COPY_AND_ASSIGN(CompositeHTTPBodyStream);
125 }; 126 };
126 127
127 } // namespace crashpad 128 } // namespace crashpad
128 129
129 #endif // CRASHPAD_UTIL_NET_HTTP_BODY_H_ 130 #endif // CRASHPAD_UTIL_NET_HTTP_BODY_H_
OLDNEW
« no previous file with comments | « util/file/string_file_test.cc ('k') | util/net/http_body.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698