OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/android/dev_tools_server.h" | 5 #include "chrome/browser/android/dev_tools_server.h" |
6 | 6 |
7 #include <pwd.h> | 7 #include <pwd.h> |
8 #include <cstring> | 8 #include <cstring> |
9 | 9 |
10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 #include "content/public/browser/favicon_status.h" | 33 #include "content/public/browser/favicon_status.h" |
34 #include "content/public/browser/navigation_entry.h" | 34 #include "content/public/browser/navigation_entry.h" |
35 #include "content/public/browser/render_view_host.h" | 35 #include "content/public/browser/render_view_host.h" |
36 #include "content/public/browser/web_contents.h" | 36 #include "content/public/browser/web_contents.h" |
37 #include "content/public/browser/web_contents_delegate.h" | 37 #include "content/public/browser/web_contents_delegate.h" |
38 #include "content/public/common/content_switches.h" | 38 #include "content/public/common/content_switches.h" |
39 #include "content/public/common/url_constants.h" | 39 #include "content/public/common/url_constants.h" |
40 #include "content/public/common/user_agent.h" | 40 #include "content/public/common/user_agent.h" |
41 #include "grit/browser_resources.h" | 41 #include "grit/browser_resources.h" |
42 #include "jni/DevToolsServer_jni.h" | 42 #include "jni/DevToolsServer_jni.h" |
| 43 #include "net/base/net_errors.h" |
43 #include "net/socket/unix_domain_listen_socket_posix.h" | 44 #include "net/socket/unix_domain_listen_socket_posix.h" |
| 45 #include "net/socket/unix_domain_server_socket_posix.h" |
44 #include "net/url_request/url_request_context_getter.h" | 46 #include "net/url_request/url_request_context_getter.h" |
45 #include "ui/base/resource/resource_bundle.h" | 47 #include "ui/base/resource/resource_bundle.h" |
46 | 48 |
47 using content::DevToolsAgentHost; | 49 using content::DevToolsAgentHost; |
48 using content::RenderViewHost; | 50 using content::RenderViewHost; |
49 using content::WebContents; | 51 using content::WebContents; |
50 | 52 |
51 namespace { | 53 namespace { |
52 | 54 |
53 // TL;DR: Do not change this string. | 55 // TL;DR: Do not change this string. |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 history::TopSites* top_sites = profile->GetTopSites(); | 384 history::TopSites* top_sites = profile->GetTopSites(); |
383 if (top_sites) | 385 if (top_sites) |
384 top_sites->SyncWithHistory(); | 386 top_sites->SyncWithHistory(); |
385 } | 387 } |
386 | 388 |
387 int last_tethering_socket_; | 389 int last_tethering_socket_; |
388 | 390 |
389 DISALLOW_COPY_AND_ASSIGN(DevToolsServerDelegate); | 391 DISALLOW_COPY_AND_ASSIGN(DevToolsServerDelegate); |
390 }; | 392 }; |
391 | 393 |
| 394 // Factory for UnixDomainServerSocket. It tries a fallback socket when |
| 395 // original socket doesn't work. |
| 396 class UnixDomainServerSocketFactory |
| 397 : public content::DevToolsHttpHandler::ServerSocketFactory { |
| 398 public: |
| 399 explicit UnixDomainServerSocketFactory(const std::string& socket_name) |
| 400 : content::DevToolsHttpHandler::ServerSocketFactory(socket_name, 0, 1) {} |
| 401 |
| 402 private: |
| 403 // content::DevToolsHttpHandler::ServerSocketFactory. |
| 404 virtual scoped_ptr<net::ServerSocket> Create() const OVERRIDE { |
| 405 return scoped_ptr<net::ServerSocket>( |
| 406 new net::UnixDomainServerSocket( |
| 407 base::Bind(&content::CanUserConnectToDevTools), |
| 408 true)); |
| 409 } |
| 410 |
| 411 virtual scoped_ptr<net::ServerSocket> CreateAndListen() const OVERRIDE { |
| 412 scoped_ptr<net::ServerSocket> socket = Create(); |
| 413 if (!socket) |
| 414 return scoped_ptr<net::ServerSocket>(); |
| 415 |
| 416 if (socket->ListenWithAddressAndPort(address_, port_, backlog_) == net::OK) |
| 417 return socket.Pass(); |
| 418 |
| 419 // Tries a fallback socket name. |
| 420 const std::string fallback_address( |
| 421 base::StringPrintf("%s_%d", address_.c_str(), getpid())); |
| 422 if (socket->ListenWithAddressAndPort(fallback_address, port_, backlog_) |
| 423 == net::OK) |
| 424 return socket.Pass(); |
| 425 |
| 426 return scoped_ptr<net::ServerSocket>(); |
| 427 } |
| 428 |
| 429 DISALLOW_COPY_AND_ASSIGN(UnixDomainServerSocketFactory); |
| 430 }; |
| 431 |
392 } // namespace | 432 } // namespace |
393 | 433 |
394 DevToolsServer::DevToolsServer() | 434 DevToolsServer::DevToolsServer() |
395 : socket_name_(base::StringPrintf(kDevToolsChannelNameFormat, | 435 : socket_name_(base::StringPrintf(kDevToolsChannelNameFormat, |
396 kDefaultSocketNamePrefix)), | 436 kDefaultSocketNamePrefix)), |
397 protocol_handler_(NULL) { | 437 protocol_handler_(NULL) { |
398 // Override the default socket name if one is specified on the command line. | 438 // Override the default socket name if one is specified on the command line. |
399 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 439 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
400 if (command_line.HasSwitch(switches::kRemoteDebuggingSocketName)) { | 440 if (command_line.HasSwitch(switches::kRemoteDebuggingSocketName)) { |
401 socket_name_ = command_line.GetSwitchValueASCII( | 441 socket_name_ = command_line.GetSwitchValueASCII( |
(...skipping 14 matching lines...) Expand all Loading... |
416 } | 456 } |
417 | 457 |
418 DevToolsServer::~DevToolsServer() { | 458 DevToolsServer::~DevToolsServer() { |
419 Stop(); | 459 Stop(); |
420 } | 460 } |
421 | 461 |
422 void DevToolsServer::Start() { | 462 void DevToolsServer::Start() { |
423 if (protocol_handler_) | 463 if (protocol_handler_) |
424 return; | 464 return; |
425 | 465 |
| 466 scoped_ptr<content::DevToolsHttpHandler::ServerSocketFactory> factory( |
| 467 new UnixDomainServerSocketFactory(socket_name_)); |
426 protocol_handler_ = content::DevToolsHttpHandler::Start( | 468 protocol_handler_ = content::DevToolsHttpHandler::Start( |
427 new net::deprecated::UnixDomainListenSocketWithAbstractNamespaceFactory( | 469 factory.Pass(), |
428 socket_name_, | |
429 base::StringPrintf("%s_%d", socket_name_.c_str(), getpid()), | |
430 base::Bind(&content::CanUserConnectToDevTools)), | |
431 base::StringPrintf(kFrontEndURL, content::GetWebKitRevision().c_str()), | 470 base::StringPrintf(kFrontEndURL, content::GetWebKitRevision().c_str()), |
432 new DevToolsServerDelegate(), | 471 new DevToolsServerDelegate(), |
433 base::FilePath()); | 472 base::FilePath()); |
434 } | 473 } |
435 | 474 |
436 void DevToolsServer::Stop() { | 475 void DevToolsServer::Stop() { |
437 if (!protocol_handler_) | 476 if (!protocol_handler_) |
438 return; | 477 return; |
439 // Note that the call to Stop() below takes care of |protocol_handler_| | 478 // Note that the call to Stop() below takes care of |protocol_handler_| |
440 // deletion. | 479 // deletion. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 jobject obj, | 511 jobject obj, |
473 jlong server, | 512 jlong server, |
474 jboolean enabled) { | 513 jboolean enabled) { |
475 DevToolsServer* devtools_server = reinterpret_cast<DevToolsServer*>(server); | 514 DevToolsServer* devtools_server = reinterpret_cast<DevToolsServer*>(server); |
476 if (enabled) { | 515 if (enabled) { |
477 devtools_server->Start(); | 516 devtools_server->Start(); |
478 } else { | 517 } else { |
479 devtools_server->Stop(); | 518 devtools_server->Stop(); |
480 } | 519 } |
481 } | 520 } |
OLD | NEW |