summaryrefslogtreecommitdiffstats
path: root/content/browser/renderer_host/pepper_tcp_server_socket.h
blob: 77b5f43693218748c75261413ed9ce47019c157d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright (c) 2012 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.

#ifndef CONTENT_BROWSER_RENDERER_HOST_PEPPER_TCP_SERVER_SOCKET_H_
#define CONTENT_BROWSER_RENDERER_HOST_PEPPER_TCP_SERVER_SOCKET_H_
#pragma once

#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"

class PepperMessageFilter;
struct PP_NetAddress_Private;

namespace net {
class ServerSocket;
class StreamSocket;
}

// PepperTCPSocket is used by PepperMessageFilter to handle requests
// from the Pepper TCP server socket API
// (PPB_TCPServerSocket_Private).
class PepperTCPServerSocket {
 public:
  PepperTCPServerSocket(PepperMessageFilter* manager,
                        int32 routing_id,
                        uint32 plugin_dispatcher_id,
                        uint32 real_socket_id,
                        uint32 temp_socket_id);
  ~PepperTCPServerSocket();

  void Listen(const PP_NetAddress_Private& addr, int32 backlog);
  void Accept();

 private:
  enum State {
    BEFORE_LISTENING,
    LISTEN_IN_PROGRESS,
    LISTENING,
    ACCEPT_IN_PROGRESS,
  };

  void CancelListenRequest();
  void SendAcceptACKError();

  void OnListenCompleted(int result);
  void OnAcceptCompleted(int result);

  PepperMessageFilter* manager_;
  int32 routing_id_;
  uint32 plugin_dispatcher_id_;
  uint32 real_socket_id_;
  uint32 temp_socket_id_;

  State state_;

  scoped_ptr<net::ServerSocket> socket_;
  scoped_ptr<net::StreamSocket> socket_buffer_;

  DISALLOW_COPY_AND_ASSIGN(PepperTCPServerSocket);
};

#endif  // CONTENT_BROWSER_RENDERER_HOST_PEPPER_TCP_SERVER_SOCKET_H_