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 #ifndef CONTENT_CHILD_SHARED_MEMORY_DATA_CONSUMER_HANDLE_H_
6 #define CONTENT_CHILD_SHARED_MEMORY_DATA_CONSUMER_HANDLE_H_
8 #include "base/callback.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "content/common/content_export.h"
12 #include "content/public/child/request_peer.h"
13 #include "third_party/WebKit/public/platform/WebDataConsumerHandle.h"
17 // This class is a WebDataConsumerHandle that accepts RequestPeer::ReceivedData.
18 class CONTENT_EXPORT SharedMemoryDataConsumerHandle final
19 : public NON_EXPORTED_BASE(blink::WebDataConsumerHandle
) {
24 enum BackpressureMode
{
26 kDoNotApplyBackpressure
,
29 class CONTENT_EXPORT Writer final
{
31 Writer(const scoped_refptr
<Context
>& context
, BackpressureMode mode
);
33 // Note: Writer assumes |AddData| is not called in a client's didGetReadable
34 // callback. There isn't such assumption for |Close| and |Fail|.
35 void AddData(scoped_ptr
<RequestPeer::ReceivedData
> data
);
37 // TODO(yhirano): Consider providing error code.
41 scoped_refptr
<Context
> context_
;
42 BackpressureMode mode_
;
44 DISALLOW_COPY_AND_ASSIGN(Writer
);
47 class ReaderImpl final
: public Reader
{
49 ReaderImpl(scoped_refptr
<Context
> context
, Client
* client
);
50 virtual ~ReaderImpl();
51 virtual Result
read(void* data
, size_t size
, Flags flags
, size_t* readSize
);
52 virtual Result
beginRead(const void** buffer
,
55 virtual Result
endRead(size_t readSize
);
58 scoped_refptr
<Context
> context_
;
60 DISALLOW_COPY_AND_ASSIGN(ReaderImpl
);
63 // Creates a handle and a writer associated with the handle. The created
64 // writer should be used on the calling thread.
65 SharedMemoryDataConsumerHandle(BackpressureMode mode
,
66 scoped_ptr
<Writer
>* writer
);
67 // |on_reader_detached| will be called aynchronously on the calling thread
68 // when the reader (including the handle) is detached (i.e. both the handle
69 // and the reader are destructed). The callback will be reset in the internal
70 // context when the writer is detached, i.e. |Close| or |Fail| is called,
71 // and the callback will never be called.
72 SharedMemoryDataConsumerHandle(BackpressureMode mode
,
73 const base::Closure
& on_reader_detached
,
74 scoped_ptr
<Writer
>* writer
);
75 virtual ~SharedMemoryDataConsumerHandle();
77 scoped_ptr
<Reader
> ObtainReader(Client
* client
);
80 virtual ReaderImpl
* obtainReaderInternal(Client
* client
);
81 const char* debugName() const override
;
83 scoped_refptr
<Context
> context_
;
85 DISALLOW_COPY_AND_ASSIGN(SharedMemoryDataConsumerHandle
);
88 } // namespace content
90 #endif // CONTENT_CHILD_SHARED_MEMORY_DATA_CONSUMER_HANDLE_H_