summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-15 21:27:33 +0000
committersergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-15 21:27:33 +0000
commit88272c9dd354633f5948da0818407d2530deecca (patch)
tree264831d28d683b9348d20bb7d2954408bdd00f6e
parentdb0a8ec1f7d23bb4eb68b02318f1fec45bf2e00f (diff)
downloadchromium_src-88272c9dd354633f5948da0818407d2530deecca.zip
chromium_src-88272c9dd354633f5948da0818407d2530deecca.tar.gz
chromium_src-88272c9dd354633f5948da0818407d2530deecca.tar.bz2
Revert 75003 - Basic implementation of Pepper Transport API.
BUG=None TEST=Unittests Review URL: http://codereview.chromium.org/6478018 TBR=sergeyu@chromium.org Review URL: http://codereview.chromium.org/6480086 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75010 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/test/ui/ppapi_uitest.cc4
-rw-r--r--ppapi/c/dev/ppb_transport_dev.h34
-rw-r--r--ppapi/cpp/dev/transport_dev.cc59
-rw-r--r--ppapi/cpp/dev/transport_dev.h16
-rw-r--r--ppapi/tests/test_transport.cc41
-rw-r--r--ppapi/tests/test_transport.h10
-rw-r--r--webkit/glue/webkit_glue.gypi2
-rw-r--r--webkit/plugins/ppapi/ppb_transport_impl.cc278
-rw-r--r--webkit/plugins/ppapi/ppb_transport_impl.h59
9 files changed, 118 insertions, 385 deletions
diff --git a/chrome/test/ui/ppapi_uitest.cc b/chrome/test/ui/ppapi_uitest.cc
index db0e94d..6c7d884 100644
--- a/chrome/test/ui/ppapi_uitest.cc
+++ b/chrome/test/ui/ppapi_uitest.cc
@@ -166,7 +166,3 @@ TEST_F(PPAPITest, FileRef) {
TEST_F(PPAPITest, DISABLED_DirectoryReader) {
RunTestViaHTTP("DirectoryReader");
}
-
-TEST_F(PPAPITest, DISABLED_Transport) {
- RunTest("Transport");
-}
diff --git a/ppapi/c/dev/ppb_transport_dev.h b/ppapi/c/dev/ppb_transport_dev.h
index 72ebb67..7dc9ad3 100644
--- a/ppapi/c/dev/ppb_transport_dev.h
+++ b/ppapi/c/dev/ppb_transport_dev.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2011 The Chromium Authors. All rights reserved.
+/* Copyright (c) 2010 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -16,8 +16,8 @@
#define PPB_TRANSPORT_DEV_INTERFACE "PPB_Transport;0.4"
struct PPB_Transport_Dev {
- // Creates a new transport object with the specified name using the
- // specified protocol.
+ // Creates a new transport object with the specified name
+ // using the specified protocol.
PP_Resource (*CreateTransport)(PP_Instance instance,
const char* name,
const char* proto);
@@ -25,24 +25,23 @@ struct PPB_Transport_Dev {
// Returns PP_TRUE if resource is a Transport, PP_FALSE otherwise.
PP_Bool (*IsTransport)(PP_Resource resource);
- // Returns PP_TRUE if the transport is currently writable (i.e. can
- // send data to the remote peer), PP_FALSE otherwise.
+ // Returns PP_TRUE if the transport is currently writable
+ // (i.e. can send data to the remote peer), PP_FALSE otherwise.
PP_Bool (*IsWritable)(PP_Resource transport);
// TODO(juberti): other getters/setters
// connect state
// connect type, protocol
// RTT
- // Establishes a connection to the remote peer. Returns
- // PP_ERROR_WOULDBLOCK and notifies on |cb| when connectivity is
- // established (or timeout occurs).
+ // Establishes a connection to the remote peer.
+ // Returns PP_ERROR_WOULDBLOCK and notifies on |cb|
+ // when connectivity is established (or timeout occurs).
int32_t (*Connect)(PP_Resource transport,
struct PP_CompletionCallback cb);
- // Obtains another ICE candidate address to be provided to the
- // remote peer. Returns PP_ERROR_WOULDBLOCK if there are no more
- // addresses to be sent. After the callback is called
- // GetNextAddress() must be called again to get the address.
+ // Obtains another ICE candidate address to be provided
+ // to the remote peer. Returns PP_ERROR_WOULDBLOCK
+ // if there are no more addresses to be sent.
int32_t (*GetNextAddress)(PP_Resource transport,
struct PP_Var* address,
struct PP_CompletionCallback cb);
@@ -51,16 +50,14 @@ struct PPB_Transport_Dev {
int32_t (*ReceiveRemoteAddress)(PP_Resource transport,
struct PP_Var address);
- // Like recv(), receives data. Returns PP_ERROR_WOULDBLOCK if there
- // is currently no data to receive. In that case, the |data| pointer
- // should remain valid until the callback is called.
+ // Like recv(), receives data. Returns PP_ERROR_WOULDBLOCK
+ // if there is currently no data to receive.
int32_t (*Recv)(PP_Resource transport,
void* data,
uint32_t len,
struct PP_CompletionCallback cb);
- // Like send(), sends data. Returns PP_ERROR_WOULDBLOCK if the
- // socket is currently flow-controlled. In that case, the |data|
- // pointer should remain valid until the callback is called.
+ // Like send(), sends data. Returns PP_ERROR_WOULDBLOCK
+ // if the socket is currently flow-controlled.
int32_t (*Send)(PP_Resource transport,
const void* data,
uint32_t len,
@@ -71,3 +68,4 @@ struct PPB_Transport_Dev {
};
#endif /* PPAPI_C_PPB_TRANSPORT_DEV_H_ */
+
diff --git a/ppapi/cpp/dev/transport_dev.cc b/ppapi/cpp/dev/transport_dev.cc
index 0b62829..241c3bd 100644
--- a/ppapi/cpp/dev/transport_dev.cc
+++ b/ppapi/cpp/dev/transport_dev.cc
@@ -1,15 +1,13 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ppapi/cpp/dev/transport_dev.h"
-#include "ppapi/c/pp_errors.h"
#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/resource.h"
#include "ppapi/cpp/module.h"
#include "ppapi/cpp/module_impl.h"
-#include "ppapi/cpp/var.h"
namespace pp {
@@ -29,58 +27,5 @@ Transport_Dev::Transport_Dev(Instance* instance,
instance->pp_instance(), name, proto));
}
-bool Transport_Dev::IsWritable() {
- if (!has_interface<PPB_Transport_Dev>())
- return false;
- return PPBoolToBool(
- get_interface<PPB_Transport_Dev>()->IsWritable(pp_resource()));
-}
-
-int32_t Transport_Dev::Connect(const CompletionCallback& cc) {
- if (!has_interface<PPB_Transport_Dev>())
- return PP_ERROR_NOINTERFACE;
- return get_interface<PPB_Transport_Dev>()->Connect(
- pp_resource(), cc.pp_completion_callback());
-}
-
-int32_t Transport_Dev::GetNextAddress(Var* address,
- const CompletionCallback& cc) {
- if (!has_interface<PPB_Transport_Dev>())
- return PP_ERROR_NOINTERFACE;
- PP_Var temp_address = PP_MakeUndefined();
- int32_t ret_val = get_interface<PPB_Transport_Dev>()->GetNextAddress(
- pp_resource(), &temp_address, cc.pp_completion_callback());
- *address = Var(Var::PassRef(), temp_address);
- return ret_val;
-}
-
-int32_t Transport_Dev::ReceiveRemoteAddress(const pp::Var& address) {
- if (!has_interface<PPB_Transport_Dev>())
- return PP_ERROR_NOINTERFACE;
- return get_interface<PPB_Transport_Dev>()->ReceiveRemoteAddress(
- pp_resource(), address.pp_var());
-}
-
-int32_t Transport_Dev::Recv(void* data, uint32_t len,
- const CompletionCallback& cc) {
- if (!has_interface<PPB_Transport_Dev>())
- return PP_ERROR_NOINTERFACE;
- return get_interface<PPB_Transport_Dev>()->Recv(
- pp_resource(), data, len, cc.pp_completion_callback());
-}
-
-int32_t Transport_Dev::Send(const void* data, uint32_t len,
- const CompletionCallback& cc) {
- if (!has_interface<PPB_Transport_Dev>())
- return PP_ERROR_NOINTERFACE;
- return get_interface<PPB_Transport_Dev>()->Send(
- pp_resource(), data, len, cc.pp_completion_callback());
-}
-
-int32_t Transport_Dev::Close() {
- if (!has_interface<PPB_Transport_Dev>())
- return PP_ERROR_NOINTERFACE;
- return get_interface<PPB_Transport_Dev>()->Close(pp_resource());
-}
-
} // namespace pp
+
diff --git a/ppapi/cpp/dev/transport_dev.h b/ppapi/cpp/dev/transport_dev.h
index d6ad56d..a03b232 100644
--- a/ppapi/cpp/dev/transport_dev.h
+++ b/ppapi/cpp/dev/transport_dev.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,29 +6,19 @@
#define PPAPI_CPP_DEV_TRANSPORT_DEV_H_
#include "ppapi/c/dev/ppb_transport_dev.h"
-#include "ppapi/cpp/completion_callback.h"
#include "ppapi/cpp/resource.h"
namespace pp {
class Instance;
-class Var;
class Transport_Dev : public Resource {
public:
+ Transport_Dev() {}
Transport_Dev(Instance* instance, const char* name, const char* proto);
-
- bool IsWritable();
- int32_t Connect(const CompletionCallback& cc);
- int32_t GetNextAddress(pp::Var* address, const CompletionCallback& cc);
- int32_t ReceiveRemoteAddress(const pp::Var& address);
- int32_t Recv(void* data, uint32_t len,
- const CompletionCallback& cc);
- int32_t Send(const void* data, uint32_t len,
- const CompletionCallback& cb);
- int32_t Close();
};
} // namespace pp
#endif // PPAPI_CPP_DEV_TRANSPORT_DEV_H_
+
diff --git a/ppapi/tests/test_transport.cc b/ppapi/tests/test_transport.cc
index f394a7d..bcb7552 100644
--- a/ppapi/tests/test_transport.cc
+++ b/ppapi/tests/test_transport.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -9,11 +9,11 @@
#include <string>
#include "ppapi/c/dev/ppb_testing_dev.h"
+#include "ppapi/c/dev/ppb_transport_dev.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/cpp/completion_callback.h"
#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/module.h"
-#include "ppapi/cpp/dev/transport_dev.h"
#include "ppapi/tests/test_utils.h"
#include "ppapi/tests/testing_instance.h"
@@ -26,42 +26,11 @@ bool TestTransport::Init() {
}
void TestTransport::RunTest() {
- RUN_TEST(Basics);
+ RUN_TEST(FirstTransport);
// TODO(juberti): more Transport tests here...
}
-std::string TestTransport::TestBasics() {
- pp::Transport_Dev transport1(instance_, "test", "");
- pp::Transport_Dev transport2(instance_, "test", "");
-
- TestCompletionCallback connect_cb1;
- TestCompletionCallback connect_cb2;
- ASSERT_EQ(transport1.Connect(connect_cb1), PP_ERROR_WOULDBLOCK);
- ASSERT_EQ(transport2.Connect(connect_cb2), PP_ERROR_WOULDBLOCK);
-
- pp::Var address1;
- pp::Var address2;
- TestCompletionCallback next_address_cb1;
- TestCompletionCallback next_address_cb2;
- ASSERT_EQ(transport1.GetNextAddress(&address1, next_address_cb1),
- PP_ERROR_WOULDBLOCK);
- ASSERT_EQ(transport2.GetNextAddress(&address2, next_address_cb2),
- PP_ERROR_WOULDBLOCK);
- ASSERT_EQ(next_address_cb1.WaitForResult(), 0);
- ASSERT_EQ(next_address_cb2.WaitForResult(), 0);
- ASSERT_EQ(transport1.GetNextAddress(&address1, next_address_cb1), PP_OK);
- ASSERT_EQ(transport2.GetNextAddress(&address2, next_address_cb2), PP_OK);
-
- ASSERT_EQ(transport1.ReceiveRemoteAddress(address2), 0);
- ASSERT_EQ(transport2.ReceiveRemoteAddress(address1), 0);
-
- ASSERT_EQ(connect_cb1.WaitForResult(), 0);
- ASSERT_EQ(connect_cb2.WaitForResult(), 0);
-
- ASSERT_TRUE(transport1.IsWritable());
- ASSERT_TRUE(transport2.IsWritable());
-
- // TODO(sergeyu): Verify that data can be sent/received.
-
+std::string TestTransport::TestFirstTransport() {
+ // TODO(juberti): actual test
PASS();
}
diff --git a/ppapi/tests/test_transport.h b/ppapi/tests/test_transport.h
index 43e4306..e52983a 100644
--- a/ppapi/tests/test_transport.h
+++ b/ppapi/tests/test_transport.h
@@ -1,9 +1,9 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef PPAPI_TESTS_TEST_TRANSPORT_H_
-#define PPAPI_TESTS_TEST_TRANSPORT_H_
+#ifndef PAPPI_TESTS_TEST_TRANSPORT_H_
+#define PAPPI_TESTS_TEST_TRANSPORT_H_
#include <string>
@@ -24,10 +24,10 @@ class TestTransport : public TestCase {
virtual void RunTest();
private:
- std::string TestBasics();
+ std::string TestFirstTransport();
// Used by the tests that access the C API directly.
const PPB_Transport_Dev* transport_interface_;
};
-#endif // PPAPI_TESTS_TEST_TRANSPORT_H_
+#endif // PAPPI_TESTS_TEST_TRANSPORT_H_
diff --git a/webkit/glue/webkit_glue.gypi b/webkit/glue/webkit_glue.gypi
index 7060ed2..2db2299 100644
--- a/webkit/glue/webkit_glue.gypi
+++ b/webkit/glue/webkit_glue.gypi
@@ -166,8 +166,6 @@
'<(DEPTH)/skia/skia.gyp:skia',
'<(DEPTH)/third_party/icu/icu.gyp:icui18n',
'<(DEPTH)/third_party/icu/icu.gyp:icuuc',
- '<(DEPTH)/third_party/libjingle/libjingle.gyp:libjingle',
- '<(DEPTH)/third_party/libjingle/libjingle.gyp:libjingle_p2p',
'<(DEPTH)/third_party/npapi/npapi.gyp:npapi',
'<(DEPTH)/ppapi/ppapi.gyp:ppapi_c',
'webkit_resources',
diff --git a/webkit/plugins/ppapi/ppb_transport_impl.cc b/webkit/plugins/ppapi/ppb_transport_impl.cc
index dead066..69139e7 100644
--- a/webkit/plugins/ppapi/ppb_transport_impl.cc
+++ b/webkit/plugins/ppapi/ppb_transport_impl.cc
@@ -1,87 +1,109 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "webkit/plugins/ppapi/ppb_transport_impl.h"
+#include "base/singleton.h"
+#include "base/threading/thread_local.h"
#include "ppapi/c/dev/ppb_transport_dev.h"
-#include "ppapi/c/pp_completion_callback.h"
-#include "ppapi/c/pp_errors.h"
-#include "third_party/libjingle/source/talk/p2p/base/p2ptransportchannel.h"
-#include "third_party/libjingle/source/talk/p2p/client/httpportallocator.h"
#include "webkit/plugins/ppapi/common.h"
#include "webkit/plugins/ppapi/plugin_module.h"
#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
-#include "webkit/plugins/ppapi/var.h"
namespace webkit {
namespace ppapi {
namespace {
-PP_Resource CreateTransport(PP_Instance instance_id, const char* name,
+// Creates a new transport object with the specified name
+// using the specified protocol.
+PP_Resource CreateTransport(PP_Instance instance,
+ const char* name,
const char* proto) {
- PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
- if (!instance)
- return 0;
-
- scoped_refptr<PPB_Transport_Impl> t(new PPB_Transport_Impl(instance));
- if (!t->Init(name, proto))
- return 0;
-
- return t->GetReference();
+ // TODO(juberti): implement me
+ PP_Resource p(0);
+ return p;
}
+// Returns whether or not resource is PPB_Transport_Impl
PP_Bool IsTransport(PP_Resource resource) {
- return BoolToPPBool(Resource::GetAs<PPB_Transport_Impl>(resource) != NULL);
+ return BoolToPPBool(!!Resource::GetAs<PPB_Transport_Impl>(resource));
}
-PP_Bool IsWritable(PP_Resource resource) {
- scoped_refptr<PPB_Transport_Impl> t(
- Resource::GetAs<PPB_Transport_Impl>(resource));
- return BoolToPPBool((t.get()) ? t->IsWritable() : false);
+// Returns whether the transport is currently writable
+// (i.e. can send data to the remote peer)
+PP_Bool IsWritable(PP_Resource transport) {
+ // TODO(juberti): impelement me
+ return PP_FALSE;
}
-int32_t Connect(PP_Resource resource, PP_CompletionCallback callback) {
- scoped_refptr<PPB_Transport_Impl> t(
- Resource::GetAs<PPB_Transport_Impl>(resource));
- return (t.get()) ? t->Connect(callback) : PP_ERROR_BADRESOURCE;
+
+// TODO(juberti): other getters/setters
+// connect state
+// connect type, protocol
+// RTT
+
+
+// Establishes a connection to the remote peer.
+// Returns PP_ERROR_WOULDBLOCK and notifies on |cb|
+// when connectivity is established (or timeout occurs).
+int32_t Connect(PP_Resource transport,
+ PP_CompletionCallback cb) {
+ // TODO(juberti): impelement me
+ return 0;
}
-int32_t GetNextAddress(PP_Resource resource, PP_Var* address,
- PP_CompletionCallback callback) {
- scoped_refptr<PPB_Transport_Impl> t(
- Resource::GetAs<PPB_Transport_Impl>(resource));
- return (t.get())? t->GetNextAddress(address, callback) : PP_ERROR_BADRESOURCE;
+
+// Obtains another ICE candidate address to be provided
+// to the remote peer. Returns PP_ERROR_WOULDBLOCK
+// if there are no more addresses to be sent.
+int32_t GetNextAddress(PP_Resource transport,
+ PP_Var* address,
+ PP_CompletionCallback cb) {
+ // TODO(juberti): implement me
+ return 0;
}
-int32_t ReceiveRemoteAddress(PP_Resource resource, PP_Var address) {
- scoped_refptr<PPB_Transport_Impl> t(
- Resource::GetAs<PPB_Transport_Impl>(resource));
- return (t.get())? t->ReceiveRemoteAddress(address) : PP_ERROR_BADRESOURCE;
+
+// Provides an ICE candidate address that was received
+// from the remote peer.
+int32_t ReceiveRemoteAddress(PP_Resource transport,
+ PP_Var address) {
+ // TODO(juberti): implement me
+ return 0;
}
-int32_t Recv(PP_Resource resource, void* data, uint32_t len,
- PP_CompletionCallback callback) {
- scoped_refptr<PPB_Transport_Impl> t(
- Resource::GetAs<PPB_Transport_Impl>(resource));
- return (t.get())? t->Recv(data, len, callback) : PP_ERROR_BADRESOURCE;
+
+// Like recv(), receives data. Returns PP_ERROR_WOULDBLOCK
+// if there is currently no data to receive.
+int32_t Recv(PP_Resource transport,
+ void* data,
+ uint32_t len,
+ PP_CompletionCallback cb) {
+ // TODO(juberti): implement me
+ return 0;
}
-int32_t Send(PP_Resource resource, const void* data, uint32_t len,
- PP_CompletionCallback callback) {
- scoped_refptr<PPB_Transport_Impl> t(
- Resource::GetAs<PPB_Transport_Impl>(resource));
- return (t.get())? t->Send(data, len, callback) : PP_ERROR_BADRESOURCE;
+
+// Like send(), sends data. Returns PP_ERROR_WOULDBLOCK
+// if the socket is currently flow-controlled.
+int32_t Send(PP_Resource transport,
+ const void* data,
+ uint32_t len,
+ PP_CompletionCallback cb) {
+ // TODO(juberti): implement me
+ return 0;
}
+
// Disconnects from the remote peer.
-int32_t Close(PP_Resource resource) {
- scoped_refptr<PPB_Transport_Impl> t(
- Resource::GetAs<PPB_Transport_Impl>(resource));
- return (t.get())? t->Close() : PP_ERROR_BADRESOURCE;
+int32_t Close(PP_Resource transport) {
+ // TODO(juberti): implement me
+ return 0;
}
+
const PPB_Transport_Dev ppb_transport = {
&CreateTransport,
&IsTransport,
@@ -97,171 +119,27 @@ const PPB_Transport_Dev ppb_transport = {
} // namespace
PPB_Transport_Impl::PPB_Transport_Impl(PluginInstance* instance)
- : Resource(instance),
- network_manager_(new talk_base::NetworkManager()),
- allocator_(new cricket::HttpPortAllocator(network_manager_.get(), "")) {
- std::vector<talk_base::SocketAddress> stun_hosts;
- stun_hosts.push_back(talk_base::SocketAddress("stun.l.google.com", 19302));
- allocator_->SetStunHosts(stun_hosts);
- // TODO(sergeyu): Use port allocator that works inside sandbox.
-}
-
-PPB_Transport_Impl::~PPB_Transport_Impl() {
+ : Resource(instance) {
+ // TODO(juberti): impl
}
const PPB_Transport_Dev* PPB_Transport_Impl::GetInterface() {
return &ppb_transport;
}
+PPB_Transport_Impl::~PPB_Transport_Impl() {
+ // TODO(juberti): teardown
+}
+
PPB_Transport_Impl* PPB_Transport_Impl::AsPPB_Transport_Impl() {
return this;
}
bool PPB_Transport_Impl::Init(const char* name, const char* proto) {
- // For now, always create http://www.google.com/transport/p2p .
- channel_.reset(new cricket::P2PTransportChannel(
- name, "", NULL, allocator_.get()));
- channel_->SignalRequestSignaling.connect(
- this, &PPB_Transport_Impl::OnRequestSignaling);
- channel_->SignalWritableState.connect(
- this, &PPB_Transport_Impl::OnWriteableState);
- channel_->SignalCandidateReady.connect(
- this, &PPB_Transport_Impl::OnCandidateReady);
- channel_->SignalReadPacket.connect(
- this, &PPB_Transport_Impl::OnReadPacket);
- return true;
-}
-
-bool PPB_Transport_Impl::IsWritable() const {
- return channel_->writable();
-}
-
-int32_t PPB_Transport_Impl::Connect(PP_CompletionCallback callback) {
- // TODO(juberti): Fail if we're already connected.
- if (connect_callback_.get() && !connect_callback_->completed())
- return PP_ERROR_INPROGRESS;
-
- channel_->Connect();
-
- PP_Resource resource_id = GetReferenceNoAddRef();
- CHECK(resource_id);
- connect_callback_ = new TrackedCompletionCallback(
- instance()->module()->GetCallbackTracker(), resource_id, callback);
- return PP_ERROR_WOULDBLOCK;
-}
-
-int32_t PPB_Transport_Impl::GetNextAddress(PP_Var* address,
- PP_CompletionCallback callback) {
- if (next_address_callback_.get() && !next_address_callback_->completed())
- return PP_ERROR_INPROGRESS;
-
- if (!local_candidates_.empty()) {
- Serialize(local_candidates_.front(), address);
- local_candidates_.pop_front();
- return PP_OK;
- }
-
- PP_Resource resource_id = GetReferenceNoAddRef();
- CHECK(resource_id);
- next_address_callback_ = new TrackedCompletionCallback(
- instance()->module()->GetCallbackTracker(), resource_id, callback);
- return PP_ERROR_WOULDBLOCK;
-}
-
-int32_t PPB_Transport_Impl::ReceiveRemoteAddress(PP_Var address) {
- cricket::Candidate candidate;
- if (!Deserialize(address, &candidate)) {
- return PP_ERROR_FAILED;
- }
-
- channel_->OnCandidate(candidate);
- return PP_OK;
-}
-
-int32_t PPB_Transport_Impl::Recv(void* data, uint32_t len,
- PP_CompletionCallback callback) {
- if (recv_callback_.get() && !recv_callback_->completed())
- return PP_ERROR_INPROGRESS;
-
- // TODO(juberti): Should we store packets that are received when
- // no callback is installed?
-
- recv_buffer_ = data;
- recv_buffer_size_ = len;
-
- PP_Resource resource_id = GetReferenceNoAddRef();
- CHECK(resource_id);
- recv_callback_ = new TrackedCompletionCallback(
- instance()->module()->GetCallbackTracker(), resource_id, callback);
- return PP_ERROR_WOULDBLOCK;
-}
-
-int32_t PPB_Transport_Impl::Send(const void* data, uint32_t len,
- PP_CompletionCallback callback) {
- return channel_->SendPacket(static_cast<const char*>(data), len);
-}
-
-int32_t PPB_Transport_Impl::Close() {
- channel_->Reset();
- instance()->module()->GetCallbackTracker()->AbortAll();
- return PP_OK;
-}
-
-void PPB_Transport_Impl::OnRequestSignaling() {
- channel_->OnSignalingReady();
-}
-
-void PPB_Transport_Impl::OnCandidateReady(
- cricket::TransportChannelImpl* channel,
- const cricket::Candidate& candidate) {
- // Store the candidate first before calling the callback.
- local_candidates_.push_back(candidate);
-
- if (next_address_callback_.get() && next_address_callback_->completed()) {
- scoped_refptr<TrackedCompletionCallback> callback;
- callback.swap(next_address_callback_);
- callback->Run(PP_OK);
- }
-}
-
-void PPB_Transport_Impl::OnWriteableState(cricket::TransportChannel* channel) {
- if (connect_callback_.get() && connect_callback_->completed()) {
- scoped_refptr<TrackedCompletionCallback> callback;
- callback.swap(connect_callback_);
- callback->Run(PP_OK);
- }
-}
-
-void PPB_Transport_Impl::OnReadPacket(cricket::TransportChannel* channel,
- const char* data, size_t len) {
- if (recv_callback_.get() && recv_callback_->completed()) {
- scoped_refptr<TrackedCompletionCallback> callback;
- callback.swap(recv_callback_);
-
- if (len <= recv_buffer_size_) {
- memcpy(recv_buffer_, data, len);
- callback->Run(PP_OK);
- } else {
- callback->Run(PP_ERROR_FAILED);
- }
- }
- // TODO(sergeyu): Buffer incoming packet if there is no pending read.
-}
-
-bool PPB_Transport_Impl::Serialize(const cricket::Candidate& candidate,
- PP_Var* address) {
- // TODO(juberti): Come up with a real wire format!
- std::string blob = candidate.ToString();
- Var::PluginReleasePPVar(*address);
- *address = StringVar::StringToPPVar(instance()->module(), blob);
- return true;
-}
-
-bool PPB_Transport_Impl::Deserialize(PP_Var address,
- cricket::Candidate* candidate) {
- // TODO(juberti): Implement this.
+ // TODO(juberti): impl
return false;
}
} // namespace ppapi
} // namespace webkit
+
diff --git a/webkit/plugins/ppapi/ppb_transport_impl.h b/webkit/plugins/ppapi/ppb_transport_impl.h
index e631ce6..96169c7 100644
--- a/webkit/plugins/ppapi/ppb_transport_impl.h
+++ b/webkit/plugins/ppapi/ppb_transport_impl.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,69 +7,27 @@
#include "base/basictypes.h"
#include "base/scoped_ptr.h"
-#include "ppapi/c/dev/ppb_transport_dev.h"
-#include "third_party/libjingle/source/talk/base/sigslot.h"
-#include "third_party/libjingle/source/talk/p2p/base/candidate.h"
-#include "webkit/plugins/ppapi/callbacks.h"
+#include "ppapi/c/pp_instance.h"
+#include "webkit/plugins/ppapi/plugin_delegate.h"
#include "webkit/plugins/ppapi/resource.h"
-namespace talk_base {
-class NetworkManager;
-} // namespace talk_base
-
-namespace cricket {
-class HttpPortAllocator;
-class P2PTransportChannel;
-class TransportChannel;
-class TransportChannelImpl;
-} // namespace cricket
+struct PPB_Transport_Dev;
namespace webkit {
namespace ppapi {
-class PPB_Transport_Impl : public Resource, public sigslot::has_slots<> {
+class PPB_Transport_Impl : public Resource {
public:
- static const PPB_Transport_Dev* GetInterface();
-
explicit PPB_Transport_Impl(PluginInstance* instance);
virtual ~PPB_Transport_Impl();
- bool Init(const char* name, const char* proto);
-
- // Resource override.
+ static const PPB_Transport_Dev* GetInterface();
virtual PPB_Transport_Impl* AsPPB_Transport_Impl();
- bool IsWritable() const;
- int32_t Connect(PP_CompletionCallback cb);
- int32_t GetNextAddress(PP_Var* address, PP_CompletionCallback cb);
- int32_t ReceiveRemoteAddress(PP_Var address);
- int32_t Recv(void* data, uint32_t len, PP_CompletionCallback cb);
- int32_t Send(const void* data, uint32_t len, PP_CompletionCallback cb);
- int32_t Close();
+ bool Init(const char* name,
+ const char* proto);
private:
- void OnRequestSignaling();
- void OnCandidateReady(cricket::TransportChannelImpl* channel,
- const cricket::Candidate& candidate);
- void OnWriteableState(cricket::TransportChannel*);
- void OnReadPacket(cricket::TransportChannel*, const char*, size_t);
-
- bool Serialize(const cricket::Candidate& candidate, PP_Var* address);
- bool Deserialize(PP_Var address, cricket::Candidate* candidate);
-
- scoped_ptr<talk_base::NetworkManager> network_manager_;
- scoped_ptr<cricket::HttpPortAllocator> allocator_;
- scoped_ptr<cricket::P2PTransportChannel> channel_;
- std::list<cricket::Candidate> local_candidates_;
-
- scoped_refptr<TrackedCompletionCallback> connect_callback_;
-
- scoped_refptr<TrackedCompletionCallback> next_address_callback_;
-
- scoped_refptr<TrackedCompletionCallback> recv_callback_;
- void* recv_buffer_;
- uint32_t recv_buffer_size_;
-
DISALLOW_COPY_AND_ASSIGN(PPB_Transport_Impl);
};
@@ -77,3 +35,4 @@ class PPB_Transport_Impl : public Resource, public sigslot::has_slots<> {
} // namespace webkit
#endif // WEBKIT_PLUGINS_PPAPI_PPB_TRANSPORT_IMPL_H_
+