[Android WebView] Fix webview perf bot switchover to use org.chromium.webview_shell...
[chromium-blink-merge.git] / content / child / shared_memory_data_consumer_handle.h
blob188d028e2e399f1c4bc4cdf20757c0daf58a4907
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"
14 namespace content {
16 // This class is a WebDataConsumerHandle that accepts RequestPeer::ReceivedData.
17 class CONTENT_EXPORT SharedMemoryDataConsumerHandle final
18 : public NON_EXPORTED_BASE(blink::WebDataConsumerHandle) {
19 private:
20 class Context;
22 public:
23 enum BackpressureMode {
24 kApplyBackpressure,
25 kDoNotApplyBackpressure,
28 class CONTENT_EXPORT Writer final {
29 public:
30 Writer(const scoped_refptr<Context>& context, BackpressureMode mode);
31 ~Writer();
32 void AddData(scoped_ptr<RequestPeer::ReceivedData> data);
33 void Close();
35 private:
36 scoped_refptr<Context> context_;
37 BackpressureMode mode_;
39 DISALLOW_COPY_AND_ASSIGN(Writer);
42 class ReaderImpl final : public Reader {
43 public:
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,
48 Flags flags,
49 size_t* available);
50 virtual Result endRead(size_t readSize);
52 private:
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();
70 private:
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_