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/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "content/common/content_export.h"
11 #include "content/public/child/request_peer.h"
12 #include "third_party/WebKit/public/platform/WebDataConsumerHandle.h"
16 // This class is a WebDataConsumerHandle that accepts RequestPeer::ReceivedData.
17 class CONTENT_EXPORT SharedMemoryDataConsumerHandle final
18 : public NON_EXPORTED_BASE(blink::WebDataConsumerHandle
) {
23 enum BackpressureMode
{
25 kDoNotApplyBackpressure
,
28 class CONTENT_EXPORT Writer final
{
30 Writer(const scoped_refptr
<Context
>& context
, BackpressureMode mode
);
32 void AddData(scoped_ptr
<RequestPeer::ReceivedData
> data
);
36 scoped_refptr
<Context
> context_
;
37 BackpressureMode mode_
;
39 DISALLOW_COPY_AND_ASSIGN(Writer
);
42 class ReaderImpl final
: public Reader
{
44 ReaderImpl(scoped_refptr
<Context
> context
, Client
* client
);
45 virtual ~ReaderImpl();
46 virtual Result
read(void* data
, size_t size
, Flags flags
, size_t* readSize
);
47 virtual Result
beginRead(const void** buffer
,
50 virtual Result
endRead(size_t readSize
);
53 scoped_refptr
<Context
> context_
;
55 DISALLOW_COPY_AND_ASSIGN(ReaderImpl
);
58 SharedMemoryDataConsumerHandle(BackpressureMode mode
,
59 scoped_ptr
<Writer
>* writer
);
60 virtual ~SharedMemoryDataConsumerHandle();
62 scoped_ptr
<Reader
> ObtainReader(Client
* client
);
64 virtual Result
read(void* data
, size_t size
, Flags flags
, size_t* readSize
);
65 virtual Result
beginRead(const void** buffer
, Flags flags
, size_t* available
);
66 virtual Result
endRead(size_t readSize
);
67 virtual void registerClient(Client
* client
);
68 virtual void unregisterClient();
71 virtual ReaderImpl
* obtainReaderInternal(Client
* client
);
72 void LockImplicitly();
73 void UnlockImplicitly();
75 scoped_refptr
<Context
> context_
;
76 // This is an implicitly acquired reader for deprecated APIs.
77 scoped_ptr
<Reader
> reader_
;
79 DISALLOW_COPY_AND_ASSIGN(SharedMemoryDataConsumerHandle
);
82 } // namespace content
84 #endif // CONTENT_CHILD_SHARED_MEMORY_DATA_CONSUMER_HANDLE_H_