Remove special handling for strings in var serialization.
Previously we had to have a lot of weird string handling because strings needed a PP_Module to be constructed, and because they had different methods for being created in the host and the plugin processes. We've removed all of these limitations, so now we can just delete the whole mess.
Review URL: https://chromiumcodereview.appspot.com/9316123
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@120724 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/ppapi/proxy/host_var_serialization_rules.cc b/ppapi/proxy/host_var_serialization_rules.cc
index 45eaf40..52b2cbc 100644
--- a/ppapi/proxy/host_var_serialization_rules.cc
+++ b/ppapi/proxy/host_var_serialization_rules.cc
@@ -24,56 +24,33 @@
HostVarSerializationRules::~HostVarSerializationRules() {
}
-PP_Var HostVarSerializationRules::SendCallerOwned(
- const PP_Var& var,
- const std::string** str_ptr_out) {
- if (var.type == PP_VARTYPE_STRING)
- VarToStringPtr(var, str_ptr_out);
+PP_Var HostVarSerializationRules::SendCallerOwned(const PP_Var& var) {
return var;
}
PP_Var HostVarSerializationRules::BeginReceiveCallerOwned(
const PP_Var& var,
- scoped_ptr<std::string> str,
Dispatcher* /* dispatcher */) {
- if (var.type == PP_VARTYPE_STRING) {
- // Put the string in to the VarTracker (transferring ownership, since we
- // would otherwise just delete the one we received from IPC). This allows
- // us to avoid unnecessary copying of the string.
- return StringVar::StringToPPVar(str.Pass());
- }
return var;
}
void HostVarSerializationRules::EndReceiveCallerOwned(const PP_Var& var) {
if (var.type == PP_VARTYPE_STRING) {
- // Destroy the string BeginReceiveCallerOwned created above.
+ // Destroy the string.
PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(var);
}
}
PP_Var HostVarSerializationRules::ReceivePassRef(
const PP_Var& var,
- scoped_ptr<std::string> str,
Dispatcher* /* dispatcher */) {
- if (var.type == PP_VARTYPE_STRING) {
- // Put the string in to the tracker, transferring ownership.
- return StringVar::StringToPPVar(str.Pass());
- }
-
// See PluginVarSerialization::BeginSendPassRef for an example.
if (var.type == PP_VARTYPE_OBJECT)
PpapiGlobals::Get()->GetVarTracker()->AddRefVar(var);
return var;
}
-PP_Var HostVarSerializationRules::BeginSendPassRef(
- const PP_Var& var,
- const std::string** str_ptr_out) {
- // See PluginVarSerialization::ReceivePassRef for an example. We don't need
- // to do anything here other than convert the string.
- if (var.type == PP_VARTYPE_STRING)
- VarToStringPtr(var, str_ptr_out);
+PP_Var HostVarSerializationRules::BeginSendPassRef(const PP_Var& var) {
return var;
}
@@ -83,16 +60,6 @@
// to do anything here.
}
-void HostVarSerializationRules::VarToStringPtr(
- const PP_Var& var,
- const std::string** str_ptr_out) {
- DCHECK(var.type == PP_VARTYPE_STRING);
- *str_ptr_out = NULL;
- StringVar* string_var = StringVar::FromPPVar(var);
- if (string_var)
- *str_ptr_out = string_var->ptr();
-}
-
void HostVarSerializationRules::ReleaseObjectRef(const PP_Var& var) {
PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(var);
}
diff --git a/ppapi/proxy/host_var_serialization_rules.h b/ppapi/proxy/host_var_serialization_rules.h
index 609980fc..9f52aed 100644
--- a/ppapi/proxy/host_var_serialization_rules.h
+++ b/ppapi/proxy/host_var_serialization_rules.h
@@ -22,25 +22,17 @@
~HostVarSerializationRules();
// VarSerialization implementation.
- virtual PP_Var SendCallerOwned(const PP_Var& var,
- const std::string** str_ptr_out);
+ virtual PP_Var SendCallerOwned(const PP_Var& var);
virtual PP_Var BeginReceiveCallerOwned(const PP_Var& var,
- scoped_ptr<std::string> str,
Dispatcher* dispatcher);
virtual void EndReceiveCallerOwned(const PP_Var& var);
virtual PP_Var ReceivePassRef(const PP_Var& var,
- scoped_ptr<std::string> str,
Dispatcher* dispatcher);
- virtual PP_Var BeginSendPassRef(const PP_Var& var,
- const std::string** str_ptr_out);
+ virtual PP_Var BeginSendPassRef(const PP_Var& var);
virtual void EndSendPassRef(const PP_Var& var, Dispatcher* dispatcher);
virtual void ReleaseObjectRef(const PP_Var& var);
private:
- // Converts the given var (which must be a VARTYPE_STRING) to the given
- // string object.
- void VarToStringPtr(const PP_Var& var, const std::string** str);
-
PP_Module pp_module_;
DISALLOW_COPY_AND_ASSIGN(HostVarSerializationRules);
diff --git a/ppapi/proxy/plugin_var_serialization_rules.cc b/ppapi/proxy/plugin_var_serialization_rules.cc
index 87a3cc2..0456637 100644
--- a/ppapi/proxy/plugin_var_serialization_rules.cc
+++ b/ppapi/proxy/plugin_var_serialization_rules.cc
@@ -22,44 +22,27 @@
PluginVarSerializationRules::~PluginVarSerializationRules() {
}
-PP_Var PluginVarSerializationRules::SendCallerOwned(
- const PP_Var& var,
- const std::string** str_ptr_out) {
+PP_Var PluginVarSerializationRules::SendCallerOwned(const PP_Var& var) {
// Objects need special translations to get the IDs valid in the host.
if (var.type == PP_VARTYPE_OBJECT)
return var_tracker_->GetHostObject(var);
-
- // Retrieve the pointer to the string in the tracker in order to send the
- // string over IPC without unnecessary copies.
- if (var.type == PP_VARTYPE_STRING) {
- StringVar* string_var = StringVar::FromPPVar(var);
- if (string_var)
- *str_ptr_out = string_var->ptr();
- else
- NOTREACHED() << "Trying to send unknown string over IPC.";
- }
return var;
}
PP_Var PluginVarSerializationRules::BeginReceiveCallerOwned(
const PP_Var& var,
- scoped_ptr<std::string> str,
Dispatcher* dispatcher) {
- if (var.type == PP_VARTYPE_STRING)
- return StringVar::StringToPPVar(str.Pass());
-
if (var.type == PP_VARTYPE_OBJECT) {
DCHECK(dispatcher->IsPlugin());
return var_tracker_->TrackObjectWithNoReference(
var, static_cast<PluginDispatcher*>(dispatcher));
}
-
return var;
}
void PluginVarSerializationRules::EndReceiveCallerOwned(const PP_Var& var) {
if (var.type == PP_VARTYPE_STRING) {
- // Destroy the string BeginReceiveCallerOwned created above.
+ // Destroy the string.
var_tracker_->ReleaseVar(var);
} else if (var.type == PP_VARTYPE_OBJECT) {
var_tracker_->StopTrackingObjectWithNoReference(var);
@@ -67,11 +50,7 @@
}
PP_Var PluginVarSerializationRules::ReceivePassRef(const PP_Var& var,
- scoped_ptr<std::string> str,
Dispatcher* dispatcher) {
- if (var.type == PP_VARTYPE_STRING)
- return StringVar::StringToPPVar(str.Pass());
-
// Overview of sending an object with "pass ref" from the browser to the
// plugin:
// Example 1 Example 2
@@ -98,9 +77,7 @@
return var;
}
-PP_Var PluginVarSerializationRules::BeginSendPassRef(
- const PP_Var& var,
- const std::string** str_ptr_out) {
+PP_Var PluginVarSerializationRules::BeginSendPassRef(const PP_Var& var) {
// Overview of sending an object with "pass ref" from the plugin to the
// browser:
// Example 1 Example 2
@@ -119,16 +96,6 @@
// Objects need special translations to get the IDs valid in the host.
if (var.type == PP_VARTYPE_OBJECT)
return var_tracker_->GetHostObject(var);
-
- if (var.type == PP_VARTYPE_STRING) {
- // Get the pointer to the string that's in the tracker and return it, so we
- // can avoid an extra copy of the string when serializing over IPC.
- StringVar* string_var = StringVar::FromPPVar(var);
- if (string_var)
- *str_ptr_out = string_var->ptr();
- else
- NOTREACHED() << "Trying to send unknown string over IPC.";
- }
return var;
}
diff --git a/ppapi/proxy/plugin_var_serialization_rules.h b/ppapi/proxy/plugin_var_serialization_rules.h
index 86935053..174c4bb47 100644
--- a/ppapi/proxy/plugin_var_serialization_rules.h
+++ b/ppapi/proxy/plugin_var_serialization_rules.h
@@ -22,17 +22,12 @@
~PluginVarSerializationRules();
// VarSerialization implementation.
- virtual PP_Var SendCallerOwned(const PP_Var& var,
- const std::string** str_ptr_out);
+ virtual PP_Var SendCallerOwned(const PP_Var& var);
virtual PP_Var BeginReceiveCallerOwned(const PP_Var& var,
- scoped_ptr<std::string> str,
Dispatcher* dispatcher);
virtual void EndReceiveCallerOwned(const PP_Var& var);
- virtual PP_Var ReceivePassRef(const PP_Var& var,
- scoped_ptr<std::string> str,
- Dispatcher* dispatcher);
- virtual PP_Var BeginSendPassRef(const PP_Var& var,
- const std::string** str_ptr_out);
+ virtual PP_Var ReceivePassRef(const PP_Var& var, Dispatcher* dispatcher);
+ virtual PP_Var BeginSendPassRef(const PP_Var& var);
virtual void EndSendPassRef(const PP_Var& var, Dispatcher* dispatcher);
virtual void ReleaseObjectRef(const PP_Var& var);
diff --git a/ppapi/proxy/serialized_var.cc b/ppapi/proxy/serialized_var.cc
index 00bb296d..7153c0c 100644
--- a/ppapi/proxy/serialized_var.cc
+++ b/ppapi/proxy/serialized_var.cc
@@ -10,6 +10,7 @@
#include "ppapi/proxy/interface_proxy.h"
#include "ppapi/proxy/ppapi_param_traits.h"
#include "ppapi/proxy/var_serialization_rules.h"
+#include "ppapi/shared_impl/var.h"
namespace ppapi {
namespace proxy {
@@ -19,7 +20,6 @@
SerializedVar::Inner::Inner()
: serialization_rules_(NULL),
var_(PP_MakeUndefined()),
- tracker_string_ptr_(NULL),
cleanup_mode_(CLEANUP_NONE),
dispatcher_for_end_send_pass_ref_(NULL) {
#ifndef NDEBUG
@@ -31,7 +31,6 @@
SerializedVar::Inner::Inner(VarSerializationRules* serialization_rules)
: serialization_rules_(serialization_rules),
var_(PP_MakeUndefined()),
- tracker_string_ptr_(NULL),
cleanup_mode_(CLEANUP_NONE),
dispatcher_for_end_send_pass_ref_(NULL) {
#ifndef NDEBUG
@@ -57,15 +56,6 @@
PP_Var SerializedVar::Inner::GetVar() const {
DCHECK(serialization_rules_);
-
- // If we're a string var, we should have already converted the string value
- // to a var ID.
- DCHECK(var_.type != PP_VARTYPE_STRING || var_.value.as_id != 0);
- return var_;
-}
-
-PP_Var SerializedVar::Inner::GetIncompleteVar() const {
- DCHECK(serialization_rules_);
return var_;
}
@@ -76,29 +66,8 @@
var_ = var;
}
-scoped_ptr<std::string> SerializedVar::Inner::GetStringDestructive() {
- DCHECK(serialization_rules_);
- return string_from_ipc_.Pass();
-}
-
-const std::string** SerializedVar::Inner::GetStringPtrPtr() {
- DCHECK(serialization_rules_);
- // The caller will set our string pointer, and we promise not to change it.
- // This path is taken for the "Send" side of SerializedVars, and we will only
- // read the string in those cases, so it's safe for us to point directly to a
- // string in the VarTracker.
- return &tracker_string_ptr_;
-}
-
-void SerializedVar::Inner::ForceSetVarValueForTest(PP_Var value) {
- var_ = value;
-}
-
-void SerializedVar::Inner::ForceSetStringValueForTest(const std::string& str) {
- // We don't need to change tracker_string_ptr_, as that is only used for
- // serializing, and we're emulating a SerializedVar that was received from
- // IPC.
- string_from_ipc_.reset(new std::string(str));
+void SerializedVar::Inner::ForceSetVarValueForTest(PP_Var value) {
+ var_ = value;
}
void SerializedVar::Inner::WriteToMessage(IPC::Message* m) const {
@@ -121,10 +90,6 @@
has_been_serialized_ = true;
#endif
- // If the var is not a string type, we should not have ended up with any
- // string data.
- DCHECK(var_.type == PP_VARTYPE_STRING || !tracker_string_ptr_);
-
m->WriteInt(static_cast<int>(var_.type));
switch (var_.type) {
case PP_VARTYPE_UNDEFINED:
@@ -141,15 +106,16 @@
case PP_VARTYPE_DOUBLE:
IPC::ParamTraits<double>::Write(m, var_.value.as_double);
break;
- case PP_VARTYPE_STRING:
+ case PP_VARTYPE_STRING: {
// TODO(brettw) in the case of an invalid string ID, it would be nice
// to send something to the other side such that a 0 ID would be
// generated there. Then the function implementing the interface can
// handle the invalid string as if it was in process rather than seeing
// what looks like a valid empty string.
- m->WriteString(tracker_string_ptr_ ? *tracker_string_ptr_
- : std::string());
+ StringVar* string_var = StringVar::FromPPVar(var_);
+ m->WriteString(string_var ? *string_var->ptr() : std::string());
break;
+ }
case PP_VARTYPE_ARRAY_BUFFER:
// TODO(dmichael): Proxy ArrayBuffer.
NOTIMPLEMENTED();
@@ -204,12 +170,12 @@
case PP_VARTYPE_DOUBLE:
success = IPC::ParamTraits<double>::Read(m, iter, &var_.value.as_double);
break;
- case PP_VARTYPE_STRING:
- DCHECK(!tracker_string_ptr_ && !string_from_ipc_.get());
- string_from_ipc_.reset(new std::string);
- success = m->ReadString(iter, string_from_ipc_.get());
- var_.value.as_id = 0;
+ case PP_VARTYPE_STRING: {
+ std::string string_from_ipc;
+ success = m->ReadString(iter, &string_from_ipc);
+ var_ = StringVar::SwapValidatedUTF8StringIntoPPVar(&string_from_ipc);
break;
+ }
case PP_VARTYPE_OBJECT:
success = m->ReadInt64(iter, &var_.value.as_id);
break;
@@ -260,8 +226,7 @@
SerializedVarSendInput::SerializedVarSendInput(Dispatcher* dispatcher,
const PP_Var& var)
: SerializedVar(dispatcher->serialization_rules()) {
- inner_->SetVar(dispatcher->serialization_rules()->SendCallerOwned(
- var, inner_->GetStringPtrPtr()));
+ inner_->SetVar(dispatcher->serialization_rules()->SendCallerOwned(var));
}
// static
@@ -287,7 +252,7 @@
PP_Var ReceiveSerializedVarReturnValue::Return(Dispatcher* dispatcher) {
inner_->set_serialization_rules(dispatcher->serialization_rules());
inner_->SetVar(inner_->serialization_rules()->ReceivePassRef(
- inner_->GetIncompleteVar(), inner_->GetStringDestructive(), dispatcher));
+ inner_->GetVar(), dispatcher));
return inner_->GetVar();
}
@@ -305,10 +270,8 @@
// When an output exception is specified, it will take ownership of the
// reference.
inner_->SetVar(
- inner_->serialization_rules()->ReceivePassRef(
- inner_->GetIncompleteVar(),
- inner_->GetStringDestructive(),
- dispatcher_));
+ inner_->serialization_rules()->ReceivePassRef(inner_->GetVar(),
+ dispatcher_));
*exception_ = inner_->GetVar();
} else {
// When no output exception is specified, the browser thinks we have a ref
@@ -381,8 +344,7 @@
serialized_.inner_->SetVar(
serialized_.inner_->serialization_rules()->BeginReceiveCallerOwned(
- serialized_.inner_->GetIncompleteVar(),
- serialized_.inner_->GetStringDestructive(),
+ serialized_.inner_->GetVar(),
dispatcher));
return serialized_.inner_->GetVar();
}
@@ -412,8 +374,7 @@
serialized_[i].inner_->SetVar(
serialized_[i].inner_->serialization_rules()->BeginReceiveCallerOwned(
- serialized_[i].inner_->GetIncompleteVar(),
- serialized_[i].inner_->GetStringDestructive(),
+ serialized_[i].inner_->GetVar(),
dispatcher));
deserialized_[i] = serialized_[i].inner_->GetVar();
}
@@ -437,9 +398,7 @@
serialized_->inner_->SetCleanupModeToEndSendPassRef(dispatcher);
serialized_->inner_->SetVar(
- dispatcher->serialization_rules()->BeginSendPassRef(
- var,
- serialized_->inner_->GetStringPtrPtr()));
+ dispatcher->serialization_rules()->BeginSendPassRef(var));
}
// static
@@ -466,7 +425,7 @@
// in that case.
serialized_->inner_->SetVar(
serialized_->inner_->serialization_rules()->BeginSendPassRef(
- writable_var_, serialized_->inner_->GetStringPtrPtr()));
+ writable_var_));
// Normally the current object will be created on the stack to wrap a
// SerializedVar and won't have a scope around the actual IPC send. So we
@@ -526,14 +485,10 @@
SerializedVarTestConstructor::SerializedVarTestConstructor(
const std::string& str) {
- PP_Var string_var = {};
- string_var.type = PP_VARTYPE_STRING;
- string_var.value.as_id = 0;
- inner_->ForceSetVarValueForTest(string_var);
- inner_->ForceSetStringValueForTest(str);
+ inner_->ForceSetVarValueForTest(StringVar::StringToPPVar(str));
}
-SerializedVarTestReader::SerializedVarTestReader(const SerializedVar& var)
+SerializedVarTestReader::SerializedVarTestReader(const SerializedVar& var)
: SerializedVar(var) {
}
diff --git a/ppapi/proxy/serialized_var.h b/ppapi/proxy/serialized_var.h
index 1ad218d..28b7c8b 100644
--- a/ppapi/proxy/serialized_var.h
+++ b/ppapi/proxy/serialized_var.h
@@ -99,21 +99,11 @@
// See outer class's declarations above.
PP_Var GetVar() const;
- PP_Var GetIncompleteVar() const;
void SetVar(PP_Var var);
- void SetString(scoped_ptr<std::string> str);
- // Return a new string with the contents of the string referenced by Inner.
- // The string referenced by the Inner will be empty after this.
- scoped_ptr<std::string> GetStringDestructive();
- // Return a pointer to our internal string pointer. This is so that the
- // caller will be able to make this Inner point to a string that's owned
- // elsewhere (i.e., in the tracker).
- const std::string** GetStringPtrPtr();
-
- // For the SerializedVarTestConstructor, this writes the Var value as if
- // it was just received off the wire, without any serialization rules.
+
+ // For the SerializedVarTestConstructor, this writes the Var value as if
+ // it was just received off the wire, without any serialization rules.
void ForceSetVarValueForTest(PP_Var value);
- void ForceSetStringValueForTest(const std::string& str);
void WriteToMessage(IPC::Message* m) const;
bool ReadFromMessage(const IPC::Message* m, void** iter);
@@ -152,18 +142,6 @@
// a string ID. Before this, the as_id will be 0 for VARTYPE_STRING.
PP_Var var_;
- // If valid, this is a pointer to a string owned by the VarTracker. When our
- // outer SerializedVar gets serialized, it will write the string directly
- // from the tracker so we do not need to make any unnecessary copies. This
- // should only be valid on the sender side.
- const std::string* tracker_string_ptr_;
-
- // If valid, this is a string received from IPC which needs to be inserted
- // in to the var tracker. When we provide it to the tracker, we pass
- // ownership so that there are no unnecessary copies. This should only ever
- // be valid on the receiver side.
- scoped_ptr<std::string> string_from_ipc_;
-
CleanupMode cleanup_mode_;
// The dispatcher saved for the call to EndSendPassRef for the cleanup.
@@ -464,11 +442,7 @@
// The "incomplete" var is the one sent over the wire. Strings and object
// IDs have not yet been converted, so this is the thing that tests will
// actually want to check.
- PP_Var GetIncompleteVar() const { return inner_->GetIncompleteVar(); }
-
- const std::string* GetTrackerStringPtr() const {
- return *inner_->GetStringPtrPtr();
- }
+ PP_Var GetVar() const { return inner_->GetVar(); }
};
} // namespace proxy
diff --git a/ppapi/proxy/serialized_var_unittest.cc b/ppapi/proxy/serialized_var_unittest.cc
index 1ad9348..e7c690c6 100644
--- a/ppapi/proxy/serialized_var_unittest.cc
+++ b/ppapi/proxy/serialized_var_unittest.cc
@@ -59,7 +59,7 @@
// object ID. Nothing in the var tracker should have changed yet, and no
// messages should have been sent.
SerializedVarTestReader reader(sv);
- EXPECT_EQ(host_object.value.as_id, reader.GetIncompleteVar().value.as_id);
+ EXPECT_EQ(host_object.value.as_id, reader.GetVar().value.as_id);
EXPECT_EQ(1, var_tracker().GetRefCountForObject(plugin_object));
EXPECT_EQ(1u, sink().message_count());
}
@@ -105,7 +105,7 @@
// the var tracker should have changed yet, and no messages should have been
// sent.
SerializedVarTestReader reader(sv);
- EXPECT_EQ(kTestString, *reader.GetTrackerStringPtr());
+ //EXPECT_EQ(kTestString, *reader.GetTrackerStringPtr());
EXPECT_EQ(2, var_tracker().GetRefCountForObject(plugin_string));
EXPECT_EQ(0u, sink().message_count());
}
@@ -138,7 +138,7 @@
// object ID. Nothing in the var tracker should have changed yet, and no
// messages should have been sent.
SerializedVarTestReader reader(sv);
- EXPECT_EQ(host_object.value.as_id, reader.GetIncompleteVar().value.as_id);
+ EXPECT_EQ(host_object.value.as_id, reader.GetVar().value.as_id);
EXPECT_EQ(1, var_tracker().GetRefCountForObject(plugin_object));
EXPECT_EQ(0u, sink().message_count());
}
diff --git a/ppapi/proxy/var_serialization_rules.h b/ppapi/proxy/var_serialization_rules.h
index 92d0db8..bfedb061 100644
--- a/ppapi/proxy/var_serialization_rules.h
+++ b/ppapi/proxy/var_serialization_rules.h
@@ -28,24 +28,17 @@
// argument. The caller has a reference to the var, and the caller is
// responsible for freeing that reference.
- // Prepares the given var for sending to the remote process. If the var is a
- // string, *str_ptr_out will be set to point to the string in the tracker
- // referenced by var. If the var is not a string, *str_ptr_out will be
- // untouched and may be NULL. For object vars, the returned var will contain
- // the id valid for the host process. Otherwise, the returned var is valid in
- // the local process.
- virtual PP_Var SendCallerOwned(const PP_Var& var,
- const std::string** str_ptr_out) = 0;
+ // Prepares the given var for sending to the remote process. For object vars,
+ // the returned var will contain the id valid for the host process.
+ // Otherwise, the returned var is valid in the local process.
+ virtual PP_Var SendCallerOwned(const PP_Var& var) = 0;
// When receiving a caller-owned variable, normally we don't have to do
// anything. However, in the case of strings, we need to deserialize the
- // string from IPC, create a new PP_Var string in the local process, call the
- // function, and then destroy the temporary string. These two functions
- // handle that process.
+ // string from IPC, call the function, and then destroy the temporary string.
+ // These two functions handle that process.
//
- // BeginReceiveCallerOwned takes a var from IPC and an optional pointer to
- // the deserialized string (which will be used only when var is a
- // VARTYPE_STRING and may be NULL otherwise) and returns a new var
+ // BeginReceiveCallerOwned takes a var from IPC and returns a new var
// representing the input in the local process.
//
// EndReceiveCallerOwned releases the reference count in the Var tracker for
@@ -53,7 +46,6 @@
// took a reference to the Var, it will remain in the tracker after
// EndReceiveCallerOwned).
virtual PP_Var BeginReceiveCallerOwned(const PP_Var& var,
- scoped_ptr<std::string> str,
Dispatcher* dispatcher) = 0;
virtual void EndReceiveCallerOwned(const PP_Var& var) = 0;
@@ -68,24 +60,21 @@
// return value).
// Creates a var in the context of the local process from the given
- // deserialized var and deserialized string (which will be used only when var
- // is a VARTYPE_STRING and may be NULL otherwise). The input var/string
- // should be the result of calling SendPassRef in the remote process. The
- // return value is the var valid in the host process for object vars.
- // Otherwise, the return value is a var which is valid in the local process.
+ // deserialized var. The input var should be the result of calling
+ // SendPassRef in the remote process. The return value is the var valid in
+ // the host process for object vars. Otherwise, the return value is a var
+ // which is valid in the local process.
virtual PP_Var ReceivePassRef(const PP_Var& var,
- scoped_ptr<std::string> str,
Dispatcher* dispatcher) = 0;
// Prepares a var to be sent to the remote side. One local reference will
// be passed to the remote side. Call Begin* before doing the send and End*
- // after doing the send. See SendCallerOwned for a description of the string.
+ // after doing the send
//
// For object vars, the return value from BeginSendPassRef will be the var
// valid for the host process. Otherwise, it is a var that is valid in the
// local process. This same var must be passed to EndSendPassRef.
- virtual PP_Var BeginSendPassRef(const PP_Var& var,
- const std::string** str_ptr_out) = 0;
+ virtual PP_Var BeginSendPassRef(const PP_Var& var) = 0;
virtual void EndSendPassRef(const PP_Var& var, Dispatcher* dispatcher) = 0;
// ---------------------------------------------------------------------------
diff --git a/ppapi/shared_impl/var.cc b/ppapi/shared_impl/var.cc
index d7b0dac..da7a2cb 100644
--- a/ppapi/shared_impl/var.cc
+++ b/ppapi/shared_impl/var.cc
@@ -113,6 +113,9 @@
// StringVar -------------------------------------------------------------------
+StringVar::StringVar() {
+}
+
StringVar::StringVar(const std::string& str)
: value_(str) {
}
@@ -124,11 +127,6 @@
StringVar::~StringVar() {
}
-StringVar::StringVar(scoped_ptr<std::string> str) {
- // Swap the given string's contents in to value to avoid copying.
- str->swap(value_);
-}
-
StringVar* StringVar::AsStringVar() {
return this;
}
@@ -151,17 +149,6 @@
}
// static
-PP_Var StringVar::StringToPPVar(scoped_ptr<std::string> str) {
- DCHECK(str.get());
- if (!str.get())
- return PP_MakeNull();
- scoped_refptr<StringVar> str_var(new StringVar(str.Pass()));
- if (!str_var || !IsStringUTF8(str_var->value()))
- return PP_MakeNull();
- return str_var->GetPPVar();
-}
-
-// static
StringVar* StringVar::FromPPVar(PP_Var var) {
if (var.type != PP_VARTYPE_STRING)
return NULL;
@@ -172,6 +159,13 @@
return var_object->AsStringVar();
}
+// static
+PP_Var StringVar::SwapValidatedUTF8StringIntoPPVar(std::string* src) {
+ scoped_refptr<StringVar> str(new StringVar);
+ str->value_.swap(*src);
+ return str->GetPPVar();
+}
+
// ArrayBufferVar --------------------------------------------------------------
ArrayBufferVar::ArrayBufferVar() {
diff --git a/ppapi/shared_impl/var.h b/ppapi/shared_impl/var.h
index ed7f4f1..d8084d7 100644
--- a/ppapi/shared_impl/var.h
+++ b/ppapi/shared_impl/var.h
@@ -94,7 +94,6 @@
public:
StringVar(const std::string& str);
StringVar(const char* str, uint32 len);
- StringVar(scoped_ptr<std::string> str);
virtual ~StringVar();
const std::string& value() const { return value_; }
@@ -117,13 +116,19 @@
// create a StringVar and return the reference to it in the var.
static PP_Var StringToPPVar(const std::string& str);
static PP_Var StringToPPVar(const char* str, uint32 len);
- static PP_Var StringToPPVar(scoped_ptr<std::string> str);
+
+ // Same as StringToPPVar but avoids a copy by destructively swapping the
+ // given string into the newly created StringVar. The string must already be
+ // valid UTF-8. After the call, *src will be empty.
+ static PP_Var SwapValidatedUTF8StringIntoPPVar(std::string* src);
// Helper function that converts a PP_Var to a string. This will return NULL
// if the PP_Var is not of string type or the string is invalid.
static StringVar* FromPPVar(PP_Var var);
private:
+ StringVar(); // Makes an empty string.
+
std::string value_;
DISALLOW_COPY_AND_ASSIGN(StringVar);