OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include <map> | |
6 | |
7 #include "base/callback.h" | |
8 #include "base/files/file.h" | |
9 #include "base/memory/ref_counted_delete_on_message_loop.h" | |
10 #include "base/memory/ref_counted_memory.h" | |
11 | |
12 namespace content { | |
13 namespace devtools { | |
14 | |
15 class DevToolsIOContext { | |
16 public: | |
17 class Stream : public base::RefCountedDeleteOnMessageLoop<Stream> { | |
18 public: | |
19 enum Status { | |
20 StatusSuccess, | |
21 StatusEOF, | |
22 StatusFailure | |
23 }; | |
24 | |
25 using ReadCallback = base::Callback< | |
26 void(const scoped_refptr<base::RefCountedString>& data, int status)>; | |
27 | |
28 void Read(off_t position, size_t max_size, ReadCallback callback); | |
29 void Append(const scoped_refptr<base::RefCountedString>& data); | |
30 const std::string& id() const { return id_; } | |
31 | |
32 private: | |
33 Stream(); | |
34 ~Stream(); | |
35 friend class DevToolsIOContext; | |
36 friend class base::RefCountedDeleteOnMessageLoop<Stream>; | |
37 friend class base::DeleteHelper<Stream>; | |
38 | |
39 bool InitOnFileThreadIdNeeded(); | |
dgozman
2015/08/24 20:45:44
typo: Id instead of If
| |
40 | |
41 const std::string id_; | |
42 base::File file_; | |
43 bool had_errors_; | |
44 off_t last_read_pos_; | |
45 }; | |
46 | |
47 DevToolsIOContext(); | |
48 ~DevToolsIOContext(); | |
49 | |
50 scoped_refptr<Stream> CreateTempFileBackedStream(); | |
51 scoped_refptr<Stream> GetById(const std::string& id); | |
52 bool Close(const std::string& id); | |
53 void DiscardAllStreams(); | |
54 | |
55 private: | |
56 using StreamsMap = std::map<std::string, scoped_refptr<Stream>>; | |
57 StreamsMap streams_; | |
58 }; | |
59 | |
60 } // namespace devtools | |
61 } // namespace content | |
OLD | NEW |