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_RECEIVED_DATA_FACTORY_H_
6 #define CONTENT_CHILD_SHARED_MEMORY_RECEIVED_DATA_FACTORY_H_
10 #include "base/memory/linked_ptr.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/shared_memory.h"
14 #include "content/common/content_export.h"
15 #include "content/public/child/request_peer.h"
23 class CONTENT_EXPORT SharedMemoryReceivedDataFactory final
24 : public base::RefCounted
<SharedMemoryReceivedDataFactory
> {
26 SharedMemoryReceivedDataFactory(IPC::Sender
* message_sender
,
28 linked_ptr
<base::SharedMemory
> memory
);
30 scoped_ptr
<RequestPeer::ReceivedData
> Create(int offset
,
34 // Stops this factory. After calling this function, releasing issued data
35 // won't send ack signal to the browser process.
39 // Here TicketId is uint32_t, but a factory may issue more data by reusing id.
40 using TicketId
= uint32_t;
42 class SharedMemoryReceivedData
;
43 // Called by SharedMemoryReceivedData.
44 void Reclaim(TicketId id
);
46 class TicketComparator
;
47 friend class base::RefCounted
<SharedMemoryReceivedDataFactory
>;
48 ~SharedMemoryReceivedDataFactory();
50 void SendAck(size_t count
);
54 std::vector
<TicketId
> released_tickets_
;
55 // We assume that |message_sender_| is valid until |Stop| is called.
56 IPC::Sender
* message_sender_
;
59 // Just to keep the payload alive while issued data is alive.
60 linked_ptr
<base::SharedMemory
> memory_
;
62 DISALLOW_COPY_AND_ASSIGN(SharedMemoryReceivedDataFactory
);
65 } // namespace content
67 #endif // CONTENT_CHILD_SHARED_MEMORY_RECEIVED_DATA_FACTORY_H_