blob: 363312e44d1968f7f03e4378fad290f0dde12c1f [file] [log] [blame]
[email protected]e87640bd2014-06-18 16:44:001// Copyright 2014 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.
4
5#ifndef PPAPI_PROXY_MESSAGE_HANDLER_H_
6#define PPAPI_PROXY_MESSAGE_HANDLER_H_
7
avie029c4132015-12-23 06:45:228#include <stdint.h>
9
dchengced92242016-04-07 00:00:1210#include <memory>
11
avie029c4132015-12-23 06:45:2212#include "base/macros.h"
[email protected]e87640bd2014-06-18 16:44:0013#include "base/memory/ref_counted.h"
[email protected]e87640bd2014-06-18 16:44:0014#include "ppapi/c/pp_resource.h"
15#include "ppapi/c/ppp_message_handler.h"
16#include "ppapi/proxy/ppapi_proxy_export.h"
17
18namespace IPC {
19class Message;
20}
21
22namespace ppapi {
23
24class ScopedPPVar;
25
26namespace proxy {
27
28class MessageLoopResource;
29
30// MessageHandler wraps a PPP_MessageHandler to encapsulate calling methods
31// on the right thread and calling the Destroy function when this
32// MessageHandler is destroyed.
33class PPAPI_PROXY_EXPORT MessageHandler {
34 public:
35 // Create a MessageHandler. If any parameters are invalid, it will return a
36 // null scoped_ptr and set |*error| appropriately.
37 // |handler_if| is the struct of function pointers we will invoke. All of
38 // the function pointers within must be valid, or we fail
39 // with PP_ERROR_BADARGUMENT.
40 // |user_data| is a pointer provided by the plugin that we pass back when we
41 // call functions in |handler_if|.
42 // |message_loop| is the message loop where we will invoke functions in
43 // |handler_if|. Must not be the main thread message loop,
44 // to try to force the plugin to not over-subscribe the main
45 // thread. If it's the main thread loop, |error| will be set
46 // to PP_ERROR_WRONGTHREAD.
47 // |error| is an out-param that will be set on failure.
dchengced92242016-04-07 00:00:1248 static std::unique_ptr<MessageHandler> Create(
[email protected]e87640bd2014-06-18 16:44:0049 PP_Instance instance,
Dave Michael970fa0cf2014-09-17 20:56:1050 const PPP_MessageHandler_0_2* handler_if,
51 void* user_data,
52 PP_Resource message_loop,
53 int32_t* error);
[email protected]e87640bd2014-06-18 16:44:0054 ~MessageHandler();
55
56 bool LoopIsValid() const;
57
58 void HandleMessage(ScopedPPVar var);
59 void HandleBlockingMessage(ScopedPPVar var,
dchengced92242016-04-07 00:00:1260 std::unique_ptr<IPC::Message> reply_msg);
[email protected]e87640bd2014-06-18 16:44:0061
62 private:
63 MessageHandler(PP_Instance instance,
Dave Michael970fa0cf2014-09-17 20:56:1064 const PPP_MessageHandler_0_2* handler_if,
65 void* user_data,
66 scoped_refptr<MessageLoopResource> message_loop);
[email protected]e87640bd2014-06-18 16:44:0067 PP_Instance instance_;
Dave Michael970fa0cf2014-09-17 20:56:1068 const PPP_MessageHandler_0_2* handler_if_;
[email protected]e87640bd2014-06-18 16:44:0069 void* user_data_;
70 scoped_refptr<MessageLoopResource> message_loop_;
71
72 DISALLOW_COPY_AND_ASSIGN(MessageHandler);
73};
74
75} // namespace proxy
76} // namespace ppapi
77
78#endif // PPAPI_PROXY_MESSAGE_HANDLER_H_