OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/api/sockets_udp/sockets_udp_api.h" | 5 #include "extensions/browser/api/sockets_udp/sockets_udp_api.h" |
6 | 6 |
7 #include "content/public/common/socket_permission_request.h" | 7 #include "content/public/common/socket_permission_request.h" |
8 #include "extensions/browser/api/socket/udp_socket.h" | 8 #include "extensions/browser/api/socket/udp_socket.h" |
9 #include "extensions/browser/api/sockets_udp/udp_socket_event_dispatcher.h" | 9 #include "extensions/browser/api/sockets_udp/udp_socket_event_dispatcher.h" |
10 #include "extensions/common/api/sockets/sockets_manifest_data.h" | 10 #include "extensions/common/api/sockets/sockets_manifest_data.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 new std::string(localAddress.ToStringWithoutPort())); | 68 new std::string(localAddress.ToStringWithoutPort())); |
69 socket_info.local_port.reset(new int(localAddress.port())); | 69 socket_info.local_port.reset(new int(localAddress.port())); |
70 } | 70 } |
71 | 71 |
72 return socket_info; | 72 return socket_info; |
73 } | 73 } |
74 | 74 |
75 void SetSocketProperties(ResumableUDPSocket* socket, | 75 void SetSocketProperties(ResumableUDPSocket* socket, |
76 sockets_udp::SocketProperties* properties) { | 76 sockets_udp::SocketProperties* properties) { |
77 if (properties->name.get()) { | 77 if (properties->name.get()) { |
78 socket->set_name(*properties->name.get()); | 78 socket->set_name(*properties->name); |
79 } | 79 } |
80 if (properties->persistent.get()) { | 80 if (properties->persistent.get()) { |
81 socket->set_persistent(*properties->persistent.get()); | 81 socket->set_persistent(*properties->persistent); |
82 } | 82 } |
83 if (properties->buffer_size.get()) { | 83 if (properties->buffer_size.get()) { |
84 socket->set_buffer_size(*properties->buffer_size.get()); | 84 socket->set_buffer_size(*properties->buffer_size); |
85 } | 85 } |
86 } | 86 } |
87 | 87 |
88 SocketsUdpCreateFunction::SocketsUdpCreateFunction() {} | 88 SocketsUdpCreateFunction::SocketsUdpCreateFunction() {} |
89 | 89 |
90 SocketsUdpCreateFunction::~SocketsUdpCreateFunction() {} | 90 SocketsUdpCreateFunction::~SocketsUdpCreateFunction() {} |
91 | 91 |
92 bool SocketsUdpCreateFunction::Prepare() { | 92 bool SocketsUdpCreateFunction::Prepare() { |
93 params_ = sockets_udp::Create::Params::Create(*args_); | 93 params_ = sockets_udp::Create::Params::Create(*args_); |
94 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 94 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
95 return true; | 95 return true; |
96 } | 96 } |
97 | 97 |
98 void SocketsUdpCreateFunction::Work() { | 98 void SocketsUdpCreateFunction::Work() { |
99 ResumableUDPSocket* socket = new ResumableUDPSocket(extension_->id()); | 99 ResumableUDPSocket* socket = new ResumableUDPSocket(extension_->id()); |
100 | 100 |
101 sockets_udp::SocketProperties* properties = params_.get()->properties.get(); | 101 sockets_udp::SocketProperties* properties = params_->properties.get(); |
102 if (properties) { | 102 if (properties) { |
103 SetSocketProperties(socket, properties); | 103 SetSocketProperties(socket, properties); |
104 } | 104 } |
105 | 105 |
106 sockets_udp::CreateInfo create_info; | 106 sockets_udp::CreateInfo create_info; |
107 create_info.socket_id = AddSocket(socket); | 107 create_info.socket_id = AddSocket(socket); |
108 results_ = sockets_udp::Create::Results::Create(create_info); | 108 results_ = sockets_udp::Create::Results::Create(create_info); |
109 } | 109 } |
110 | 110 |
111 SocketsUdpUpdateFunction::SocketsUdpUpdateFunction() {} | 111 SocketsUdpUpdateFunction::SocketsUdpUpdateFunction() {} |
112 | 112 |
113 SocketsUdpUpdateFunction::~SocketsUdpUpdateFunction() {} | 113 SocketsUdpUpdateFunction::~SocketsUdpUpdateFunction() {} |
114 | 114 |
115 bool SocketsUdpUpdateFunction::Prepare() { | 115 bool SocketsUdpUpdateFunction::Prepare() { |
116 params_ = sockets_udp::Update::Params::Create(*args_); | 116 params_ = sockets_udp::Update::Params::Create(*args_); |
117 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 117 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
118 return true; | 118 return true; |
119 } | 119 } |
120 | 120 |
121 void SocketsUdpUpdateFunction::Work() { | 121 void SocketsUdpUpdateFunction::Work() { |
122 ResumableUDPSocket* socket = GetUdpSocket(params_->socket_id); | 122 ResumableUDPSocket* socket = GetUdpSocket(params_->socket_id); |
123 if (!socket) { | 123 if (!socket) { |
124 error_ = kSocketNotFoundError; | 124 error_ = kSocketNotFoundError; |
125 return; | 125 return; |
126 } | 126 } |
127 | 127 |
128 SetSocketProperties(socket, ¶ms_.get()->properties); | 128 SetSocketProperties(socket, ¶ms_->properties); |
129 results_ = sockets_udp::Update::Results::Create(); | 129 results_ = sockets_udp::Update::Results::Create(); |
130 } | 130 } |
131 | 131 |
132 SocketsUdpSetPausedFunction::SocketsUdpSetPausedFunction() | 132 SocketsUdpSetPausedFunction::SocketsUdpSetPausedFunction() |
133 : socket_event_dispatcher_(NULL) {} | 133 : socket_event_dispatcher_(NULL) {} |
134 | 134 |
135 SocketsUdpSetPausedFunction::~SocketsUdpSetPausedFunction() {} | 135 SocketsUdpSetPausedFunction::~SocketsUdpSetPausedFunction() {} |
136 | 136 |
137 bool SocketsUdpSetPausedFunction::Prepare() { | 137 bool SocketsUdpSetPausedFunction::Prepare() { |
138 params_ = api::sockets_udp::SetPaused::Params::Create(*args_); | 138 params_ = api::sockets_udp::SetPaused::Params::Create(*args_); |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 | 517 |
518 int net_result = socket->SetBroadcast(params_->enabled); | 518 int net_result = socket->SetBroadcast(params_->enabled); |
519 if (net_result != net::OK) { | 519 if (net_result != net::OK) { |
520 error_ = net::ErrorToString(net_result); | 520 error_ = net::ErrorToString(net_result); |
521 } | 521 } |
522 results_ = sockets_udp::SetBroadcast::Results::Create(net_result); | 522 results_ = sockets_udp::SetBroadcast::Results::Create(net_result); |
523 } | 523 } |
524 | 524 |
525 } // namespace api | 525 } // namespace api |
526 } // namespace extensions | 526 } // namespace extensions |
OLD | NEW |