Linux: Depend on liberation-fonts package for RPMs.
[chromium-blink-merge.git] / content / browser / devtools / devtools_io_context.h
blob7e43233464e94339f51913d2fcc3596b4aa7f48b
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.
5 #include <map>
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"
12 namespace content {
13 namespace devtools {
15 class DevToolsIOContext {
16 public:
17 class Stream : public base::RefCountedDeleteOnMessageLoop<Stream> {
18 public:
19 enum Status {
20 StatusSuccess,
21 StatusEOF,
22 StatusFailure
25 using ReadCallback = base::Callback<
26 void(const scoped_refptr<base::RefCountedString>& data, int status)>;
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& handle() const { return handle_; }
32 private:
33 Stream();
34 ~Stream();
35 friend class DevToolsIOContext;
36 friend class base::RefCountedDeleteOnMessageLoop<Stream>;
37 friend class base::DeleteHelper<Stream>;
39 void ReadOnFileThread(off_t pos, size_t max_size, ReadCallback callback);
40 void AppendOnFileThread(const scoped_refptr<base::RefCountedString>& data);
41 bool InitOnFileThreadIfNeeded();
43 const std::string handle_;
44 base::File file_;
45 bool had_errors_;
46 off_t last_read_pos_;
49 DevToolsIOContext();
50 ~DevToolsIOContext();
52 scoped_refptr<Stream> CreateTempFileBackedStream();
53 scoped_refptr<Stream> GetByHandle(const std::string& handle);
54 bool Close(const std::string& handle);
55 void DiscardAllStreams();
57 private:
58 using StreamsMap = std::map<std::string, scoped_refptr<Stream>>;
59 StreamsMap streams_;
62 } // namespace devtools
63 } // namespace content