Reland "Non-SFI mode: Switch to newlib. (patchset #4 id:60001 of https://codereview...
[chromium-blink-merge.git] / ppapi / tests / extensions / socket_permissions / test_socket_permissions.cc
blobf92a5c2b5836b96020d16030397639846f243747
1 // Copyright 2015 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.
5 #include "ppapi/cpp/completion_callback.h"
6 #include "ppapi/cpp/instance.h"
7 #include "ppapi/cpp/module.h"
8 #include "ppapi/cpp/tcp_socket.h"
9 #include "ppapi/utility/completion_callback_factory.h"
11 namespace {
13 class MyInstance : public pp::Instance {
14 public:
15 explicit MyInstance(PP_Instance instance)
16 : pp::Instance(instance), socket_(this), factory_(this) { }
17 virtual ~MyInstance() { }
19 void DidBindSocket(int32_t result) {
20 if (result == PP_OK)
21 PostMessage("PASS");
22 else
23 PostMessage(result);
26 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) {
27 PP_NetAddress_IPv4 ipv4_address = {80, {127, 0, 0, 1} };
28 pp::NetAddress address(this, ipv4_address);
29 socket_.Bind(address, factory_.NewCallback(&MyInstance::DidBindSocket));
30 return true;
33 private:
34 pp::TCPSocket socket_;
35 pp::CompletionCallbackFactory<MyInstance> factory_;
38 class MyModule : public pp::Module {
39 public:
40 MyModule() : pp::Module() { }
41 virtual ~MyModule() { }
43 virtual pp::Instance* CreateInstance(PP_Instance instance) {
44 return new MyInstance(instance);
48 } // namespace
50 namespace pp {
52 Module* CreateModule() {
53 return new MyModule();
56 } // namespace pp