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.
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"
15 class DevToolsIOContext
{
17 class Stream
: public base::RefCountedDeleteOnMessageLoop
<Stream
> {
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_
; }
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_
;
52 scoped_refptr
<Stream
> CreateTempFileBackedStream();
53 scoped_refptr
<Stream
> GetByHandle(const std::string
& handle
);
54 bool Close(const std::string
& handle
);
55 void DiscardAllStreams();
58 using StreamsMap
= std::map
<std::string
, scoped_refptr
<Stream
>>;
62 } // namespace devtools
63 } // namespace content