summaryrefslogtreecommitdiffstats
path: root/content/child/websocket_dispatcher.h
blob: e40053de41ca0a7e328185e93e110a4a8be932ba (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
// Copyright 2013 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_CHILD_WEBSOCKET_DISPATCHER_H_
#define CONTENT_CHILD_WEBSOCKET_DISPATCHER_H_

#include <stdint.h>
#include <map>
#include <string>
#include <vector>

#include "base/compiler_specific.h"
#include "base/macros.h"
#include "ipc/ipc_listener.h"

namespace content {

class WebSocketBridge;

// Dispatches WebSocket related messages sent to a child process from the
// main browser process.  There is one instance per child process. Messages
// are dispatched on the main child thread.  The ChildThread class
// creates an instance of WebSocketDispatcher and delegates calls to it.
class WebSocketDispatcher : public IPC::Listener {
 public:
  WebSocketDispatcher();
  ~WebSocketDispatcher() override;

  // Returns a unique channel id
  int AddBridge(WebSocketBridge* bridge);
  void RemoveBridge(int channel_id);

  // IPC::Listener implementation.
  bool OnMessageReceived(const IPC::Message& msg) override;

 private:
  WebSocketBridge* GetBridge(int channel_id, uint32_t type);

  std::map<int, WebSocketBridge*> bridges_;
  int channel_id_max_;

  DISALLOW_COPY_AND_ASSIGN(WebSocketDispatcher);
};

}  // namespace content

#endif  // CONTENT_CHILD_WEBSOCKET_DISPATCHER_H_