| Index: ppapi/tests/extensions/socket_permissions/test_socket_permissions.cc
|
| diff --git a/ppapi/examples/threading/threading.cc b/ppapi/tests/extensions/socket_permissions/test_socket_permissions.cc
|
| similarity index 48%
|
| copy from ppapi/examples/threading/threading.cc
|
| copy to ppapi/tests/extensions/socket_permissions/test_socket_permissions.cc
|
| index bfd21a910619bcda70efe77df7f3cfb78244bb22..389a6cff908eb9d6158989dcd48b9c52bdbd8501 100644
|
| --- a/ppapi/examples/threading/threading.cc
|
| +++ b/ppapi/tests/extensions/socket_permissions/test_socket_permissions.cc
|
| @@ -1,58 +1,54 @@
|
| -// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Copyright 2015 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/c/pp_errors.h"
|
| -#include "ppapi/cpp/input_event.h"
|
| +#include "ppapi/cpp/completion_callback.h"
|
| #include "ppapi/cpp/instance.h"
|
| #include "ppapi/cpp/module.h"
|
| +#include "ppapi/cpp/tcp_socket.h"
|
| #include "ppapi/utility/completion_callback_factory.h"
|
| -#include "ppapi/utility/threading/simple_thread.h"
|
| +
|
| +namespace {
|
|
|
| class MyInstance : public pp::Instance {
|
| public:
|
| - MyInstance(PP_Instance instance) : pp::Instance(instance) {
|
| - thread_ = new pp::SimpleThread(this);
|
| - factory_.Initialize(this);
|
| - }
|
| -
|
| - virtual ~MyInstance() {
|
| - delete thread_;
|
| + explicit MyInstance(PP_Instance instance)
|
| + : pp::Instance(instance), socket_(this), factory_(this) { }
|
| + virtual ~MyInstance() { }
|
| +
|
| + void DidBindSocket(int32_t result) {
|
| + if (result == PP_OK)
|
| + PostMessage("hello");
|
| + else
|
| + PostMessage(result);
|
| }
|
|
|
| virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) {
|
| - thread_->Start();
|
| - thread_->message_loop().PostWork(
|
| - factory_.NewCallback(&MyInstance::CallOnBackground));
|
| + PP_NetAddress_IPv4 ipv4_address = {80, {127, 0, 0, 1} };
|
| + pp::NetAddress address(this, ipv4_address);
|
| + socket_.Bind(address, factory_.NewCallback(&MyInstance::DidBindSocket));
|
| return true;
|
| }
|
|
|
| - virtual void DidChangeView(const pp::View& view) {
|
| - }
|
| -
|
| private:
|
| - void CallOnBackground(int32_t result) {
|
| - }
|
| -
|
| + pp::TCPSocket socket_;
|
| pp::CompletionCallbackFactory<MyInstance> factory_;
|
| -
|
| - pp::SimpleThread* thread_;
|
| };
|
|
|
| -
|
| class MyModule : public pp::Module {
|
| public:
|
| - MyModule() : pp::Module() {}
|
| - virtual ~MyModule() {}
|
| + MyModule() : pp::Module() { }
|
| + virtual ~MyModule() { }
|
|
|
| virtual pp::Instance* CreateInstance(PP_Instance instance) {
|
| return new MyInstance(instance);
|
| }
|
| };
|
|
|
| +} // namespace
|
| +
|
| namespace pp {
|
|
|
| -// Factory function for your specialization of the Module object.
|
| Module* CreateModule() {
|
| return new MyModule();
|
| }
|
|
|