Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: ppapi/proxy/plugin_var_serialization_rules.cc

Issue 4096008: Var serialization-related proxy stuff. This allows vars to be sent over IPC... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/proxy/plugin_var_serialization_rules.h ('k') | ppapi/proxy/serialized_var.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // 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 #include "ppapi/proxy/plugin_var_serialization_rules.h"
6
7 #include "ppapi/proxy/plugin_var_tracker.h"
8
9 namespace pp {
10 namespace proxy {
11
12 PluginVarSerializationRules::PluginVarSerializationRules(
13 PluginVarTracker* var_tracker)
14 : var_tracker_(var_tracker) {
15 }
16
17 PluginVarSerializationRules::~PluginVarSerializationRules() {
18 }
19
20 void PluginVarSerializationRules::SendCallerOwned(const PP_Var& var,
21 std::string* str_val) {
22 // Nothing to do since we manage the refcount, other than retrieve the string
23 // to use for IPC.
24 if (var.type == PP_VARTYPE_STRING)
25 *str_val = var_tracker_->GetString(var);
26 }
27
28 PP_Var PluginVarSerializationRules::BeginReceiveCallerOwned(
29 const PP_Var& var,
30 const std::string* str_val) {
31 if (var.type == PP_VARTYPE_STRING) {
32 // Convert the string to the context of the current process.
33 PP_Var ret;
34 ret.type = PP_VARTYPE_STRING;
35 ret.value.as_id = var_tracker_->MakeString(*str_val);
36 return ret;
37 }
38
39 return var;
40 }
41
42 void PluginVarSerializationRules::EndReceiveCallerOwned(const PP_Var& var) {
43 if (var.type == PP_VARTYPE_STRING) {
44 // Destroy the string BeginReceiveCallerOwned created above.
45 var_tracker_->Release(var);
46 }
47 }
48
49 PP_Var PluginVarSerializationRules::ReceivePassRef(const PP_Var& var,
50 const std::string& str_val) {
51 if (var.type == PP_VARTYPE_STRING) {
52 // Convert the string to the context of the current process.
53 PP_Var ret;
54 ret.type = PP_VARTYPE_STRING;
55 ret.value.as_id = var_tracker_->MakeString(str_val);
56 return ret;
57 }
58
59 // Overview of sending an object with "pass ref" from the browser to the
60 // plugin:
61 // Example 1 Example 2
62 // Plugin Browser Plugin Browser
63 // Before send 3 2 0 1
64 // Browser calls BeginSendPassRef 3 2 0 1
65 // Plugin calls ReceivePassRef 4 1 1 1
66 // Browser calls EndSendPassRef 4 1 1 1
67 //
68 // In example 1 before the send, the plugin has 3 refs which are represented
69 // as one ref in the browser (since the plugin only tells the browser when
70 // it's refcount goes from 1 -> 0). The initial state is that the browser
71 // plugin code started to return a value, which means it gets another ref
72 // on behalf of the caller. This needs to be transferred to the plugin and
73 // folded in to its set of refs it maintains (with one ref representing all
74 // fo them in the browser).
75 if (var.type == PP_VARTYPE_OBJECT)
76 var_tracker_->ReceiveObjectPassRef(var);
77 return var;
78 }
79
80 void PluginVarSerializationRules::BeginSendPassRef(const PP_Var& var,
81 std::string* str_val) {
82 // Overview of sending an object with "pass ref" from the plugin to the
83 // browser:
84 // Example 1 Example 2
85 // Plugin Browser Plugin Browser
86 // Before send 3 1 1 1
87 // Plugin calls BeginSendPassRef 3 1 1 1
88 // Browser calls ReceivePassRef 3 2 1 2
89 // Plugin calls EndSendPassRef 2 2 0 1
90 //
91 // The plugin maintains one ref count in the browser on behalf of the
92 // entire ref count in the plugin. When the plugin refcount goes to 0, it
93 // will call the browser to deref the object. This is why in example 2
94 // transferring the object ref to the browser involves no net change in the
95 // browser's refcount.
96
97 if (var.type == PP_VARTYPE_STRING)
98 *str_val = var_tracker_->GetString(var);
99 }
100
101 void PluginVarSerializationRules::EndSendPassRef(const PP_Var& var) {
102 // See BeginSendPassRef for an example of why we release our ref here.
103 if (var.type == PP_VARTYPE_OBJECT)
104 var_tracker_->Release(var);
105 }
106
107 void PluginVarSerializationRules::ReleaseObjectRef(const PP_Var& var) {
108 var_tracker_->Release(var);
109 }
110
111 } // namespace proxy
112 } // namespace pp
OLDNEW
« no previous file with comments | « ppapi/proxy/plugin_var_serialization_rules.h ('k') | ppapi/proxy/serialized_var.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698