| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/files/file.h" | 10 #include "base/files/file.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 enum Status { | 21 enum Status { |
| 22 StatusSuccess, | 22 StatusSuccess, |
| 23 StatusEOF, | 23 StatusEOF, |
| 24 StatusFailure | 24 StatusFailure |
| 25 }; | 25 }; |
| 26 | 26 |
| 27 using ReadCallback = base::Callback< | 27 using ReadCallback = base::Callback< |
| 28 void(const scoped_refptr<base::RefCountedString>& data, int status)>; | 28 void(const scoped_refptr<base::RefCountedString>& data, int status)>; |
| 29 | 29 |
| 30 void Read(off_t position, size_t max_size, ReadCallback callback); | 30 void Read(off_t position, size_t max_size, ReadCallback callback); |
| 31 void Append(const scoped_refptr<base::RefCountedString>& data); | 31 void Append(std::unique_ptr<std::string> data); |
| 32 const std::string& handle() const { return handle_; } | 32 const std::string& handle() const { return handle_; } |
| 33 | 33 |
| 34 private: | 34 private: |
| 35 Stream(); | 35 Stream(); |
| 36 ~Stream(); | 36 ~Stream(); |
| 37 friend class DevToolsIOContext; | 37 friend class DevToolsIOContext; |
| 38 friend class base::RefCountedDeleteOnMessageLoop<Stream>; | 38 friend class base::RefCountedDeleteOnMessageLoop<Stream>; |
| 39 friend class base::DeleteHelper<Stream>; | 39 friend class base::DeleteHelper<Stream>; |
| 40 | 40 |
| 41 void ReadOnFileThread(off_t pos, size_t max_size, ReadCallback callback); | 41 void ReadOnFileThread(off_t pos, size_t max_size, ReadCallback callback); |
| 42 void AppendOnFileThread(const scoped_refptr<base::RefCountedString>& data); | 42 void AppendOnFileThread(std::unique_ptr<std::string> data); |
| 43 bool InitOnFileThreadIfNeeded(); | 43 bool InitOnFileThreadIfNeeded(); |
| 44 | 44 |
| 45 const std::string handle_; | 45 const std::string handle_; |
| 46 base::File file_; | 46 base::File file_; |
| 47 bool had_errors_; | 47 bool had_errors_; |
| 48 off_t last_read_pos_; | 48 off_t last_read_pos_; |
| 49 }; | 49 }; |
| 50 | 50 |
| 51 DevToolsIOContext(); | 51 DevToolsIOContext(); |
| 52 ~DevToolsIOContext(); | 52 ~DevToolsIOContext(); |
| 53 | 53 |
| 54 scoped_refptr<Stream> CreateTempFileBackedStream(); | 54 scoped_refptr<Stream> CreateTempFileBackedStream(); |
| 55 scoped_refptr<Stream> GetByHandle(const std::string& handle); | 55 scoped_refptr<Stream> GetByHandle(const std::string& handle); |
| 56 bool Close(const std::string& handle); | 56 bool Close(const std::string& handle); |
| 57 void DiscardAllStreams(); | 57 void DiscardAllStreams(); |
| 58 | 58 |
| 59 private: | 59 private: |
| 60 using StreamsMap = std::map<std::string, scoped_refptr<Stream>>; | 60 using StreamsMap = std::map<std::string, scoped_refptr<Stream>>; |
| 61 StreamsMap streams_; | 61 StreamsMap streams_; |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 } // namespace devtools | 64 } // namespace devtools |
| 65 } // namespace content | 65 } // namespace content |
| OLD | NEW |