blob: 399cff326ecf2dfc08233c94984f2c802a47ac2f [file] [log] [blame]
[email protected]d8f868a62012-02-04 16:44:371// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]66085312010-11-05 22:14:252// 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_VAR_SERIALIZATION_RULES_H_
6#define PPAPI_PROXY_VAR_SERIALIZATION_RULES_H_
7
[email protected]67600b92012-03-10 06:51:488#include "base/memory/ref_counted.h"
[email protected]66085312010-11-05 22:14:259#include "ppapi/c/pp_var.h"
10
11#include <string>
12
[email protected]4d2efd22011-08-18 21:58:0213namespace ppapi {
[email protected]66085312010-11-05 22:14:2514namespace proxy {
15
16// Encapsulates the rules for serializing and deserializing vars to and from
17// the local process. The renderer and the plugin process each have separate
18// bookkeeping rules.
[email protected]67600b92012-03-10 06:51:4819class VarSerializationRules : public base::RefCounted<VarSerializationRules> {
[email protected]66085312010-11-05 22:14:2520 public:
[email protected]66085312010-11-05 22:14:2521 // Caller-owned calls --------------------------------------------------------
22 //
23 // A caller-owned call is when doing a function call with a "normal" input
24 // argument. The caller has a reference to the var, and the caller is
25 // responsible for freeing that reference.
26
[email protected]2d449b32012-02-07 05:38:0027 // Prepares the given var for sending to the remote process. For object vars,
28 // the returned var will contain the id valid for the host process.
29 // Otherwise, the returned var is valid in the local process.
30 virtual PP_Var SendCallerOwned(const PP_Var& var) = 0;
[email protected]66085312010-11-05 22:14:2531
32 // When receiving a caller-owned variable, normally we don't have to do
33 // anything. However, in the case of strings, we need to deserialize the
[email protected]2d449b32012-02-07 05:38:0034 // string from IPC, call the function, and then destroy the temporary string.
35 // These two functions handle that process.
[email protected]66085312010-11-05 22:14:2536 //
[email protected]2d449b32012-02-07 05:38:0037 // BeginReceiveCallerOwned takes a var from IPC and returns a new var
[email protected]4614f192011-01-21 00:26:4338 // representing the input in the local process.
[email protected]66085312010-11-05 22:14:2539 //
[email protected]d8f868a62012-02-04 16:44:3740 // EndReceiveCallerOwned releases the reference count in the Var tracker for
41 // the object or string that was added to the tracker. (Note, if the recipient
42 // took a reference to the Var, it will remain in the tracker after
43 // EndReceiveCallerOwned).
[email protected]67600b92012-03-10 06:51:4844 virtual PP_Var BeginReceiveCallerOwned(const PP_Var& var) = 0;
[email protected]66085312010-11-05 22:14:2545 virtual void EndReceiveCallerOwned(const PP_Var& var) = 0;
46
[email protected]b20df1c2011-08-03 14:38:2447 // Passing refs -------------------------------------------------------------
[email protected]66085312010-11-05 22:14:2548 //
49 // A pass-ref transfer is when ownership of a reference is passed from
[email protected]b20df1c2011-08-03 14:38:2450 // one side to the other. Normally, this happens via return values and
[email protected]66085312010-11-05 22:14:2551 // output arguments, as for exceptions. The code generating the value
52 // (the function returning it in the case of a return value) will AddRef
53 // the var on behalf of the consumer of the value. Responsibility for
54 // Release is on the consumer (the caller of the function in the case of a
55 // return value).
56
57 // Creates a var in the context of the local process from the given
[email protected]2d449b32012-02-07 05:38:0058 // deserialized var. The input var should be the result of calling
59 // SendPassRef in the remote process. The return value is the var valid in
60 // the host process for object vars. Otherwise, the return value is a var
61 // which is valid in the local process.
[email protected]67600b92012-03-10 06:51:4862 virtual PP_Var ReceivePassRef(const PP_Var& var) = 0;
[email protected]66085312010-11-05 22:14:2563
64 // Prepares a var to be sent to the remote side. One local reference will
65 // be passed to the remote side. Call Begin* before doing the send and End*
[email protected]2d449b32012-02-07 05:38:0066 // after doing the send
[email protected]f24448db2011-01-27 20:40:3967 //
[email protected]d8f868a62012-02-04 16:44:3768 // For object vars, the return value from BeginSendPassRef will be the var
69 // valid for the host process. Otherwise, it is a var that is valid in the
70 // local process. This same var must be passed to EndSendPassRef.
[email protected]2d449b32012-02-07 05:38:0071 virtual PP_Var BeginSendPassRef(const PP_Var& var) = 0;
[email protected]67600b92012-03-10 06:51:4872 virtual void EndSendPassRef(const PP_Var& var) = 0;
[email protected]66085312010-11-05 22:14:2573
74 // ---------------------------------------------------------------------------
75
76 virtual void ReleaseObjectRef(const PP_Var& var) = 0;
77
78 protected:
79 VarSerializationRules() {}
[email protected]95bbcc72012-07-11 00:07:5480 virtual ~VarSerializationRules() {}
81
82 private:
83 friend class base::RefCounted<VarSerializationRules>;
[email protected]66085312010-11-05 22:14:2584};
85
86} // namespace proxy
[email protected]4d2efd22011-08-18 21:58:0287} // namespace ppapi
[email protected]66085312010-11-05 22:14:2588
89#endif // PPAPI_PROXY_VAR_SERIALIZATION_RULES_H_