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 "content/browser/devtools/protocol/tethering_handler.h" | 5 #include "content/browser/devtools/protocol/tethering_handler.h" |
6 | 6 |
7 #include "content/public/browser/browser_thread.h" | 7 #include "content/public/browser/browser_thread.h" |
8 #include "net/base/io_buffer.h" | 8 #include "net/base/io_buffer.h" |
9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
10 #include "net/socket/server_socket.h" | 10 #include "net/socket/server_socket.h" |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 } | 322 } |
323 | 323 |
324 | 324 |
325 // TetheringHandler ---------------------------------------------------------- | 325 // TetheringHandler ---------------------------------------------------------- |
326 | 326 |
327 // static | 327 // static |
328 TetheringHandler::TetheringImpl* TetheringHandler::impl_ = nullptr; | 328 TetheringHandler::TetheringImpl* TetheringHandler::impl_ = nullptr; |
329 | 329 |
330 TetheringHandler::TetheringHandler( | 330 TetheringHandler::TetheringHandler( |
331 const CreateServerSocketCallback& socket_callback, | 331 const CreateServerSocketCallback& socket_callback, |
332 scoped_refptr<base::MessageLoopProxy> message_loop_proxy) | 332 scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
333 : socket_callback_(socket_callback), | 333 : socket_callback_(socket_callback), |
334 message_loop_proxy_(message_loop_proxy), | 334 task_runner_(task_runner), |
335 is_active_(false), | 335 is_active_(false), |
336 weak_factory_(this) { | 336 weak_factory_(this) { |
337 } | 337 } |
338 | 338 |
339 TetheringHandler::~TetheringHandler() { | 339 TetheringHandler::~TetheringHandler() { |
340 if (is_active_) { | 340 if (is_active_) { |
341 message_loop_proxy_->DeleteSoon(FROM_HERE, impl_); | 341 task_runner_->DeleteSoon(FROM_HERE, impl_); |
342 impl_ = nullptr; | 342 impl_ = nullptr; |
343 } | 343 } |
344 } | 344 } |
345 | 345 |
346 void TetheringHandler::SetClient(scoped_ptr<Client> client) { | 346 void TetheringHandler::SetClient(scoped_ptr<Client> client) { |
347 client_.swap(client); | 347 client_.swap(client); |
348 } | 348 } |
349 | 349 |
350 void TetheringHandler::Accepted(uint16 port, const std::string& name) { | 350 void TetheringHandler::Accepted(uint16 port, const std::string& name) { |
351 client_->Accepted(AcceptedParams::Create()->set_port(port) | 351 client_->Accepted(AcceptedParams::Create()->set_port(port) |
(...skipping 11 matching lines...) Expand all Loading... |
363 } | 363 } |
364 | 364 |
365 Response TetheringHandler::Bind(DevToolsCommandId command_id, int port) { | 365 Response TetheringHandler::Bind(DevToolsCommandId command_id, int port) { |
366 if (port < kMinTetheringPort || port > kMaxTetheringPort) | 366 if (port < kMinTetheringPort || port > kMaxTetheringPort) |
367 return Response::InvalidParams("port"); | 367 return Response::InvalidParams("port"); |
368 | 368 |
369 if (!Activate()) | 369 if (!Activate()) |
370 return Response::ServerError("Tethering is used by another connection"); | 370 return Response::ServerError("Tethering is used by another connection"); |
371 | 371 |
372 DCHECK(impl_); | 372 DCHECK(impl_); |
373 message_loop_proxy_->PostTask( | 373 task_runner_->PostTask( |
374 FROM_HERE, | 374 FROM_HERE, base::Bind(&TetheringImpl::Bind, base::Unretained(impl_), |
375 base::Bind(&TetheringImpl::Bind, base::Unretained(impl_), | 375 command_id, port)); |
376 command_id, port)); | |
377 return Response::OK(); | 376 return Response::OK(); |
378 } | 377 } |
379 | 378 |
380 Response TetheringHandler::Unbind(DevToolsCommandId command_id, int port) { | 379 Response TetheringHandler::Unbind(DevToolsCommandId command_id, int port) { |
381 if (!Activate()) | 380 if (!Activate()) |
382 return Response::ServerError("Tethering is used by another connection"); | 381 return Response::ServerError("Tethering is used by another connection"); |
383 | 382 |
384 DCHECK(impl_); | 383 DCHECK(impl_); |
385 message_loop_proxy_->PostTask( | 384 task_runner_->PostTask( |
386 FROM_HERE, | 385 FROM_HERE, base::Bind(&TetheringImpl::Unbind, base::Unretained(impl_), |
387 base::Bind(&TetheringImpl::Unbind, base::Unretained(impl_), | 386 command_id, port)); |
388 command_id, port)); | |
389 return Response::OK(); | 387 return Response::OK(); |
390 } | 388 } |
391 | 389 |
392 void TetheringHandler::SendBindSuccess(DevToolsCommandId command_id) { | 390 void TetheringHandler::SendBindSuccess(DevToolsCommandId command_id) { |
393 client_->SendBindResponse(command_id, BindResponse::Create()); | 391 client_->SendBindResponse(command_id, BindResponse::Create()); |
394 } | 392 } |
395 | 393 |
396 void TetheringHandler::SendUnbindSuccess(DevToolsCommandId command_id) { | 394 void TetheringHandler::SendUnbindSuccess(DevToolsCommandId command_id) { |
397 client_->SendUnbindResponse(command_id, UnbindResponse::Create()); | 395 client_->SendUnbindResponse(command_id, UnbindResponse::Create()); |
398 } | 396 } |
399 | 397 |
400 void TetheringHandler::SendInternalError(DevToolsCommandId command_id, | 398 void TetheringHandler::SendInternalError(DevToolsCommandId command_id, |
401 const std::string& message) { | 399 const std::string& message) { |
402 client_->SendError(command_id, Response::InternalError(message)); | 400 client_->SendError(command_id, Response::InternalError(message)); |
403 } | 401 } |
404 | 402 |
405 } // namespace tethering | 403 } // namespace tethering |
406 } // namespace devtools | 404 } // namespace devtools |
407 } // namespace content | 405 } // namespace content |
OLD | NEW |