OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ppapi/c/pp_errors.h" | 5 #include "ppapi/cpp/completion_callback.h" |
6 #include "ppapi/cpp/input_event.h" | |
7 #include "ppapi/cpp/instance.h" | 6 #include "ppapi/cpp/instance.h" |
8 #include "ppapi/cpp/module.h" | 7 #include "ppapi/cpp/module.h" |
| 8 #include "ppapi/cpp/tcp_socket.h" |
9 #include "ppapi/utility/completion_callback_factory.h" | 9 #include "ppapi/utility/completion_callback_factory.h" |
10 #include "ppapi/utility/threading/simple_thread.h" | 10 |
| 11 namespace { |
11 | 12 |
12 class MyInstance : public pp::Instance { | 13 class MyInstance : public pp::Instance { |
13 public: | 14 public: |
14 MyInstance(PP_Instance instance) : pp::Instance(instance) { | 15 explicit MyInstance(PP_Instance instance) |
15 thread_ = new pp::SimpleThread(this); | 16 : pp::Instance(instance), socket_(this), factory_(this) { } |
16 factory_.Initialize(this); | 17 virtual ~MyInstance() { } |
17 } | |
18 | 18 |
19 virtual ~MyInstance() { | 19 void DidBindSocket(int32_t result) { |
20 delete thread_; | 20 if (result == PP_OK) |
| 21 PostMessage("PASS"); |
| 22 else |
| 23 PostMessage(result); |
21 } | 24 } |
22 | 25 |
23 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) { | 26 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) { |
24 thread_->Start(); | 27 PP_NetAddress_IPv4 ipv4_address = {80, {127, 0, 0, 1} }; |
25 thread_->message_loop().PostWork( | 28 pp::NetAddress address(this, ipv4_address); |
26 factory_.NewCallback(&MyInstance::CallOnBackground)); | 29 socket_.Bind(address, factory_.NewCallback(&MyInstance::DidBindSocket)); |
27 return true; | 30 return true; |
28 } | 31 } |
29 | 32 |
30 virtual void DidChangeView(const pp::View& view) { | |
31 } | |
32 | |
33 private: | 33 private: |
34 void CallOnBackground(int32_t result) { | 34 pp::TCPSocket socket_; |
35 } | |
36 | |
37 pp::CompletionCallbackFactory<MyInstance> factory_; | 35 pp::CompletionCallbackFactory<MyInstance> factory_; |
38 | |
39 pp::SimpleThread* thread_; | |
40 }; | 36 }; |
41 | 37 |
42 | |
43 class MyModule : public pp::Module { | 38 class MyModule : public pp::Module { |
44 public: | 39 public: |
45 MyModule() : pp::Module() {} | 40 MyModule() : pp::Module() { } |
46 virtual ~MyModule() {} | 41 virtual ~MyModule() { } |
47 | 42 |
48 virtual pp::Instance* CreateInstance(PP_Instance instance) { | 43 virtual pp::Instance* CreateInstance(PP_Instance instance) { |
49 return new MyInstance(instance); | 44 return new MyInstance(instance); |
50 } | 45 } |
51 }; | 46 }; |
52 | 47 |
| 48 } // namespace |
| 49 |
53 namespace pp { | 50 namespace pp { |
54 | 51 |
55 // Factory function for your specialization of the Module object. | |
56 Module* CreateModule() { | 52 Module* CreateModule() { |
57 return new MyModule(); | 53 return new MyModule(); |
58 } | 54 } |
59 | 55 |
60 } // namespace pp | 56 } // namespace pp |
OLD | NEW |