blob: 3da0926c14c3494210b867b7490573af00411061 [file] [log] [blame]
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <vector>
#include "base/memory/linked_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/shared_memory.h"
#include "content/common/content_export.h"
#include "content/public/child/request_peer.h"
namespace IPC {
class Sender;
} // namespace IPC
namespace content {
class CONTENT_EXPORT SharedMemoryReceivedDataFactory final
: public base::RefCounted<SharedMemoryReceivedDataFactory> {
SharedMemoryReceivedDataFactory(IPC::Sender* message_sender,
int request_id,
linked_ptr<base::SharedMemory> memory);
scoped_ptr<RequestPeer::ReceivedData> Create(int offset,
int length,
int encoded_length);
// Stops this factory. After calling this function, releasing issued data
// won't send ack signal to the browser process.
void Stop();
// Here TicketId is uint32_t, but a factory may issue more data by reusing id.
using TicketId = uint32_t;
class SharedMemoryReceivedData;
// Called by SharedMemoryReceivedData.
void Reclaim(TicketId id);
class TicketComparator;
friend class base::RefCounted<SharedMemoryReceivedDataFactory>;
void SendAck(size_t count);
TicketId id_;
TicketId oldest_;
std::vector<TicketId> released_tickets_;
// We assume that |message_sender_| is valid until |Stop| is called.
IPC::Sender* message_sender_;
int request_id_;
bool is_stopped_;
// Just to keep the payload alive while issued data is alive.
linked_ptr<base::SharedMemory> memory_;
} // namespace content