blob: 3d58d9ff4c471a331d96d71206a1830f0a9cd1e0 [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
[email protected]e87640bd2014-06-18 16:44:0012#include "base/memory/ref_counted.h"
[email protected]e87640bd2014-06-18 16:44:0013#include "ppapi/c/pp_resource.h"
14#include "ppapi/c/ppp_message_handler.h"
15#include "ppapi/proxy/ppapi_proxy_export.h"
16
17namespace IPC {
18class Message;
19}
20
21namespace ppapi {
22
23class ScopedPPVar;
24
25namespace proxy {
26
27class MessageLoopResource;
28
29// MessageHandler wraps a PPP_MessageHandler to encapsulate calling methods
30// on the right thread and calling the Destroy function when this
31// MessageHandler is destroyed.
32class PPAPI_PROXY_EXPORT MessageHandler {
33 public:
34 // Create a MessageHandler. If any parameters are invalid, it will return a
35 // null scoped_ptr and set |*error| appropriately.
36 // |handler_if| is the struct of function pointers we will invoke. All of
37 // the function pointers within must be valid, or we fail
38 // with PP_ERROR_BADARGUMENT.
39 // |user_data| is a pointer provided by the plugin that we pass back when we
40 // call functions in |handler_if|.
41 // |message_loop| is the message loop where we will invoke functions in
42 // |handler_if|. Must not be the main thread message loop,
43 // to try to force the plugin to not over-subscribe the main
44 // thread. If it's the main thread loop, |error| will be set
45 // to PP_ERROR_WRONGTHREAD.
46 // |error| is an out-param that will be set on failure.
dchengced92242016-04-07 00:00:1247 static std::unique_ptr<MessageHandler> Create(
[email protected]e87640bd2014-06-18 16:44:0048 PP_Instance instance,
Dave Michael970fa0cf2014-09-17 20:56:1049 const PPP_MessageHandler_0_2* handler_if,
50 void* user_data,
51 PP_Resource message_loop,
52 int32_t* error);
Peter Boström3d5b3cb2021-09-23 21:35:4553
54 MessageHandler(const MessageHandler&) = delete;
55 MessageHandler& operator=(const MessageHandler&) = delete;
56
[email protected]e87640bd2014-06-18 16:44:0057 ~MessageHandler();
58
59 bool LoopIsValid() const;
60
61 void HandleMessage(ScopedPPVar var);
62 void HandleBlockingMessage(ScopedPPVar var,
dchengced92242016-04-07 00:00:1263 std::unique_ptr<IPC::Message> reply_msg);
[email protected]e87640bd2014-06-18 16:44:0064
65 private:
66 MessageHandler(PP_Instance instance,
Dave Michael970fa0cf2014-09-17 20:56:1067 const PPP_MessageHandler_0_2* handler_if,
68 void* user_data,
69 scoped_refptr<MessageLoopResource> message_loop);
[email protected]e87640bd2014-06-18 16:44:0070 PP_Instance instance_;
Dave Michael970fa0cf2014-09-17 20:56:1071 const PPP_MessageHandler_0_2* handler_if_;
[email protected]e87640bd2014-06-18 16:44:0072 void* user_data_;
73 scoped_refptr<MessageLoopResource> message_loop_;
[email protected]e87640bd2014-06-18 16:44:0074};
75
76} // namespace proxy
77} // namespace ppapi
78
79#endif // PPAPI_PROXY_MESSAGE_HANDLER_H_