Additional fixes to new notification docs
[chromium-blink-merge.git] / ppapi / host / resource_message_handler.h
blob73f7f842aed54dd0b6ffa5dec87747296925ec58
1 // Copyright (c) 2012 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.
5 #ifndef PPAPI_HOST_RESOURCE_MESSAGE_HANDLER_H_
6 #define PPAPI_HOST_RESOURCE_MESSAGE_HANDLER_H_
8 #include "base/basictypes.h"
9 #include "ppapi/c/pp_stdint.h"
10 #include "ppapi/host/ppapi_host_export.h"
12 namespace IPC {
13 class Message;
16 namespace ppapi {
17 namespace host {
19 struct HostMessageContext;
20 struct ReplyMessageContext;
22 // This is the base class of classes that can handle resource messages. It
23 // mainly exists at present to share code for checking replies to resource
24 // messages are valid.
25 class PPAPI_HOST_EXPORT ResourceMessageHandler {
26 public:
27 ResourceMessageHandler();
28 virtual ~ResourceMessageHandler();
30 // Called when this handler should handle a particular message. This should
31 // call into the the message handler implemented by subclasses (i.e.
32 // |OnResourceMessageReceived|) and perform any additional work necessary to
33 // handle the message (e.g. checking resource replies are valid). True is
34 // returned if the message is handled and false otherwise.
35 virtual bool HandleMessage(const IPC::Message& msg,
36 HostMessageContext* context) = 0;
38 // Send a resource reply message.
39 virtual void SendReply(const ReplyMessageContext& context,
40 const IPC::Message& msg) = 0;
42 protected:
43 // Runs the message handler and checks that a reply was sent if necessary.
44 void RunMessageHandlerAndReply(const IPC::Message& msg,
45 HostMessageContext* context);
47 // Handles messages associated with a given resource object. If the flags
48 // indicate that a response is required, the return value of this function
49 // will be sent as a resource message "response" along with the message
50 // specified in the reply of the context.
52 // You can do a response asynchronously by returning PP_OK_COMPLETIONPENDING.
53 // This will cause the reply to be skipped, and the class implementing this
54 // function will take responsibility for issuing the callback. The callback
55 // can be issued inside OnResourceMessageReceived before it returns, or at
56 // a future time.
58 // If you don't have a particular reply message, you can just ignore
59 // the reply in the message context. However, if you have a reply more than
60 // just the int32_t result code, set the reply to be the message of your
61 // choosing.
63 // The default implementation just returns PP_ERROR_NOTSUPPORTED.
64 virtual int32_t OnResourceMessageReceived(const IPC::Message& msg,
65 HostMessageContext* context);
67 private:
68 DISALLOW_COPY_AND_ASSIGN(ResourceMessageHandler);
71 } // namespace host
72 } // namespace ppapi
74 #endif // PPAPI_HOST_RESOURCE_MESSAGE_HANDLER_H_