| 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" |
| 11 #include "base/memory/ref_counted_delete_on_message_loop.h" | 11 #include "base/memory/ref_counted_delete_on_sequence.h" |
| 12 #include "base/memory/ref_counted_memory.h" | 12 #include "base/memory/ref_counted_memory.h" |
| 13 | 13 |
| 14 namespace content { | 14 namespace content { |
| 15 | 15 |
| 16 class DevToolsIOContext { | 16 class DevToolsIOContext { |
| 17 public: | 17 public: |
| 18 class Stream : public base::RefCountedDeleteOnMessageLoop<Stream> { | 18 class Stream : public base::RefCountedDeleteOnSequence<Stream> { |
| 19 public: | 19 public: |
| 20 enum Status { | 20 enum Status { |
| 21 StatusSuccess, | 21 StatusSuccess, |
| 22 StatusEOF, | 22 StatusEOF, |
| 23 StatusFailure | 23 StatusFailure |
| 24 }; | 24 }; |
| 25 | 25 |
| 26 using ReadCallback = base::Callback< | 26 using ReadCallback = base::Callback< |
| 27 void(const scoped_refptr<base::RefCountedString>& data, int status)>; | 27 void(const scoped_refptr<base::RefCountedString>& data, int status)>; |
| 28 | 28 |
| 29 void Read(off_t position, size_t max_size, ReadCallback callback); | 29 void Read(off_t position, size_t max_size, ReadCallback callback); |
| 30 void Append(std::unique_ptr<std::string> data); | 30 void Append(std::unique_ptr<std::string> data); |
| 31 const std::string& handle() const { return handle_; } | 31 const std::string& handle() const { return handle_; } |
| 32 | 32 |
| 33 private: | 33 private: |
| 34 Stream(); | 34 Stream(); |
| 35 ~Stream(); | 35 ~Stream(); |
| 36 friend class DevToolsIOContext; | 36 friend class DevToolsIOContext; |
| 37 friend class base::RefCountedDeleteOnMessageLoop<Stream>; | 37 friend class base::RefCountedDeleteOnSequence<Stream>; |
| 38 friend class base::DeleteHelper<Stream>; | 38 friend class base::DeleteHelper<Stream>; |
| 39 | 39 |
| 40 void ReadOnFileThread(off_t pos, size_t max_size, ReadCallback callback); | 40 void ReadOnFileThread(off_t pos, size_t max_size, ReadCallback callback); |
| 41 void AppendOnFileThread(std::unique_ptr<std::string> data); | 41 void AppendOnFileThread(std::unique_ptr<std::string> data); |
| 42 bool InitOnFileThreadIfNeeded(); | 42 bool InitOnFileThreadIfNeeded(); |
| 43 | 43 |
| 44 const std::string handle_; | 44 const std::string handle_; |
| 45 base::File file_; | 45 base::File file_; |
| 46 bool had_errors_; | 46 bool had_errors_; |
| 47 off_t last_read_pos_; | 47 off_t last_read_pos_; |
| 48 }; | 48 }; |
| 49 | 49 |
| 50 DevToolsIOContext(); | 50 DevToolsIOContext(); |
| 51 ~DevToolsIOContext(); | 51 ~DevToolsIOContext(); |
| 52 | 52 |
| 53 scoped_refptr<Stream> CreateTempFileBackedStream(); | 53 scoped_refptr<Stream> CreateTempFileBackedStream(); |
| 54 scoped_refptr<Stream> GetByHandle(const std::string& handle); | 54 scoped_refptr<Stream> GetByHandle(const std::string& handle); |
| 55 bool Close(const std::string& handle); | 55 bool Close(const std::string& handle); |
| 56 void DiscardAllStreams(); | 56 void DiscardAllStreams(); |
| 57 | 57 |
| 58 private: | 58 private: |
| 59 using StreamsMap = std::map<std::string, scoped_refptr<Stream>>; | 59 using StreamsMap = std::map<std::string, scoped_refptr<Stream>>; |
| 60 StreamsMap streams_; | 60 StreamsMap streams_; |
| 61 }; | 61 }; |
| 62 | 62 |
| 63 } // namespace content | 63 } // namespace content |
| OLD | NEW |