blob: 5f8233c1df5bf4ac78c7e153a1a01446569a585b [file] [log] [blame]
[email protected]c2932f5e2010-11-03 03:22:331// Copyright (c) 2010 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_CALLBACK_TRACKER_H_
6#define PPAPI_PROXY_CALLBACK_TRACKER_H_
7
8#include <map>
9
10#include "ppapi/c/pp_completion_callback.h"
11#include "ppapi/c/pp_stdint.h"
12
13namespace pp {
14namespace proxy {
15
16class Dispatcher;
17
18// This object tracks cross-process callbacks. When the plugin sends a callback
19// object to the renderer, we save the information and pass an identifier
20// instead.
21//
22// On the renderer side, this identifier is converted to a new callback in that
23// process. When executed, this new callback sends an IPC message containing the
24// previous identifier back to the plugin.
25//
26// When we receive that message, ExecuteSerializedCallback converts the
27// identifier back to the original callback information and runs the callback.
28class CallbackTracker {
29 public:
30 CallbackTracker(Dispatcher* dispatcher);
31 ~CallbackTracker();
32
33 // Converts the given callback in the context of the plugin to a serialized
34 // ID. This will be passed to ReceiveCallback on the renderer side.
35 uint32_t SendCallback(PP_CompletionCallback callback);
36
37 // Converts the given serialized callback ID to a new completion callback in
38 // the context of the current process. This callback actually will represent
39 // a proxy that will execute the callback in the plugin process.
40 PP_CompletionCallback ReceiveCallback(uint32_t serialized_callback);
41
42 // Sends a request to the remote process to execute the given callback.
43 void SendExecuteSerializedCallback(uint32_t serialized_callback,
44 int32_t param);
45
46 // Executes the given callback ID with the given result in the current
47 // process. This will also destroy the information associated with the
48 // callback and the serialized ID won't be valid any more.
49 void ReceiveExecuteSerializedCallback(uint32_t serialized_callback,
50 int32_t param);
51
52 private:
53 // Pointer to the dispatcher that owns us.
54 Dispatcher* dispatcher_;
55
56 int32_t next_callback_id_;
57
58 // Maps callback IDs to the actual callback objects in the plugin process.
59 typedef std::map<int32_t, PP_CompletionCallback> CallbackMap;
60 CallbackMap callback_map_;
61};
62
63} // namespace proxy
64} // namespace pp
65
66#endif // PPAPI_PROXY_CALLBACK_TRACKER_H_