Switch from using codec ids to codec name hashes.
[chromium-blink-merge.git] / content / child / shared_memory_received_data_factory.h
blob3da0926c14c3494210b867b7490573af00411061
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_
8 #include <vector>
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"
17 namespace IPC {
18 class Sender;
19 } // namespace IPC
21 namespace content {
23 class CONTENT_EXPORT SharedMemoryReceivedDataFactory final
24 : public base::RefCounted<SharedMemoryReceivedDataFactory> {
25 public:
26 SharedMemoryReceivedDataFactory(IPC::Sender* message_sender,
27 int request_id,
28 linked_ptr<base::SharedMemory> memory);
30 scoped_ptr<RequestPeer::ReceivedData> Create(int offset,
31 int length,
32 int encoded_length);
34 // Stops this factory. After calling this function, releasing issued data
35 // won't send ack signal to the browser process.
36 void Stop();
38 private:
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);
52 TicketId id_;
53 TicketId oldest_;
54 std::vector<TicketId> released_tickets_;
55 // We assume that |message_sender_| is valid until |Stop| is called.
56 IPC::Sender* message_sender_;
57 int request_id_;
58 bool is_stopped_;
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_