Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ppapi / tests / extensions / multicast_permissions / test_multicast_permissions.cc
blob6f97378a9f7c943f671bd8171f76cb1f4d2bbdd6
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/cpp/udp_socket.h"
10 #include "ppapi/utility/completion_callback_factory.h"
12 namespace {
14 class MyInstance : public pp::Instance {
15 public:
16 explicit MyInstance(PP_Instance instance)
17 : pp::Instance(instance), udp_socket_(this), factory_(this) {}
18 virtual ~MyInstance() {}
20 void DidBindUDPSocket(int32_t result) {
21 // We should be able to bind the multicast socket with permission.
22 if (result != PP_OK)
23 PostMessage(result);
24 else
25 PostMessage("PASS");
28 void DidSetOptionUDPSocket(int32_t result) {
29 // We should be able to set the multicast option with permission.
30 if (result != PP_OK) {
31 PostMessage(result);
32 return;
35 PP_NetAddress_IPv4 ipv4_address = {80, {127, 0, 0, 1}};
36 pp::NetAddress address(this, ipv4_address);
37 udp_socket_.Bind(address,
38 factory_.NewCallback(&MyInstance::DidBindUDPSocket));
41 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) {
42 udp_socket_.SetOption(
43 PP_UDPSOCKET_OPTION_MULTICAST_LOOP, pp::Var(true),
44 factory_.NewCallback(&MyInstance::DidSetOptionUDPSocket));
45 return true;
48 private:
49 pp::UDPSocket udp_socket_;
50 pp::CompletionCallbackFactory<MyInstance> factory_;
53 class MyModule : public pp::Module {
54 public:
55 MyModule() : pp::Module() {}
56 virtual ~MyModule() {}
58 virtual pp::Instance* CreateInstance(PP_Instance instance) {
59 return new MyInstance(instance);
63 } // namespace
65 namespace pp {
67 Module* CreateModule() {
68 return new MyModule();
71 } // namespace pp